Nic Lin's Blog

喜歡在地上打滾的 Rails Developer

在 Server 上自動監控 Sidekiq

很不幸運地,sidekiq 並不是一個非常可靠的 process。有時候會自己死掉,造成非常大的困擾。所以實務上還會需要額外再裝一個監控工具,如果發現它掛了,就自動重開它。

sudo apt-get install monit

edit vim /etc/monit/monitrc, 約在 118 行處將註解取消

 set httpd port 2812
    use address localhost  # only accept connection from localhost
    allow localhost        # allow localhost to connect to the server and
    allow admin:monit

將 sidekiq.conf (範例參考如下,請將 rails101 置換成你的APP名稱 ) 到 /etc/monit/conf.d

 check process sidekiq_rails101_production0
   with pidfile "/home/deploy/rails101/shared/tmp/pids/sidekiq-0.pid"
   start program = "/bin/su - deploy -c 'cd /home/deploy/rails101/current && /usr/bin/env bundle exec sidekiq   --index 0 --pidfile /home/deploy/rails101/shared/tmp/pids/sidekiq-0.pid --environment production  --logfile /home/deploy/rails101/shared/log/sidekiq.log  -d'" with timeout 30 seconds

   stop program = "/bin/su - deploy -c 'cd /home/deploy/rails101/current && /usr/bin/env bundle exec sidekiqctl stop /home/deploy/rails101/shared/tmp/pids/sidekiq-0.pid'" with timeout 20 seconds
   group rails101-sidekiq

輸入 sudo service monit restart 重啟 輸入 sudo monit status 可以看到應該有成功在監測 sidekiq

Share Comments
comments powered by Disqus