0

I'm trying to use Monit to monitor and restart some rails apps when they crash. The apps use Sphinx. Monit isnt accepting commands that would typically work in the shell.

The monitrc configuration looks something like this:

...
check process app_name
  with pidfile "/path/to/pidfile/searchd.production.pidfile"
  start program = sudo su user_name -c "cd /home/app_name/current
    && RAILS_ENV=production rake ts:start"
  stop program = sudo su user_name -c "cd /home/app_name/current
    && RAILS_ENV=production rake ts:stop"
...

permission to access the pidfile is denied but if I try:

with pidfile "sudo /path/to/pidfile/searchd.production.pidfile"

it doesnt work.

likewise, monit doesnt accept the start and stop program bash commands.

Is there an obvious workaround I'm missing? I'm a noob by the way.

I also had a look at http://capitate.rubyforge.org/recipes/sphinx-monit.html#sphinx:monit:start but don't really get it.

user1642579
  • 95
  • 1
  • 5

1 Answers1

0

Try to place bundle exec before callling rake. Like this:

start program = sudo su user_name -c "cd /home/app_name/current
  && RAILS_ENV=production bundle exec rake ts:start"
stop program = sudo su user_name -c "cd /home/app_name/current
  && RAILS_ENV=production bundle exec rake ts:stop"

This was the primary cause I couldn't monitor my puma server and delayed_job workers on my production server.

update:

My working example:

check process puma with pidfile <%= puma_pidfile %>
  start program = "/bin/su - ubuntu -c 'cd /home/ubuntu/apps/artvasion/current && bundle exec puma -C config/puma.rb'"
  stop program =  "/bin/su - ubuntu -c 'kill `cat /home/ubuntu/apps/artvasion/shared/pids/puma.pid`'"
  # ...monitoring stuff
DavidRH
  • 809
  • 5
  • 8
  • Thanks Dave but I think the problem is specific to Monits limited language, for example, I need `/bin/bash su` instead of `su` – user1642579 Sep 20 '12 at 05:22
  • Sure. I updated my answer with my puma config. It uses `su` the way you describe. – DavidRH Sep 21 '12 at 14:12