0

So I am having a problem with monit starting a process this is my code:

check process program_1
matching "program_1"
start program = "/home/user1/files/start.sh"
stop program = "/home/user1/files/stop.sh"

Monit is running as root, anyway when I shutdown the process monit will notice it and will try to start it again. However it fails to do so. failed to start: /home/user1/files/start.sh I also tried this:

check process program_1
matching "program_1"
start program = "/bin/bash -c '/home/user1/files/start.sh'"
stop program = "/bin/bash -c '/home/user1/files/stop.sh'"

This doesn't work either. It now says: Failed to start: /bin/bash
Is there anything i'm missing?

Zero
  • 113
  • 2
  • 4

4 Answers4

1

Monit matching can be a bit wide - for example if you are matching for "sh" it will always think that your program is running.
Try to run the following while your program_1 is not running:

ps aux | grep program_1 | grep -v grep

If you see any output then your matching is wrong, try to narrow the search pattern.

As a best practice I would suggest that you either make program_1 write a pid file and read it with monit pidfile:

check process program_1 with pidfile /run/program_1.pid

Or if that is not possible, write a short script that actually checks if your program is running and returns 1 for not-running and 0 for running.
Then pass your script to Monit like that:

check program program_1 with path /etc/periodic/program_1_test.sh
if status != 0 then restart
start program = "/home/user1/files/start.sh"
stop program = "/home/user1/files/stop.sh"

Also, never do chmod 777 on a script that runs as root.

Daniel
  • 302
  • 1
  • 5
0

Worked, when i changed the shell interpreter to #!/bin/sh instead of #!/bin/bash, able to capture monit environmental variable Moreover i am trying to execute shell script with extension ".sh" #!/bin/sh #echo $1 > /temp/file2 { echo "MONIT_SERVICE is $MONIT_SERVICE" echo "MONIT_EVENT is $MONIT_EVENT" echo "MONIT_DESCRIPTION is $MONIT_DESCRIPTION" } >> /temp/file2

0

I think it may be that the file doesn't have permissions to run without bash (should be able to rectify by running "chmod +x" and your second command shouldn't include the "-c" switch to bash and the filename also doesn't need to be quoted.

Chris Davidson
  • 331
  • 1
  • 6
  • I ran chmod 777 on start.sh, it still does not make any difference. And I should get rid of the -c after bash? And which quoted filename do you mean – Zero Nov 25 '14 at 19:28
  • The lines should look like this; `start program = "/bin/bash /home/user1/files/start.sh"` `stop program = "/bin/bash /home/user1/files/stop.sh"` – Chris Davidson Nov 25 '14 at 19:56
  • I tried it, still this error: 'program_1' process is not running. trying to restart. start: /bin/bash. Failed to start. – Zero Nov 26 '14 at 14:34
  • What happens when you run that command manually on the command line, not invoked via monit? – Chris Davidson Dec 23 '14 at 20:05
0

(should be a comment, but its a bit long)

I ran chmod 777 on start.sh

erk. That's attacking the problem with a sledgehammer.

You didn't say what all this is running on. I suggest checking

1) if it is running in a chroot environment (if it runs as root this would be a sensible pre-caution by the packager)

2) if you have SELinux (or another mandatory access control system such as Smack or AppArmor). You should be seeing some log activity relating to the script you are trying to run.

symcbean
  • 19,931
  • 1
  • 29
  • 49