Answer the question
In order to leave comments, you need to log in
How to automatically rebuild an application in linux?
Guys, please tell me, I have a service (wrapper - monitors csync2), which for one reason or another can fail with an error, how can I configure it to automatically restart? OS Debian9. Perhaps there is some utility for this (
Answer the question
In order to leave comments, you need to log in
systemd No matter what anyone says, this is the simplest and most reliable solution.
I don’t have csync2 at hand,
but I can give you the general logic for the simplest monitoring
An example for cron right away,
as we can see, we will look at the status of the daemon, in the response we are looking for the word Active: failed
&& - If true, then execute the command
. The csync may be a little different, but in fact
you need to
1. define the crash criterion.
2. based on this crash, restart the daemon.
3. you can use third-party monitoring there zabbix but I think you don't have such a volume.
Cool and brainy - systemd, if you don't puke on it
Bosyatsky:
# Winbindd processes
entries=`ps -ax | grep winbindd | grep -v grep | wc -l`
# When there are 0 entries, start winbindd
if [ $entries -eq 0 ]; then
cd /usr/local/etc/rc.d
samba start
/usr/bin/logger -4 -i -t chkwinbind -p daemon.info Winbindd crash detected, process restarted
else
/usr/bin/logger -4 -i -t chkwinbind -p daemon.info Running $entries winbindd process\(es\)
fi
You can write a shell script (sh, csh, bash). He starts the program; waits for its completion (nothing needs to be done here at all, this is standard behavior); checks process exit code and logs; and decides whether to restart the program or not.
There are programs that "dive into the background" - the process forks, the parent exits, the child runs. This is just against the fact that the script that launched the program waited for completion.
As a rule, all sorts of daemon programs like SendMail, Apache, Squid and others do this. But such programs leave a file like /var/run/program.pid (the path may be different; the file name can be different), in which the process id is written in the first line (if the program runs several copies, then the id of the main process). Further, it is obvious - we must wait for the completion of this process. And I'm not sure that you can get the exit code - you have to look at the documentation.
If the file /var/run/program.pid is not created, then the process did not start at all; Well, or it started and managed to die. Although if you send "kill -9" to the process, it will die, but /var/run/program.pid will remain, but the process id written there will most likely be free. This should also be taken into account.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question