Ausfälle von Diensten entgegenwirken

June 27th, 2007 || 0 comments

SSH, Apache, Postfix – laufen oftmals auf Servern und neigen mitunter dazu, auszufallen. Problematisch, wenn der Admin pennt, aber die Kunden auf das System zugreifen wollen, beispielsweise in Onlineshops. Kleines Script, dass im 2-Minuten-Takt die angegebenen Dienste auf Lebenszeichen prüft, ggf. neustartet – und in einer Datei mitprotokolliert wann sie ausgefallen sind.


[code lang="bash"]
#!/bin/bash
# check for daemons. to be invoked via inittab:
#
# sksc:2345:respawn:/usr/sbin/daemoncheck.sh
#
SSH=$(pidof sshd)
POSTFIX=$(pidof master)
APACHE=$(pidof apache2)
TIMESTAMP=$(date)
logfile="/var/log/daemoncheck.log"

if [ -z "$SSH" ]; then
/etc/init.d/sshd start
echo "$TIMESTAMP restarted sshd" >>$logfile
fi

if [ -z "$POSTFIX" ]; then
/etc/init.d/postfix start
echo "$TIMESTAMP restarted postfix" >>$logfile
fi

if [ -z "$APACHE" ]; then
/etc/init.d/apache2 start
echo "$TIMESTAMP restarted apache2" >>$logfile
fi

# 2 minutes
sleep 120

exit 0
[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

What's this?

You are currently reading Ausfälle von Diensten entgegenwirken at karnaya universe.

meta

Switch to our mobile site