This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Autostart with init.d

General support and discussion of Eggdrop bots.
Post Reply
d
dragu
Voice
Posts: 3
Joined: Sat Jan 31, 2009 8:48 pm

Autostart with init.d

Post by dragu »

Aight were just about to head for bed when i got the urge to do something
with the eggdrop bot that is running on my server. After having updated the
bot software to the latest version i got the urge to add it to the init.d so that
it would automaticly start when the machine was activated.

I understand if this might not be the right place for something like this but
would appriciate any comments about it so i know if it might work as the
idea was in my head for it to do.

Code: Select all

#!/bin/sh
#
# Starts eggdrop script
#
# chkconfig: 345 94 06
# description: eggdrop is the world's most popular Open Source bot, designed under GNU license
# more information can be found at http://www.eggheads.org
MYDESC="eggdrop"
MYPATH=/home/user/eggdrop
MYNAME=user
MYLOCK=$MYNAME
DAEMON=$MYPATH/RunEggdrop.sh
MYPIDF=/var/run/$MYNAME.pid
MYCMND="$MYPATH/RunEggdrop.sh"

# Source function library.
. /etc/rc.d/init.d/functions

# Make sure the daemon directory is in the front of the path list
PATH=$MYPATH:$PATH

# See how we were called.
case "$1" in
  start)
        # Change to package directory so config paths can be relative
        cd $MYPATH || \
          { echo "$0: Can't cd to $MYPATH" ; exit 1 ; }
        # Make sure the daemon exists
        [ -f $DAEMON ] || \
          { echo "$0: Daemon not found: $DAEMON" ; exit 1 ; }
        # See if we are already running
        # Note: kill -0 _PID_
        #       returns true if process _PID_ is alive and accepting signals.
        [ -f $MYPIDF ] && kill -0 `cat $MYPIDF` && \
          { echo "$0: $MYPIDF exists and process is running" ; exit 1 ; }
        echo -n "Starting $MYDESC: "
        echo "$MYNAME "
        su -l -c "$MYCMND" user | tee $MYPIDF
        tail -1 $MYPIDF | cut -d'=' -f2 | cut -d' ' -f1 > $MYPIDF
        chown user.user $MYPIDF
        touch /var/lock/subsys/$MYLOCK
        ;;
  stop)
        echo -n "Shutting down $MYDESC: "
        echo -n "$MYNAME "
        killproc eggdrop
        rm -f $MYPIDF
        echo
        rm -f /var/lock/subsys/$MYLOCK
        ;;
  status)
        status $MYNAME
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0
The sh script which it calls to start the eggdrop is just a container of:

Code: Select all

cd /home/user/eggdrop
./eggdrop config.conf
Any suggestions or comments would be most welcomed.
But now i'm going to let my brain rest :P and sorry if i posted this in
the wrong section of the forum.
C
Callisto
Halfop
Posts: 86
Joined: Sun Mar 13, 2005 11:04 am

Post by Callisto »

Hi, just wondering what is wrong with a good old fashioned crontab?
I dont mean to be picky or distrespectful, however isnt your shell script kinda re-inventing the wheel?
The only advantage I can see is the bot starts as soon as the box has started.
Regards
d
dragu
Voice
Posts: 3
Joined: Sat Jan 31, 2009 8:48 pm

Post by dragu »

Well i sure don't have anything against the crontab solution, how ever that
direction does not ensure that it starts directly when the machine is on.
Personly also i try to keep as few things as possible in the cron section if
there are other ways to solve it.

Ceartingly i can admit that it might seem alot as that there shouldn't be any
need to do it in another way.

How ever it were mostly only a thought to have a way that it would start in
direct and simple way after say a power outage or something like that.

Anyhow i will be looking into this a bit more and if i'd might find a solution
where actually it would work. But suggestions and advice would always be
most welcomed. :)
User avatar
incith
Master
Posts: 275
Joined: Sat Apr 23, 2005 2:16 am
Location: Canada

Post by incith »

I'd have to agree with just using cron. Set the timer to every minute if you must (I use 5 or 10 minute check).. your bot will start as soon as cron check runs, whether the machine is rebooted or not.

Just setup your botchk file and chmod +x it. Then (from shell) run crontab -e

Code: Select all

# minute(0-59) hour(0-23) day(1-31) month(1-12) weekday(0-6,0=sun)
*/15 * * * * /home/incith/eggdrop/botchk.visitant 2>&1
Save & close file.

Guess I use 15 minutes. */1 would be every minute, etc.
d
dragu
Voice
Posts: 3
Joined: Sat Jan 31, 2009 8:48 pm

Post by dragu »

Ehrm.. Yes that is ceartingly true that it would. How ever depending on the
timer and such dilemas it does not kick on right at the boot which is the
thing which i were looking to do. And also as i mentioned, i am not a big
fan over cron and tries to use it to a minimum.

No offence to those which like the solution for cron, it's just not my
cup of tea so to say. Anyhow guess will look it up to another direction
to find out if the things would work.
Post Reply