Service Auto Recovery

Discussion in 'Tips/Tricks/Mods' started by linickx, Mar 6, 2007.

  1. linickx

    linickx New Member

    Hi All,

    I thought I'd share this tip, I wanted a script that would restart httpd/mysql if the process died (full waffle here), written & tested on CentOS your mileage might vary elsewhere, but obviously it can easily be expanded to "recover" the full range of ISPConfig services.

    Save the following code in /etc/cron.hourly

    # taken from redhast default scripts - /etc/rc.d/init.d/functions
    # Set up a default search path.
    export PATH
    status() {
            local base=${1##*/}
            local pid
            # Test syntax.
            if [ "$#" = 0 ] ; then
                    echo $"Usage: status {program}"
                    return 1
            # First try "pidof"
            pid=`pidof -o $$ -o $PPID -o %PPID -x $1 ||
                 pidof -o $$ -o $PPID -o %PPID -x ${base}`
            if [ -n "$pid" ]; then
    # Uncomment this if you want OK messages
    #               echo $"${base} (pid $pid) is running..."
                    return 0
            # Next try "/var/run/*.pid" files
            if [ -f /var/run/${base}.pid ] ; then
                    read pid < /var/run/${base}.pid
                    if [ -n "$pid" ]; then
                            echo $"${base} dead but pid file exists"
                            /etc/init.d/${base} restart
                            return 1
            # See if /var/lock/subsys/${base} exists
            if [ -f /var/lock/subsys/${base} ]; then
                    echo $"${base} dead but subsys locked"
                    /etc/init.d/${base} restart
                    return 2
            echo $"${base} is stopped"
            return 3
    # found in /etc/init.d/httpd
    status mysqld
    status $httpd
    If anyone has a cleaner / better solution I'd be glad to hear it :D
    Good Luck !
  2. falko

    falko Super Moderator ISPConfig Developer

  3. linickx

    linickx New Member

    cool, thanks for the link, I'll check it out :)

Share This Page