Desde hace tiempo tengo montado en casa un servidor, con varios servicios, mediacenter, etc…
Lo importante en un servidor, es que sus servicios funcionen correctamente el mayor tiempo posible, por lo que es necesario comprobar si todos están activos.Sin embargo, debido a errores, en algunas ocasiones, éstos servidores dejan de funcionar, por lo que es necesario comprobar que permanecen activos cada cierto tiempo y en caso de no estarlo reactivarlos.
Por eso aquí os dejo el código para comprobar y reiniciar los servicios.
Tu «fichero.sh»
Busca «RUTA» y pon la localización de los ficheros solicitados:
#!/bin/bash
services=(zoneminder webmin tomcat6 subsonic apache2)
for name in ${services[@]}
do
SERVICEEXIST=`sudo service $name status|grep -n "is running"|cut -d: -f1`
if [ "$SERVICEEXIST" != "1" ] ; then
service $name start
fi
done
procesos=(amuled utserver lircd)
for name in ${procesos[@]}
do
PROCESSNAME=`ps -A|grep $name|cut -d: -f3|cut -d" " -f2|tail -1`
if [ "$PROCESSNAME" != "$name" ]; then
case $name in
"amuled") sudo service amule-daemon restart; break;;
"utserver") RUTA/utserver -daemon; break;;
"lircd") sudo service lirc start; break;;
esac
fi
done
pyload=`pyLoadCore --status`
if [ $pyload == "false" ];then
pyLoadCore --daemon
fi
nxserver=`sudo /usr/NX/bin/nxserver --status|grep -n "is running"|cut -d: -f1`
if [ $pyload == "false" ];then
sudo /usr/NX/bin/nxserver --daemon
fi
SERVICEEXIST=`sudo service proftpd status|grep -n "currently running"|cut -d: -f1`
if [ $SERVICEEXIST == "false" ];then
sudo service proftpd start
fi
SERVICEEXIST=`sudo service ssh status|grep -n "running"|cut -d: -f1`
if [ $SERVICEEXIST == "false" ];then
sudo service ssh start
fi
SERVICEEXIST=`sudo service mysql status|grep -n "running"|cut -d: -f1`
if [ $SERVICEEXIST == "false" ];then
sudo service ssh start
fi
SERVICEEXIST=`sudo service cups status|grep -n "running"|cut -d: -f1`
if [ $SERVICEEXIST == "false" ];then
sudo service ssh start
fi
Una vez guardado ejecutamos:
sudo crontab -e
Y en el archivo que se abre introducimos:
*/1 * * * * bash RUTA/fichero.sh
Dónde «1» es el número de minutos que deben pasar entre checkeos.
Apasionado, geek, ingeniero de locuras y absolutamente convencido de nada
What a plrusaee to find someone who thinks through the issues