#!/bin/sh # # BOINC - start and stop the BOINC client daemon on Unix # # Unix start/stop script to run the BOINC client as a daemon at # system startup, as the 'boinc' user (not root!). # # This version works on Red Hat Linux, Fedora Core, Debian, Ubuntu, SUSE, # Mandrake, and Slackware Linux, and should work on generic Linux systems # provided that they have 'pidof' and a POSIX /bin/sh (most all do). # Metadata for chkconfig and the SUSE equivalent INIT info are included below. # # Usage: boinc { start | stop | status | restart } # ### # chkconfig: 345 98 03 # description: This script starts the local BOINC client as a daemon # For more information about BOINC (the Berkeley Open Infrastructure # for Network Computing) see http://boinc.berkeley.edu # processname: boinc # config: /etc/sysconfig/boinc # ### BEGIN INIT INFO # Provides: boinc # Required-Start: $network # Required-Stop: $network # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Description: This script starts the local BOINC client as a daemon # For more information about BOINC (the Berkeley Open Infrastructure # for Network Computing) see http://boinc.berkeley.edu ### END INIT INFO # # Eric Myers - 27 July 2004 # Department of Physics and Astronomy, Vassar College, Poughkeepsie NY # Eric Myers # Spy Hill Research, Poughkeepsie, New York # @(#) $Id: boinc,v 1.14 2008/07/14 12:52:34 myers Exp $ ######################################################################## # Defaults, which can be overridden by putting new NAME=value lines # in /etc/sysconfig/boinc (for Red Hat/Fedora Linux and variants) # or /etc/default/boinc (for Debian/Ubuntu and variants) # Name of user to run as: # BOINCUSER=boinc # Working directory. Could be /home/boinc, /var/lib/boinc, etc.. # The reason /var/lib/boinc is preferable is that this works best for a # cluster of computers whereas /home/anything might be shared between machines # BOINCDIR=/var/lib/boinc # Name of the client executable. This is the file "boinc" if you # unpacked the download file boinc_M.mm.rr_i686-pc-linux-gnu.sh, # but I like to rename it and put it in a public place. # (Hint: move boincmgr to /usr/local/bin too so anyone can easily use it). # BOINCEXE=/usr/bin/boinc_client # Log and error files (you should rotate these occasionally) # LOGFILE=boinc.log ERRORLOG=error.log # BOINC options for the command line when running the client. # Be aware that --allow_remote_gui_rpc opens up your machine to the world! # (Or at least to your local subnet) # #BOINCOPTS="--allow_remote_gui_rpc" BOINCOPTS="" # Deprecated. Was used to construct the executable name in days of old. # (Still here just as a last ditch to find an old executable, but # probably should be removed.) # BUILD_ARCH=i686-pc-linux-gnu # Mandrake 10.1 really wants a subsys lock file ... if [ -d /var/lock/subsys ]; then LOCKDIR=/var/lock/subsys elif [ -d /var/lock ]; then LOCKDIR=/var/lock fi # su on Linux seems to need this to be set to work properly in a script export TERM dumb ## # Init script function library. This stuff is Red Hat specific, # but if the functions are not found we create our own simple replacements. # (The idea for replacing the functions comes from OpenAFS. Thanks guys!) if [ -f /etc/rc.d/init.d/functions ] ; then . /etc/rc.d/init.d/functions ##TODO: Try to use LSB here for systems that have it? else export PATH=/sbin:/bin:/usr/sbin:/usr/bin echo_success () { echo -n " [ OK ] " ; } echo_failure () { echo -n " [FAILED] " ; } echo_warning () { echo -n " [WARNING] " ; } killproc() { PID=`pidof -s -x -o $$ -o $PPID -o %PPID $1` [ $PID ] && kill $PID ; } fi ## Look for any local configuration settings which override all above if [ -f /etc/sysconfig/boinc ]; then . /etc/sysconfig/boinc elif [ -f /etc/default/boinc ]; then . /etc/default/boinc fi ## Verify the working directory exists: if [ ! -d $BOINCDIR ]; then echo -n "Cannot find BOINC directory $BOINCDIR " echo_failure echo exit 7 fi # Some additional places to look for the client executable # (We do this after init.d/functions and sysconfig/boinc, which sets PATH) export PATH=$BOINCDIR:/usr/local/bin:$PATH ## Locate the executable, either boinc_client, boinc, ## or boinc_M.mm_.... with highest version number ## We only do this if BOINCEXE set above isn't found or is not executable. if [ ! -x $BOINCEXE ]; then BOINCEXE=`/usr/bin/which boinc_client 2>/dev/null` if [ ! -x "$BOINCEXE" ]; then BOINCEXE=`/usr/bin/which boinc 2>/dev/null` if [ ! -x "$BOINCEXE" ]; then BOINCEXE=`/bin/ls -1 $BOINCDIR/boinc_*_$BUILD_ARCH 2>/dev/null | tail -1 ` fi fi fi if [ ! -x "$BOINCEXE" ]; then echo -n "Cannot find an executable for the BOINC client." echo_failure echo exit 2 fi ## Functions: $1 is one of start|stop|status|restart case "$1" in start) cd $BOINCDIR if [ -f lockfile ] ; then echo -n "Another instance of BOINC is running (lockfile exists)." echo_failure echo exit 4 fi if [ ! -d projects ] ; then echo -n "The BOINC client requires initialization." echo_warning echo fi echo -n "Starting BOINC client as a daemon: " su $BOINCUSER -c "$BOINCEXE $BOINCOPTS" >>$LOGFILE 2>>$ERRORLOG & sleep 4 PID=`pidof -s -x -o $$ -o $PPID -o %PPID $BOINCEXE` if [ $PID ]; then [ -d $LOCKDIR ] && touch $LOCKDIR/boinc echo_success else echo_failure fi echo ;; stop) cd $BOINCDIR if [ ! -f lockfile -a ! -f $LOCKDIR/boinc ] ; then echo -n "BOINC is not running (no lockfiles found)." echo_success else echo -n "Stopping BOINC client daemon: " killproc $BOINCEXE && echo_success || echo_failure # clean up in any case rm -f $BOINCDIR/lockfile rm -f $LOCKDIR/boinc fi echo ;; restart) $0 stop $0 start ;; status) PID=`pidof -x -o $$ -o $PPID -o %PPID boinc_client` if [ "x$PID" = "x" ]; then PID=`pidof -x -o $$ -o $PPID -o %PPID $BOINCEXE` fi if [ "$PID" != "" ]; then echo "BOINC client is running (pid $PID)." else if [ -f $BOINCDIR/lockfile -o -f $LOCKDIR/boinc ]; then echo "BOINC is stopped but lockfile(s) exist." else echo "BOINC client is stopped." fi fi ;; *) echo "Usage: boinc {start|stop|restart|status}" exit 1 esac exit #EOF#