xaxa
xaxa

Reputation: 1159

heroku restart via new API

I'm a bit confused, as there used to be a method in heroku API to restart processes of an app. Now this API seems to be deprecated and all links are leading to https://devcenter.heroku.com/articles/platform-api-reference where I cannot find any information about restart (even the word restart itself).

Can someone shed some light on it? This is, I believe, along with showing logs, one of the most important API commands for a dev, as you can do most of other tasks via heroku webui.

Upvotes: 2

Views: 2759

Answers (3)

Rishi Bhachu
Rishi Bhachu

Reputation: 172

This worked for me via terminal (you will need to install Heroku CLI first);

curl -n -X DELETE https://api.heroku.com/apps/<your app name/id>/dynos -H "Content-Type: application/json" -H "Accept: application/vnd.heroku+json; version=3"

Upvotes: 0

Obromios
Obromios

Reputation: 16373

You can use the heroku platform-api to do this. There is a dyno restart method for the api.. Here is an example of how to do with a rake task.

First you need to set up the credentials. From your development machine

$ heroku plugins:install heroku-cli-oauth

then

$ heroku authorizations:create -d "Platform API token"

this will output a number of fields, including a token field. Make a copy of the token value, say it is abc-def. Then

heroku config:set OAUTH_TOKEN=abc-def

to set the OAUTH_TOKEN value on your production machine. Your rake task might look something like this:

  desc 'heroku_restart'
  task heroku_restart: :environment do
    heroku = PlatformAPI.connect_oauth(ENV['OAUTH_TOKEN'])
    dynos =  heroku.dyno.list(ENV['HEROKU_APP_NAME'])
    heroku.dyno.restart(ENV['HEROKU_APP_NAME'], dynos[0]['name'])
  end

This will restart the first dyno in the dynos list. Now commit this change and deploy to production, your rake task is ready to go.

Upvotes: 6

friism
friism

Reputation: 19279

You have to use Dyno delete: https://devcenter.heroku.com/articles/platform-api-reference#dyno-delete

If you delete a one-off dyno, it won't be restarted, if it's defined in the formation, it will be restarted.

We'll improve the docs, thanks for pointing out this omission.

Upvotes: 1

Related Questions