我知道我可以从控制台运行heroku restart
.我想做的是在我的应用程序(管理控制台(中有一个按钮,按下该按钮会运行heroku restart
。有谁知道如何做到这一点,如果可能的话?所以代码看起来像这样:
<button id="heroku_restart">Restart</button>
$("#heroku_restart").click(function() {
$.post('/restart', {}).done(function(response) {
alert(response)
})
})
class AdminsController
# this is the action mapped to the route /restart
def restart
# code for heroku restart
end
end
因此,根据@vpibano,在撰写本文时,使用platform-api
进行此操作是轻而易举的。这是我网站上的按钮发布的操作:
def restart
heroku = PlatformAPI.connect_oauth(ENV["heroku_oauth_token"])
heroku.dyno.restart_all("lastmingear")
render nothing: true
end
根据帖子中提到的描述,一种方法是:
1( 首先找到 server.pid 文件
pid_file = Rails.root.join("tmp", "pids", "server.opid")
2(现在,截断文件的内容
File.open(pid_file, "w") {|f| f.truncate(0)}
3(最后,使用内核模块运行服务器:
Kernel.exec("rails s")
注意:正如@vpibano所说的那样,您将需要身份验证才能访问您的应用程序。
这不是一个工作模型,而是实现要求的一种方式。
希望对您有所帮助!!