2011-05-17 21:25:01
Apache und MySQL supervised
Unter notfall-sshd_oom-resistent steht beschrieben, wie man sshd supervised (mit den daemontools von DJB) betreibt. Dieser Post zeigt Beispiele, wie auch Apache und MySQL unter der Kontrolle von supervise laufen.
Apache
> ps axuwf|...
/command/svscan /service/
\_ supervise apache-sv
\_ /usr/sbin/apache2 -f /etc/httpd/httpd.conf -D FOREG..
> cat /service/apache-sv/run
#!/bin/bash
exec 2>&1
# don't respawn too fast
sleep 1
# in case that apache lost his father "supervise" kill the
# procs
ps axuwf |grep -v grep \
|grep ' /usr/sbin/apache2 ' \
|awk '{print$2}' \
|xargs -r kill -TERM
exec /usr/sbin/apache2 -f /etc/httpd/httpd.conf -D FOREGROUND
MySQL
#!/bin/bash
export PATH=/command:$PATH:/usr/local/bin:/usr/local/sbin
PROC_PATTERN=usr.sbin.mysqld
MAX_KILL_ATTEMPTS=20
SCRIPT=$(pwd)/$0
get_pid() {
PID=$(/bin/ps axwf \
|grep $PROC_PATTERN|grep -v grep\
|awk '{print$1}' 2>/dev/null)
}
kill_procs() {
COUNT=0
get_pid
while [ "$PID" ]
do
kill -TERM $PID 2>/dev/null
let COUNT=COUNT+1
[ "$COUNT" -gt $MAX_KILL_ATTEMPTS ] \
&& kill -9 $PID 2>/dev/null
sleep 3
get_pid
done
}
# we must be sure: kill all remaining procs
kill_procs
# this should never be reached, otherwise there are
# maybe too many databases/tables on this host
ulimit -n 250000
exec /usr/sbin/mysqld \
--defaults-file=/etc/mysql/my.cnf \
--basedir=/usr \
--datadir=/var/lib/mysql \
--pid-file=/var/run/mysqld/mysqld.pid \
--socket=/var/run/mysqld/mysqld.sock