Monit failed to start shell script

6,276

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.

Share:
6,276

Related videos on Youtube

Zero
Author by

Zero

Updated on September 18, 2022

Comments

  • Zero
    Zero over 1 year

    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
    Zero over 9 years
    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
  • Chris Davidson
    Chris Davidson over 9 years
    The lines should look like this; start program = "/bin/bash /home/user1/files/start.sh" stop program = "/bin/bash /home/user1/files/stop.sh"
  • Zero
    Zero over 9 years
    I tried it, still this error: 'program_1' process is not running. trying to restart. start: /bin/bash. Failed to start.
  • Chris Davidson
    Chris Davidson over 9 years
    What happens when you run that command manually on the command line, not invoked via monit?