简体   繁体   中英

How to stop a Heroku dyno using the Heroku API so it doesn't restart

How can a fully stop a Heroku dyno using the Heroku API so it doesn't restart?

I have Heroku set up to run a Python script that always loops and never exits to check sensors. This main.py script is run as a Dyno worker via my Procfile. Right now, it always runs as anticipated. It even restarts upon a crash, which is also helpful for this app.

Using the Heroku API , I would like to be able to completely stop this process. This won't be reoccurring often, just a failsafe kill-switch. I can stop the dyno worker by logging in to Heroku and clicking the edit button in the Resources tab and turn off the worker. But, I would like to turn off the worker via the API.

I have tried the following API calls (via Postman), which both stop the current process, but after a few seconds, Heroku starts the worker back up again.

Stop the current Dyno

POST https://api.heroku.com/apps/<app_id>/dynos/worker.1/actions/stop

Deletes / restarts all dynos in the app

DELETE https://api.heroku.com/apps/<app_id>/dynos

Also, I can put the app in to maintenance mode, but that only stops HTTP traffic, not the Dynos

PATCH https://api.heroku.com/apps/<app_id>
with payload of {"maintenance":true}

One option is completely deleting the app, but that's a bit too much for me as it will also remove all log files, and be a pain to set it back up again.

DELETE https://api.heroku.com/apps/<app_id>

Is there any way to completely stop a Dyno or app via the API until I manually start it back up again?

You have to use Heroku Formation API to scale the processes up and down, it will not restart the App by itself.

For detailed answer check this .

Seems like you are stoping the worker rather than a dyno. You have to provide a dyno id.

Stoping dyno

After stopping correctly restart to start it again.

restarting the dyno

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM