自动重新启动我的heroku应用程序 [英] Restart my heroku application automatically

查看:127
本文介绍了自动重新启动我的heroku应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个终端命令重新启动我的heroku应用程序:

  heroku重启

有没有办法运行脚本来运行这个命令并每隔一小时重新启动我的应用程序?

解决方案

实际上我只是为我的应用程序解决了这个问题,并在其上写了一篇关于更多细节的文章。基本上,你需要heroku-api宝石,因为heroku宝石被CLI取代。然后你需要一个rake任务,一些配置变量和heroku调度器插件(除了最小的dyno时间之外,都是免费的)。

Rake任务如下所示:

p>

 命名空间:heroku do 
desc'重新启动所有heroku dynos,以便我们可以控制何时重新启动'
任务:重新启动
Heroku :: API。
new(用户名:ENV ['HEROKU_USERNAME'],密码:ENV ['HEROKU_PASSWORD'])。
post_ps_restart(ENV ['HEROKU_APP_NAME'])
end
end



<您也可以将其设置为使用您的API令牌,而不是将您的用户名和密码放入配置中。如果您不希望您的共同撰稿人/同事知道您的密码或您在Heroku上的主要帐户的密码,这一点很重要。

  heroku config:set HEROKU_USERNAME = [username] HEROKU_PASSWORD = [password] HEROKU_APP_NAME = [app_name] -a [app_name] 

现在,继续部署和测试:

  git push [heroku_remote_name] [feature_branch]:master 
heroku run rake heroku:restart -a [app_name]

最后,我们需要设置完成任务按计划运行。我选择了免费的Heroku cron插件:

  heroku addons:add scheduler:standard -a [app_name ] 
heroku addons:open scheduler -a [app_name]

这将打开调度程序用户界面在你的浏览器中,你可以创建一个定时工来随时运行rake任务。我们每天只需要一次,而且我们选择在我们第一天的第一项计划任务之前运行它。



我的原始帖子附有CSS(参见下面的update2 ):



https://web.archive.org/web/20150612091315/http://engineering.korrelate.com/2013/08/21 / restart-heroku-dynos-on-your-terms /



更新

我将任务名称从implode更改为restart,以便更清楚地了解正在发生的事情。 Implode是一个有趣的名字,但是很不好用。我的公司删除了这篇博文。我在这里添加了更多的代码,并且我更新了链接,但CSS看起来像是一只狗抛弃了它。我的道歉。


This terminal command restarts my heroku application:

heroku restart

Is there a way to run a script that will run this command and restart my application every hour?

解决方案

I actually just had to solve this problem for my apps and wrote a post on it with more details. Basically, you need the heroku-api gem now since the heroku gem is replaced by the CLI. Then you need a rake task, a couple of config variables and the heroku scheduler plugin (free except for minimal dyno time).

The rake task looks like this:

namespace :heroku do
  desc 'restarts all the heroku dynos so we can control when they restart'
  task :restart do
    Heroku::API.
      new(username: ENV['HEROKU_USERNAME'], password: ENV['HEROKU_PASSWORD']).
      post_ps_restart(ENV['HEROKU_APP_NAME'])
  end
end

You can also set it up to use your API token instead of putting your username and password into the config. This only matters if you don't want your co-contributors/coworkers knowing your password or the password to your main account on Heroku.

heroku config:set HEROKU_USERNAME=[username] HEROKU_PASSWORD=[password] HEROKU_APP_NAME=[app_name] -a [app_name]

Now, go ahead and deploy and test:

git push [heroku_remote_name] [feature_branch]:master
heroku run rake heroku:restart -a [app_name]

Lastly, we’ll need to set up the task to run this on schedule. I’ve chosen to go with the free Heroku cron add-on:

heroku addons:add scheduler:standard -a [app_name]
heroku addons:open scheduler -a [app_name]

This will open up the scheduler UI in your browser and you can create a scheduled worker to run the rake task whenever you’d like. We only need it once per day and we’re choosing to run it before our first scheduled job of the day.

My original post with frigged up CSS (see update2 below):

https://web.archive.org/web/20150612091315/http://engineering.korrelate.com/2013/08/21/restart-heroku-dynos-on-your-terms/

UPDATE

I changed the name of the task from "implode" to "restart" to be way more clear as to what is happening. Implode is a fun name but pretty much useless otherwise.

UPDATE2

Apparently my company removed the blog post. I'm adding more of the code here and I've updated the link, but the CSS looks like a dog threw it up. My apologies.

这篇关于自动重新启动我的heroku应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆