Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monit restart program script

I am fairly new to monit and I was wondering if this script is enough to restart a crashed program lets say program1 is the name of the program.

check process program1
matching "program1"
start program = "/home/user/files/start.sh"
stop program = "/home/user/files/stop.sh"

Will it restart a crashed program now? And how can I assure it does not restart the program when it is working?

Edit: some more info The program uses port 30000 udp. Will this make it more cautious? And how many seconds are between the "cycles"?

if failed port 30000 type UDP for 3 cycles then restart
like image 976
Zero Avatar asked Nov 23 '14 15:11

Zero


People also ask

How do I restart monit?

While debugging why certain process is failing it is usually useful to tell Monit to stop restarting the failing process. You can do so via monit stop <process-name> command. To start it back up use monit start <process-name> command.

How do I check my monit status?

The monit configuration can be re-read after installing the PSM by entering the command “monit reload”, or by rebooting the machine. You can obtain the status of the PSM and other important services via the monit web interface at http:// <server ip address>:2812 or on the command line.

What is monit cycle?

Monit will detach from the terminal and run as a background process, i.e. as a daemon process. As a daemon, Monit runs in cycles; It monitor services, then goes to sleep for a configured period, then wakes up and start monitoring again in an endless loop.

How does monit work in Linux?

Monit can be used to test programs or scripts at certain times, much like cron, but in addition, you can test the exit value of a program and perform an action or send an alert if the exit value indicates an error. This means that you can use Monit to perform any type of check you can write a script for.


1 Answers

Monit uses the system call execv to execute a program or a script. This means that you cannot write shell commands directly in the start, stop or exec statements. To do this, you must do as above; start a shell and issue your commands there.

Read about execution

This is just example what you should execute program or script:

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

Based on ConfigurationExamples

like image 70
Philidor Avatar answered Oct 19 '22 20:10

Philidor