Sample SysV Init Script for fah6 (Recyclable, too!)
Posted: Sat Oct 18, 2008 7:52 am
I've been messing with this for a while, and now it looks stable enough to share without much embarrasment. :o)
You'll have to change the variables at the top of the file to match your system. My system configuration has it running under my username nate in a working directory /usr/local/folding ... the directory itself and contents of which are all chown nate:nate and at least chmod u+rw ... hopefully you are already at the point you can launch the client if you're reading this.
FEATURES
This script checks for any existing instances, and exits with message and exit code 1 if fah6 is already running. Likewise, it doesn't try to kill something that doesn't exist, and exits with '1'. Startup and shutdown are verified, if there's a problem, the exit code is 1. Also the restart, reload, force-reload options have a timeout allowing child threads to stop.
Client is started with calls to "su $USER" > /bin/sh > client which detaches from sh. It is stopped with "killall -INT" which has not so far chubbed up any WU's or led to messages about "previous termination was improper."
This script is not configured for the SMP client, but that should be easy enough to do: Find the line starting with "su $USER" and change to your liking. Most stuff is easily changed from the first few lines of variables.
I included the chkconfig stuff for it to be started last and shutdown first, but then I found that only works if you have chkconfig (redhat and friends). I use ubuntu, so I decided to learn about update-rc.d instead of getting chkconfig. If you're in debian / ubuntu, take your pick - chkconfig is probably easier to install and learn than update-rc.d is to learn -- or type.
All output is done to stdout, except in the case that you screw up the argument to the script. Then it goes to stderr.
My Precious:
I know there's a few init.d scripts already floating about -- but I like mine better, so Pthhtht. I made it easily recyclable on purpose, since I've done a couple of these so far which weren't.
Enjoy,
-- Nate
You'll have to change the variables at the top of the file to match your system. My system configuration has it running under my username nate in a working directory /usr/local/folding ... the directory itself and contents of which are all chown nate:nate and at least chmod u+rw ... hopefully you are already at the point you can launch the client if you're reading this.
FEATURES
This script checks for any existing instances, and exits with message and exit code 1 if fah6 is already running. Likewise, it doesn't try to kill something that doesn't exist, and exits with '1'. Startup and shutdown are verified, if there's a problem, the exit code is 1. Also the restart, reload, force-reload options have a timeout allowing child threads to stop.
Client is started with calls to "su $USER" > /bin/sh > client which detaches from sh. It is stopped with "killall -INT" which has not so far chubbed up any WU's or led to messages about "previous termination was improper."
This script is not configured for the SMP client, but that should be easy enough to do: Find the line starting with "su $USER" and change to your liking. Most stuff is easily changed from the first few lines of variables.
I included the chkconfig stuff for it to be started last and shutdown first, but then I found that only works if you have chkconfig (redhat and friends). I use ubuntu, so I decided to learn about update-rc.d instead of getting chkconfig. If you're in debian / ubuntu, take your pick - chkconfig is probably easier to install and learn than update-rc.d is to learn -- or type.
All output is done to stdout, except in the case that you screw up the argument to the script. Then it goes to stderr.
My Precious:
Code: Select all
#!/bin/sh
# chkconfig: 2345 99 00
# description: FAH client SYSV init script
USER="nate"
DAEMON="fah6"
WORKDIR="/usr/local/folding"
DESC="Folding@Home Client"
NAME="folding"
case "$1" in
start)
echo -n "Starting $DESC: "
if PID=`pidof $DAEMON`; then
echo "FAIL: $DESC has already been started: $DAEMON PID [$PID]."
exit 0
else
su $USER -s /bin/sh -c "cd $WORKDIR; ./fah6 -verbosity 9 < /dev/null > /dev/null 2>&1 &"
if PID=`pidof $DAEMON`; then
echo "$DAEMON started with PID [$PID]."
else
echo "failed to start $DESC ... PID [$PID]."
exit 1
fi
fi
;;
stop)
echo -n "Stopping $DESC: "
if PID=`pidof $DAEMON`; then
killall -INT $DAEMON
sleep 5
if PID=`pidof $DAEMON`; then
echo "NOT TERMINATED YET: still running with PID [$PID]."
exit 1
else
echo "$DAEMON"
fi
else
echo "Not stoping $DESC: $DAEMON has no PID [$PID]."
exit 0
fi
;;
restart | force-reload)
$0 stop
echo "Allowing 10sec more for threads to close..."
sleep 10
$0 start
;;
reload)
if PID=`pidof $DAEMON`; then
$0 stop
echo "Allowing 10sec more for threads to close..."
sleep 10
$0 start
else
echo "Will not reload $DESC (not already running)."
fi
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload|reload}" >&2
exit 1
;;
esac
exit 0
Enjoy,
-- Nate