#!/bin/sh # boincctl - Control boinc. Stop it/Start it/Restart it. Originally # meant to be used as a boot time script so that boinc starts # at boot time, but can be used any time. For a boot time script # put this in /etc/init.d and make the appropriate links from # the appropriate run level areas (ie. /etc/rc3.d). (This was # developed on RedHat 9 so I know what the boot areas are there. # It should also work on Solaris, I'm not familiar with other # flavors of Linix/UNIX.) # Author: Charles Dennett/Rochester, NY USA. # Email: dennett@rochester.rr.com # Date: December 12, 2003. # Version: 1.0 # # History: Version 1.1. May 20. 2004. # Update stop function to use SIGTERM (15). # Version 1.2. September 18, 2004 # Comments about functions. # # Comment: Copyright by the author. Feel free to make modifications. # However, please keep these comments intact. # Use: To start: boincctl start # To stop: boincctl stop # To restart: boincctl restart # Status: boincctl status # # Variables that will need to be configured. # # BOINC_HOME: The directory where boinc will run. It should be run # in its own directory to keep its files and subdirectories # separate form others. # # BOINC_BIN: The full path to the boinc executable. # # RUN_AS: Username that boinc is to run as. # # BOINC_OUT: File to direct output from boinc. If you don't want this, # set it to /dev/null. # # BOINC_PARMS: Any command line parameters for boinc you wish to pass to # it. If you don't want any, simply use a null list (""). # # FUNCT: Should be use if your distribution is not redhat or debian # based. Can be set to pkill to use pkill or killproc to use # killproc to kill the client. BOINC_HOME=/home/gandalf/boinc/ BOINC_BIN=/usr/local/bin/boinc RUN_AS=gandalf BOINC_OUT=boinc.out BOINC_ERR=boinc.err BOINC_PARMS="" #BOINC_PARMS="-allow_remote_gui_rpc" #BOINC_PARMS="-return_results_immediately" #BOINC_PARMS="-return_results_immediately -allow_remote_gui_rpc" #FUNCT= # Functions This is for RedHat 9. Don't know if it exists in other # flavors of *nix. If this does not work for you, simply comment it out # and fix the stop function below so that it does not use the killproc # function since killproc is defined in the functions file. pkill might # be a good choice. Examine other boot scripts to see how they do it. if [ -e /etc/debian_version ] then DISTRIB="debian" elif [ -e /etc/redhat_version ]; then DISTRIB="redhat" elif [ -e /etc/redhat-release ]; then DISTRIB="redhat" elif [ -e /etc/fedora-release ]; then DISTRIB="fedora" fi if [ "$DISTRIB" = "debian" ] then FUNCT=pkill elif [ "$DISTRIB" = "redhat" ] || [ "$DISTRIB" = "fedora" ]; then FUNCT=killproc fi if [ ! -n "$FUNCT" ] && [ ! -n "$DISTRIB" ] then echo "BOINCCTL: Unsupported distribution, please check usability of pkill or killproc and set FUNCT=" exit 1 fi if [ "$FUNCT" = "killproc" ] then . /etc/init.d/functions fi # No other changes needed below this, most likely. start() { echo -n "Starting BOINC..." eval $SU_CMD echo " done." } stop() { echo -n "Stopping BOINC..." if [ "$FUNCT" = "pkill" ] then pkill -15 `basename $BOINC_BIN` fi if [ "$FUNCT" = "killproc" ] then killproc `basename $BOINC_BIN` -15 fi echo " done." } restart() { stop echo "Be patient. Waiting 10 seconds for all to stop." sleep 10 start } #---------------------------------------------------------------------------- # # Start of mainline code # # If the user running this script is not the user we want boinc to run as, set # up the su command so that we can become that user. Note, we will have to # know this user's password. If this script is run at boot time, it is root # that is running this script and no password is required. WHO_AM_I=`whoami` CMD="$BOINC_BIN $BOINC_PARMS >> $BOINC_OUT 2>> $BOINC_ERR &" if [ "$WHO_AM_I" != "$RUN_AS" ]; then SU_CMD="su $RUN_AS -c \"$CMD\"" else SU_CMD=$CMD fi # Go to where we want boinc to run cd $BOINC_HOME case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) echo "What do I do here for status?" tail -20 $BOINC_OUT ;; *) echo "Usage: `basename $0` start|stop|restart|status" exit 1 ;; esac