[英]How to run heroku restart from inside of a rails app?
我知道从控制台我可以运行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 模块运行服务器:
Kernel.exec("rails s")
注意:正如@vpibano 所提到的,您将需要身份验证才能访问您的应用程序。
这不是一个工作模型,而是实现需求的一种方式。
希望能帮助到你!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.