IRCServices Auto Restart by Cron

The UnrealIRCd team does not officially provide support for any services packages that you may be using or want to use. This forum is provided so the community can help each other with services issues.

Moderator: Supporters

Locked
Darvocet
Posts: 105
Joined: Sun Jun 27, 2004 6:40 am
Location: Houston, TX
Contact:

IRCServices Auto Restart by Cron

Post 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
- Darvocet
Sr. Network Admin: EpicIRC.Net
Ron2K

Post by Ron2K »

I thought IRCServices already came with one pre-packaged :P
Darvocet
Posts: 105
Joined: Sun Jun 27, 2004 6:40 am
Location: Houston, TX
Contact:

Post by Darvocet »

Ron2K wrote:I thought IRCServices already came with one pre-packaged :P
haha well if they did I didn't notice. :P
- Darvocet
Sr. Network Admin: EpicIRC.Net
codemastr
Former UnrealIRCd head coder
Posts: 811
Joined: Sat Mar 06, 2004 8:47 pm
Location: United States
Contact:

Post 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.
-- codemastr
Darvocet
Posts: 105
Joined: Sun Jun 27, 2004 6:40 am
Location: Houston, TX
Contact:

Post 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
- Darvocet
Sr. Network Admin: EpicIRC.Net
Locked