mirror of
https://abf.rosa.ru/djam/boinc-client.git
synced 2025-02-24 15:42:49 +00:00
254 lines
7 KiB
Bash
254 lines
7 KiB
Bash
#!/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, Mandrake, Debian,
|
|
# and Slackware Linux, and should work on generic Linux systems
|
|
# provided that they have 'pidof' (most do).
|
|
# Metadata for chkconfig and the SUSE equivalent INIT info are included below.
|
|
#
|
|
# Usage: boinc { start | stop | status | reload | restart }
|
|
#
|
|
###
|
|
# chkconfig: - 98 02
|
|
# 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:
|
|
# Default-Stop: 0 1 2 6
|
|
# Short-Description: This script monitors the BOINC client.
|
|
# 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 <myers@vassar.edu> - 27 July 2004
|
|
# Department of Physics and Astronomy, Vassar College, Poughkeepsie NY
|
|
# Eric Myers <myers@spy-hill.net>
|
|
# Spy Hill Research, Poughkeepsie, New York
|
|
# @(#) $Id: boinc,v 1.10 2007/12/27 20:09:09 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 I prefer /var/lib/boinc is that this works best for a
|
|
# cluster of computers where /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
|
|
BOINCCMD=/usr/bin/boinc_cmd
|
|
|
|
# Log and error files (you should rotate these occasionally)
|
|
#
|
|
LOGFILE=/var/log/boinc.log
|
|
ERRORLOG=/var/log/boincerr.log
|
|
|
|
|
|
# Subsys lock file ...
|
|
|
|
# If there is the subsys directory, then use it ...
|
|
if [ -d /var/lock/subsys/ ]; then
|
|
LOCKFILE=/var/lock/subsys/boinc-client
|
|
elif [ -d /var/lock ]; then
|
|
LOCKFILE=/var/lock/boinc-client
|
|
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
|
|
else
|
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
function echo_success () { echo -n " [ OK ] " ; }
|
|
function echo_failure () { echo -n " [FAILED] " ; }
|
|
function echo_warning () { echo -n " [WARNING] " ; }
|
|
function 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
|
|
|
|
# BOINC options: for the command line when running the client.
|
|
# Be aware that --allow_remote_gui_rpc opens up your machine to the world!
|
|
#
|
|
#BOINCOPTS="--allow_remote_gui_rpc"
|
|
BOINCOPTS="--daemon --dir $BOINCDIR"
|
|
|
|
|
|
# Some additional places to look for the client executable
|
|
# (Should 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`
|
|
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|reload|restart
|
|
|
|
case "$1" in
|
|
start)
|
|
cd $BOINCDIR
|
|
|
|
if [ ! -d projects ] ; then
|
|
echo -n "The BOINC client requires initialization (no projects attached)."
|
|
echo_warning
|
|
echo
|
|
fi
|
|
|
|
echo -n "Starting BOINC client as a daemon: "
|
|
|
|
# Check that we're a privileged user
|
|
if [ `id -u` != 0 ] ; then
|
|
echo -n "Insufficient rights."
|
|
echo_failure
|
|
echo
|
|
exit 4
|
|
fi
|
|
|
|
daemon --check $BOINCEXE --user $BOINCUSER +19 "$BOINCEXE $BOINCOPTS" >>$LOGFILE 2>>$ERRORLOG &
|
|
try=0
|
|
while [ $try -lt 10 ] ; do
|
|
PID=`pidof -s -x -o $$ -o $PPID -o %PPID $BOINCEXE`
|
|
if [ $PID ]; then
|
|
touch $LOCKFILE && echo_success || echo_failure
|
|
break
|
|
else
|
|
sleep 1
|
|
fi
|
|
let try+=1
|
|
done;
|
|
if [ -z $PID ]; then
|
|
echo_failure
|
|
fi
|
|
echo
|
|
;;
|
|
stop)
|
|
cd $BOINCDIR
|
|
if [ ! -f lockfile -a ! -f $LOCKFILE ] ; 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 $LOCKFILE
|
|
fi
|
|
echo
|
|
;;
|
|
reload)
|
|
if [ ! -f lockfile -a ! -f $LOCKFILE ] ; then
|
|
echo -n "BOINC is not running (no lockfiles found) -- starting service."
|
|
$0 start
|
|
else
|
|
echo -n "Reading configuration: "
|
|
$BOINCCMD --read_cc_config >>$LOGFILE 2>>$ERRORLOG && echo_success || echo_failure
|
|
fi
|
|
echo
|
|
;;
|
|
force-reload)
|
|
$0 reload
|
|
$0 restart
|
|
;;
|
|
condrestart|try-restart)
|
|
$0 status || exit 0
|
|
$0 restart
|
|
;;
|
|
restart)
|
|
$0 stop
|
|
$0 start
|
|
;;
|
|
|
|
status)
|
|
PID=`pidof -x -o $$ -o $PPID -o %PPID boinc_client`
|
|
if [ "$PID" == "" ]; 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 $LOCKFILE ]; then
|
|
echo "BOINC is stopped but lockfile(s) exist."
|
|
exit 2
|
|
else
|
|
echo "BOINC client is stopped."
|
|
exit 3
|
|
fi
|
|
fi
|
|
;;
|
|
|
|
*)
|
|
echo "Usage: boinc {start|stop|restart|condrestart|try-restart|reload|force-reload|status}"
|
|
exit 2
|
|
esac
|
|
|
|
exit
|
|
|
|
#EOF#
|