[英]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.