LoginSignup
12
11

More than 5 years have passed since last update.

eye を使って unicorn を監視、自動回復

Last updated at Posted at 2015-10-22

背景

  • Eye を Unicorn の自動回復(autohealing)のために利用
  • EyemonitBluepillGodsupervisord のようなプロセス監視ツール
  • Eye は起動時とか、終了時とかの絵文字がかわいい!癒される。
  • Eye は Ruby の DSL !便利!
    • monit はちょっと独自すぎて抵抗が・・・
  • eye infoeye watch などもなかなか便利。使える!
  • Eye を使って unicorn を管理してみた

Eyefile の例

Eyefile
# Eye 自身のログを保存
Eye.config do
  logger __dir__ + "/log/eye.log"
end

rails_root = File.expand_path(__dir__)
Eye.application "MyApplication" do
  working_dir rails_root
  process "unicorn" do
    load_env ".env"

    unicorn_pid = "#{rails_root}/tmp/pids/unicorn.pid"
    pid_file unicorn_pid

    start_command %(sh -c '
      ./bin/unicorn -c config/unicorn.rb -E production -D;
    ')
    # stop_signals [:QUIT, 10.seconds]
    stop_command "kill -QUIT {PID}"

    # graceful restart
    restart_command %(sh -c '
      kill -USR2 {PID}
      until [ -f "#{unicorn_pid}.oldbin" ]; do
        sleep 0.1
      done
      oldpid=$(cat #{unicorn_pid}.oldbin)
      kill -WINCH $oldpid;
      kill -QUIT $oldpid;
    ')

    stdall   "#{rails_root}/log/eye-unicorn.log"
  end
end

利用手順

Eye の設定読み込み、Eye の設定に従って、起動

$ leye l
Eye started! ㋡
Config loaded!

㋡ は外国人からすると、顔文字に見えるらしい
leye は eye コマンドの派生版。カレントディレクトリの Eyefile を使い、
eye の pid ファイルをカレントディレクトリの .eye/ に個別に管理する。
eye だと $HOME/.eye/eye の pid ファイルを保持する。

Eye の状況確認

$ leye i
MyApplication                     
  unicorn ......................... starting
$ leye i
MyApplication                     
  unicorn ......................... up  (12:43, 0%, 79Mb, <3583>)

Eye の終了

$ leye q
Quit ಠ╭╮ಠ

クリッとした おめめ がかわいい

参考文献

12
11
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
12
11