Page 1 of 1

IRCServices Auto Restart by Cron

Posted: Fri Feb 04, 2005 3:38 pm
by Darvocet
I just thought I should share this, I made it yesterday. I run IRCServices, and have a cron running which is meant to attempt to start it every 3 minutes. If IRCServies is already running the script ends, if not it starts the services. This works very well from a cron, to keep the services from attempting to restart and filling up the log file.

Code: Select all

#!/bin/sh
PID=`ps cax | grep ircservices | cut -f1 -d \ `
DATE=`date +"%I:%M:%S %p on %F"`
LOGFILE=/home/ircd/services/data/ircservices.log
if [ -z $PID ]; then
        $HOME/services/sbin/ircservices -dir=$HOME/services/data/;

        #log what happened
        echo -n "ERROR: Restarting services at: " >> $LOGFILE
        echo $DATE >> $LOGFILE
fi

Posted: Fri Feb 04, 2005 5:24 pm
by Ron2K
I thought IRCServices already came with one pre-packaged :P

Posted: Fri Feb 04, 2005 10:53 pm
by Darvocet
Ron2K wrote:I thought IRCServices already came with one pre-packaged :P
haha well if they did I didn't notice. :P

Posted: Sat Feb 05, 2005 12:56 am
by codemastr
Using ps to detect whether a program is running is a bad idea. First, each OS has a different output. Some might not even support all of those flags. But also, maybe, for example, someone has two copies of IRC Services running. Or perhaps they have set the "title" of the program to something else. The best way to do it is to read the pid from the pid file and to send it a signal CHLD and see what happens.

Posted: Sat Feb 05, 2005 4:28 pm
by Darvocet
codemastr wrote:The best way to do it is to read the pid from the pid file and to send it a signal CHLD and see what happens.
Yea I had tried that first, but somehow the pid file was being overwritten by the cron, and caused the ircservices to attempt to restart, whcih would fail, but caused the log file to log a startup every 3 minutes with the cron. Which effectively made the logfile very big. :) It was probably something in my scripting, but the ps aux script worked fine for now. :P