Fli
02-18-2016, 09:08 PM
How to make some service like SSHd permanently running and restart it if it is stopped or dead?
If i kill SSHd (service) accidentally, i think this can help to start it (on Redhat/CentOS Linux):
vi /root/makesshrunning
paste into it:
if [[ "$(service sshd status)" != *"running"* ]];then service sshd restart;fi
chmod 700 /root/makesshrunning && echo "*/5 * * * * root /bin/sh /root/makesshrunning" >> /etc/cron.d/mycrons && chmod 600 /etc/cron.d/mycrons
--------------
Update: i did a few adjustments to monitor LFD (firewall) too and send me log file reports via email. I renamed script file from makesshrunning to keeprunningservices:
[email protected]
# SSH
if [[ "$(service sshd status)" != *"running"* ]];then
service sshd restart
tail -n 50 /var/log/secure | mail -s "/root/keeprunningservices SSH restart" $adminmail
fi
# LFD
if [[ "$(service lfd status)" != *"running"* ]];then
service lfd restart
tail -n 50 /var/log/lfd.log | grep -v ignored | mail -s "/root/keeprunningservices LFD restart" $adminmail
fi
If i kill SSHd (service) accidentally, i think this can help to start it (on Redhat/CentOS Linux):
vi /root/makesshrunning
paste into it:
if [[ "$(service sshd status)" != *"running"* ]];then service sshd restart;fi
chmod 700 /root/makesshrunning && echo "*/5 * * * * root /bin/sh /root/makesshrunning" >> /etc/cron.d/mycrons && chmod 600 /etc/cron.d/mycrons
--------------
Update: i did a few adjustments to monitor LFD (firewall) too and send me log file reports via email. I renamed script file from makesshrunning to keeprunningservices:
[email protected]
# SSH
if [[ "$(service sshd status)" != *"running"* ]];then
service sshd restart
tail -n 50 /var/log/secure | mail -s "/root/keeprunningservices SSH restart" $adminmail
fi
# LFD
if [[ "$(service lfd status)" != *"running"* ]];then
service lfd restart
tail -n 50 /var/log/lfd.log | grep -v ignored | mail -s "/root/keeprunningservices LFD restart" $adminmail
fi