Restart my heroku application automatically

后端 未结 7 1569
北海茫月
北海茫月 2020-12-13 08:01

This terminal command restarts my heroku application:

heroku restart

Is there a way to run a script that will run this command and restart

7条回答
  •  旧时难觅i
    2020-12-13 08:36

    A script isn't necessary, just "crash" your application and Heroku will restart it.

    Just don't do this more frequently than once every ten minutes or Heroku will subject you to a 10 minute timeout.

    In node.js you do this with process.exit(0).

    From Chris at Heroku Support:

    A crashed dyno will be restarted immediately. If the dyno moves from a crashed state into an "up" state (meaning that the dyno bound to $PORT) then it's subject to being a normal running dyno. If it crashes again during the boot or "starting" sequence then it won't be restarted again until after the TIMEOUT period. The TIMEOUT period is currently 10 minutes but that is subject to change. This prevents dynos that are continually crashing from putting extraneous load on the platform.

    However, as good as that sounds, it doesn't work in practice. You will hit the timeout every time you exit because the dyno manager expects your app to be up:

    For your worker process management you're exiting the process cleanly but the platform is expecting the dyno to be up. It sounds like you're essentially crashing the dyno as a result.

    So again, if you need to restart periodically -- and that period can be set to > 10 minutes -- this is a easy and simple way to manage memory clearing. If you need to reboot dynamically (for example, when idle is detected) or frequently you will need to explore other options.

    You can access the name of the dyno (ex. "worker.3", "web.1") through the environment variable "PS" and issue a heroku API restart command programmatically.

提交回复
热议问题