Bash Script: Check service and auto start if needed


If you are running a service and for some reason the service gets broken, you will want it to automatically restart. For that reason, I have created a script as below. Feel free to amend the array autoservice as needed because in my case it is monitoring mysqld, cherokee and squid.

#!/bin/bash
#Add values to the array autoservice seperated by spaces
autoservice=(mysqld cherokee squid)

#the code
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
for i in “${autoservice[@]}”
do
:
service $i status # > /dev/null
if [ $? -eq 0 ]; then
echo $i “Running..”
else
service $i restart
fi
done

Created in /scripts/checkService.sh, you need to chmod 777 the file and add it to crontab to run every 5minutes via the following:

 

chmod 777 /scripts/checkService.sh

 

crontab -e

add this line to run it every 5 mintues

*/5     *       *       *       *       sh /scripts/checkService.sh

Read More

Cherokee Web Server


I ran across Cherokee Web Server last week and I can say that this might take over Apache in some time.

Cherokee Web Server Logo

Installation and Configuration was pretty easy on my CentOS vps. A good guide to follow if you are also a linode user would be http://www.linode.com/forums/archive/o_t/t_5410/script_to_install_cherokee_postfix_dovecot_etc._enjoy.html which automates the installation of a postfix,dovecot and cherokee web server. Installation was so simple and fast that I was done with it in under 15minutes.

This website currently runs on cherokee web server.

Try it if you have time : )

Read More