Bash script to verify the daemon is working if not, start the daemon
Hi,
I need to write a bash script to verify some xyz daemon is running are not, if not start that xyz daemon Any help would be appreciated... Thanks is Advance |
A lot of daemons store their process ID in a file in /var/run (ex. sshd.pid for the sshd daemon). You might try looking there. Then if you find it, you can do an 'if [ -x "/proc/<PID>" ]' to see if the process directory exists. Otherwise, just a grep through a "ps -ax" for the daemon name might be enough.
|
If the xyz daemon init script is fully featured then the commands you need are
Code:
/etc/init.d/xyz status Code:
/etc/init.d/xyz start |
You might take a look at the "start-stop-daemon" program that is used in debian and possibly other distros.
|
Quote:
|
Quote:
Code:
# service httpd status | grep -iqP "\brunning\b" && (do something here) |
Quote:
Thanks lutusp & All I am new to Linux and Bash may be my question sounds like a homework :-) |
You can use init to control the service. Put this line to /etc/inittab
Code:
ap:2345:respawn:/usr/sbin/apache2 Code:
kill -HUP 1 |
All times are GMT -5. The time now is 11:52 PM. |