5

I have a simple script that I'm trying to get Monit to monitor. After some digging around I found this little nugget: start program = "su - myuser -c '/home/user/myscript.rb start' " which I believe should work but looking at the log files it says:

[PDT Oct 30 02:47:17] info     : 'simple_script' start: su
[PDT Oct 30 02:47:17] error    : Error: Could not execute su

Likewise earlier attempts only seem to read the part preceding a space so:

start program = "/home/user/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /home/user/simple_script_daemon.rb stop"

results in…

[PDT Oct 30 03:09:49] info     : 'simple_script' start: /home/user/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

Which doesn't fail like the first example but still seems to only execute the part preceding the space.

This is my full statement:

check process simple_script
    with pidfile /home/user/simple_script.rb.pid
    start program = "su - user -c '/home/user/simple_script_daemon.rb start' "
    stop program = "su - user -c '/home/user/simple_script_daemon.rb stop' "
    group simple_script

If you've got an idea what might be going on I'd love to hear from you!

fetimo
  • 235
  • 5
  • 13

2 Answers2

7

I guess you could try something like:

check process simple_script
    with pidfile /home/user/simple_script.rb.pid
    start program = "/home/user/simple_script_daemon.rb start" as uid user and gid user
    stop program = "/home/user/simple_script_daemon.rb stop" as uid user and gid user
    group simple_script

as stated in monit doc.

tshepang
  • 12,111
  • 21
  • 91
  • 136
brisssou
  • 499
  • 6
  • 12
  • 6
    Hi Brice, after a _lot_ of fiddling around I've found that the following does it: start program = "/bin/bash -c 'export rvm_path=/home/user/.rvm; . $rvm_path/scripts/rvm; cd /home/user/crittr.me; $rvm_path/bin/rvm rvmrc load; ./simple_script_daemon.rb start'" Thanks for your help! – fetimo Jan 15 '12 at 22:26
4

You may need to provide full path to su, i.e. /bin/su

Michał Szajbe
  • 8,830
  • 3
  • 33
  • 39