Monit Ruby on Rails Sidekiq

安稳与你 提交于 2019-12-05 05:58:30

check this: https://groups.google.com/forum/?fromgroups=#!topic/rubyversionmanager/0abB9jlqi_Y if you use rvm,

/bin/su - <username> -c 'bundle exec sidekiq -C /var/www/site/config/sidekiq.yml -P /var/www/site/tmp/pids/sidekiq.pid'

if you launch monit from user, set $HOME in your .bash_profile.

Or investigate whis answer: https://github.com/mperham/sidekiq/issues/506

After working on my own monit and sidekiq config, I can share what worked for me running ubuntu.

First, there exists a sidekiq upstart script for ubuntu if you are on that distro. There are scripts for sidekiq and for managing the workers: https://github.com/mperham/sidekiq/tree/master/examples/upstart/manage-one

I ran into a few errors with that default upstart script, as I am using rvm. Checking /var/logs/upstart/sidekiq-0.log shed some light on the problems. This line:

exec bin/sidekiq -i ${index} -e production -C config/sidekiq.yml -P tmp/pids/sidekiq-${index}.pid

needed to be changed to exec bundle exec sidekiq + the options

Then, for keeping everything in line with my rvm install, I changed the following:

#source $HOME/.rvm/scripts/rvm
source /usr/local/rvm/scripts/rvm

In /etc/monit/monitrc I reference the upstart scripts and have:

# sidekiq
check process sidekiq
  with pidfile /var/www/apps/myapp/current/tmp/pids/sidekiq-0.pid
  start program = "/usr/bin/sudo start sidekiq index=0"
  stop program = "/usr/bin/sudo stop sidekiq index=0"
  if totalmem is greater than 500 MB for 2 cycles then restart # eating up memory?
  if 3 restarts within 5 cycles then timeout

Here is a gist I wrote on github :

check process sidekiq_production with pidfile /var/run/sidekiq_production.pid
        depends on redis-server
        start program = "/etc/init.d/sidekiq_production start" with timeout 90 seconds
        stop program = "/etc/init.d/sidekiq_production stop" with timeout 90 seconds
        if totalmem is greater than 200 MB for 2 cycles then restart # eating up memory?
        if 2 restarts within 3 cycles then timeout

I wrote also an init script for sidekiq on Debian : https://gist.github.com/alain75007/5517948

Finally this solution worked for me like charm :)

check process sidekiq with pidfile path_to_my_pid_file/sidekiq.pid

start program = "/bin/bash -c 'cd my_app_current && source /home/myuser/.rvm/environments/ruby-2.1.2@global && bundle exec sidekiq -e production -P path_to_my_pid_file/sidekiq.pid -L /my_shared_folder_path/log/sidekiq.log -C my_app_current/config/sidekiq.yml --daemon'" as uid "myuser" and gid "myuser"

stop program = "/bin/bash -c 'kill -s INT `cat path_to_my_pid_file/sidekiq.pid`'" as uid "myuser" and gid "myuser"

** Keep following points in mind:**

  • I am using RVM for ruby version management please check with rbenv.
  • Here you need to pass the global location of ruby the way I passed it here:- /home/myuser/.rvm/environments/ruby-2.1.2@global

Your Problem is that the command bundle is missing. I think your should write the monit config file like that:

check process sidekiq 
  with pidfile /srv/www/projects/myapp/shared/log/production.sidekiq.pid
  start program = "/usr/bin/env /usr/bin/env HOME=/home/USER_NAME RACK_ENV=production RAILS_ENV=production PATH=/usr/local/bin:/usr/local/ruby/bin:/usr/bin:/bin:$PATH /bin/sh -l -c 'cd /srv/www/rails/myapp/current; bundle exec sidekiq'" as uid USER_NAME
  stop program = "/usr/bin/env /usr/bin/env HOME=/home/USER_NAME RACK_ENV=production RAILS_ENV=production PATH=/usr/local/bin:/usr/local/ruby/bin:/usr/bin:/bin:$PATH /bin/sh -l -c 'cd /
  group myapp_workers

If you walk into the apps directory and call bundle I think it work.

Here is the config that works on Ubuntu with rvm

check process sidekiq-th with pidfile /web/vcms/tmp/pids/sidekiq.pid
   start program = "/home/dimon/.rvm/bin/rvm-shell -c '/web/vcms/sidekiq.sh start'"
   stop program = "/bin/bash /web/vcms/sidekiq.sh stop &"   

It uses a script, the main lines are

start

cd /web/vcms; sidekiq -d -e production &

and stop

sidekiqctl stop $PIDFILE

I'm not a shell scripting guru and will be thankful for any advice =)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!