#!/bin/sh
# rc.boinc - BOINC startup/control script for Slackware Linux
#
# Licence:
# Copyright (c) 2005, 2008, Mark Hill
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#######################################################################
# Program: /etc/rc.d/rc.boinc
# Purpose: A startup and control script for Slackware Linux.
# Installation:
# 1. Rename this file to rc.boinc and remove any possible DOS line endings. I.E:
# $ tr -d '\r' rc.boinc
# 2. Edit the variables below to suit your BOINC setup.
# 3. Place this file in /etc/rc.d/ and make the file executable.
# 4. Change ownerships of the file as appropriate
# 5. Add the following code to /etc/rc.d/rc.local:
#
# if [ -x /etc/rc.d/rc.boinc ]; then
# /etc/rc.d/rc.boinc start
# fi
#
# 6. Test the script - Run the script as root using 'sh /etc/rc.d/rc.boinc' or
# similar. You should see a list of options.
# 7. Check for any current running boinc process be running the script like
# so as root: 'sh /etc/rc.d/rc.boinc status'
# 8. If no boinc process running, run as root: 'sh /etc/rc.d/rc.boinc start'
# 9. Installation complete! - rc.boinc should start boinc on each boot. You may
# want to use an 'rc.boinc stop' command to a shutdown script, although this
# isn't strictly necessary.
#######################################################################
# Author: Mark Hill
# URL:
# Version: 2008-09-22 - Removed previous change to boinc_status. Rewrote
# function as grep would sometimes find itself from the ps output
#######################################################################
# Usage: rc.boinc start|stop|restart|reload|force-reload|status
#######################################################################
# Begin user configuration
BOINC_DIR=/home/mark/BOINC/ # directory of boinc files - MUST have trailing /
BOINC_BIN=boinc # name of the boinc binary
BOINC_USER=root # user that will run boinc process
BOINC_OPTIONS= # E.G "-return_results_immediately"
BOINC_LOGFILE=/home/mark/boinc-log # will be created if it does not exist
BOINC_ERRORFILE=/home/mark/boinc-errors # as above
# End of user configuration
#######################################################################
boinc_status() {
if ( ps -ef | grep "$BOINC_DIR$BOINC_BIN$" > /dev/null 2>&1 ); then
return 0
else
return 3
fi
}
boinc_start() {
boinc_status;
if [ $? = 0 ]; then
echo "BOINC is already running"
exit 1;
fi
if [ ! -d $BOINC_DIR ]; then
echo "ERROR: $BOINC_DIR does not exist"
exit 1;
elif [ ! -x $BOINC_DIR$BOINC_BIN ]; then
echo "ERROR: $BOINC_DIR$BOINC_BIN does not exist or not executable"
exit 1;
fi
echo "Starting BOINC client"
su - $BOINC_USER -c "
cd $BOINC_DIR;
exec $BOINC_DIR$BOINC_BIN \
$BOINC_OPTIONS \
>$BOINC_LOGFILE 2>$BOINC_ERRORFILE" &
}
boinc_stop() {
echo "Stopping BOINC client"
killall $BOINC_BIN
}
boinc_restart() {
echo "Restarting BOINC client"
boinc_status;
if [ $? = 0 ]; then
boinc_stop
sleep 3
boinc_start
else
boinc_start
fi
}
case "$1" in
start)
boinc_start
exit 0
;;
stop)
boinc_stop
exit 0
;;
restart)
boinc_restart
exit 0
;;
status)
boinc_status
if [ $? = 0 ]; then
echo "BOINC is running"
else
echo "BOINC is not running"
fi
;;
force-reload)
boinc_restart
exit 0
;;
reload)
echo "BOINC is unable to reload config without restart"
echo "Try using $0 restart"
exit 3
;;
*)
echo "Usage: $0 start|stop|restart|reload|force-reload|status"
exit 1
;;
esac