LoginSignup
8
8

More than 5 years have passed since last update.

HerokuのDynoの日次再起動の時刻を指定する

Last updated at Posted at 2019-01-30

Herokuのdynoは1日1回再起動する https://qiita.com/pilot/items/d42526c227ea322a2aa1 の続き

SchedulerアドオンでHeroku CLIを叩いて手動再起動する

  1. HerokuにHeroku CLI用のBuild Packを追加
    1. heroku buildpacks:add https://github.com/heroku/heroku-buildpack-cli
  2. Heroku CLI用の長期間認証を作成
    1. heroku authorizations:create
    2. 結果の「Token」欄の値を使う
  3. 環境変数に設定
    1. heroku config:set HEROKU_API_KEY=<長期間認証Token>
    2. ★環境変数を設定すると起動中のアプリが再起動するので注意★
  4. アプリをデプロイ (git push)
    1. 「Heroku CLI installation done」が表示される
  5. Schedulerアドオン導入
    1. heroku addons:create scheduler:standard
    2. 無料、Very Rareに動かない/重複実行あり https://devcenter.heroku.com/articles/scheduler
  6. スケジュール設定
    1. heroku addons:open scheduler
      1. ブラウザが起動してスケジュール設定画面が表示される
    2. 例えば「/app/.heroku/bin/heroku restart -a <アプリ名> web.1」「Standard 1X」「Daily」「20:00 UTC」を設定
      1. web.1とweb.2で時刻をずらす等
      2. 「20:00 UTC」は日本時間の午前5時

Schedulerはheroku run bashと同じくOne Off Dynoで実行されるので「長時間使用で無料枠を超える」等が起きないように留意のこと

再起動処理中もなるべくアプリを使えるようにするためにPrebootも設定しておく
heroku features:enable preboot
Prebootについて https://devcenter.heroku.com/articles/preboot
設定していないと「Dynoは立ち上がったがアプリの準備はまだできていない」状態でリクエストが振られ、エラーになることがある

以上

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8