3
# BOINC - start and stop the BOINC client daemon on Unix
5
# Unix start/stop script to run the BOINC client as a daemon at
6
# system startup, as the 'boinc' user (not root!).
8
# This version should work on unixes that have bash, zsh, or ksh. If
9
# started with another Bourne compatible shell, it will attempt to restart
10
# in bash, zsh, or ksh.
12
# Metadata for chkconfig and the SUSE equivalent INIT info are included below.
14
# Usage: boinc { start | stop | status | reload | restart }
17
# chkconfig: 345 98 02
18
# description: This script starts the local BOINC client as a daemon
19
# For more information about BOINC (the Berkeley Open Infrastructure
20
# for Network Computing) see http://boinc.berkeley.edu
22
# config: /etc/sysconfig/boinc
26
# Required-Start: $network
27
# Required-Stop: $network
28
# Default-Start: 3 4 5
29
# Default-Stop: 0 1 2 6
30
# Short-Description: This script monitors the BOINC client.
31
# Description: This script starts the local BOINC client as a daemon
32
# For more information about BOINC (the Berkeley Open Infrastructure
33
# for Network Computing) see http://boinc.berkeley.edu
36
# Eric Myers <myers@vassar.edu> - 27 July 2004
37
# Department of Physics and Astronomy, Vassar College, Poughkeepsie NY
38
# Eric Myers <myers@spy-hill.net>
39
# Spy Hill Research, Poughkeepsie, New York
40
# @(#) $Id: boinc,v 1.10 2007/12/27 20:09:09 myers Exp $
42
# Modified by Eric Korpela <korpela@ssl.berkeley.edu> - 11 Apr 2008
43
########################################################################
45
# Defaults, which can be overridden by putting new NAME=value lines
46
# in /etc/sysconfig/boinc-client, /etc/default/boinc-client,
47
# /etc/boinc-client.conf, or the same files under ${sysconfdir}
49
## These 4 installation dirs set by autoconf. ##########################
50
prefix=`dirname @prefix@/.`
51
exec_prefix=`dirname @exec_prefix@/.`
52
bindir=`dirname @bindir@/.`
53
sysconfdir=`dirname @sysconfdir@/.`
54
########################################################################
57
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/ucb/bin
59
# Find the correct ps to use. On solaris /usr/ucb/ps is the one to use
60
# on everything else, we hope the first one in the path is the right one.
61
if [ -x /usr/ucb/ps ] ; then
67
########################################################################
69
# Figure out if we are running under an acceptable shell
70
# (bash, ksh, zsh) which supports functions.
72
########################################################################
74
# count how many times we've tried to restart
76
if [ -z "$TRIES" ] ; then
79
# bash and zsh are easy to test.
80
if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ] ; then
81
# we aren't running under bash or zsh, check for ksh
82
if [ -z "`echo ${ENV} | grep ksh`" ] ; then
83
# still might be ksh. One last shot.
84
if [ -z "`${PS} $$ | tail -1 | grep ksh`" ] ; then
85
# as far as I can tell we aren't in an approved shell
86
TRIES=`expr $TRIES + 1`
87
# have we tried too many times?
88
if [ $TRIES -gt 4 ] ; then
89
echo "ERROR: endless loop discovered in $0 [ERROR]"
92
for try in $SHELLS ; do
94
if [ ! -z "${ex}" -a -x "${ex}" ] ; then
95
if ${ex} $0 $TRIES ; then
96
# it worked, we can exit
99
# it failed for some reason that should have been printed
105
# if we got here, we tried everything.
106
echo "ERROR: $0 requires bash, zsh, or ksh to run. [FALIED]"
109
#if we got here or below, were in an approved shell.
112
########################################################################
115
# Name of user to run as:
119
# Working directory. Could be /home/boinc, /var/lib/boinc, etc..
120
# The reason I prefer /var/lib/boinc is that this works best for a
121
# cluster of computers where /home/anything might be shared between machines
123
BOINCDIR=/var/lib/boinc
125
# Name of the client executable. This is the file "boinc" if you
126
# unpacked the download file boinc_M.mm.rr_i686-pc-linux-gnu.sh,
127
# but I like to rename it and put it in a public place.
128
# (Hint: move boincmgr to /usr/local/bin too so anyone can easily use it).
130
BOINCEXE_NAME=boinc_client
131
BOINCEXE=${bindir}/${BOINCEXE_NAME}
132
BOINCCMD_NAME=boinccmd
133
BOINCCMD=${bindir}/${BOINCCMD_NAME}
135
# Log files (you should rotate these occasionally)
137
LOGFILE=/var/log/${BOINCEXE_NAME}.log
138
ERRORLOG=/var/log/${BOINCEXE_NAME}_err.log
141
PIDFILE=/var/run/${BOINCEXE_NAME}.pid
143
# BOINC options: for the command line when running the client.
144
# Be aware that --allow_remote_gui_rpc opens up your machine to the world!
146
# Add this option if you want to allow boinc manager connections from remote
148
#BOINCOPTS="--allow_remote_gui_rpc"
149
# Add this option if you want to turn off all logging
150
#BOINCOPTS="--daemon"
151
# Add this option if you want to redirect logging to the files stderrdae.txt
152
# and stdoutdae.txt in BOINCDIR rather than LOGFILE and ERRORLOG
153
#BOINCOPTS="--redirectio"
154
# Add this option if you want to run only when no logins from anywhere are
156
#BOINCOPTS="--check_all_logins"
157
# The default is no options.
160
# Subsys lock file ...
162
# If there is the subsys directory, then use it ...
163
if [ -d /var/lock/subsys/ ]; then
164
LOCKFILE=/var/lock/subsys/boinc-client
165
elif [ -d /var/lock ]; then
166
LOCKFILE=/var/lock/boinc-client
169
# su on Linux seems to need this to be set to work properly in a script
174
# Init script function library. This stuff is Red Hat specific,
175
# but if the functions are not found we create our own simple replacements.
176
# (The idea for replacing the functions comes from OpenAFS. Thanks guys!)
178
if [ -f /etc/rc.d/init.d/functions ] ; then
179
. /etc/rc.d/init.d/functions
180
if `printf "Hello" >/dev/null 2>/dev/null` ; then
182
printcol='printf \033[60G%s'
183
if `echo -en "Hello" >/dev/null 2>/dev/null` ; then
185
printcol='echo -en \033[60G'
187
# no printf make do with echo -n
188
printcol="echo -n .........."
190
function echo_success () { $printcol "[OK]" ; }
191
function echo_failure () { $printcol "[FAILED]" ; }
192
function echo_warning () { $printcol "[WARNING]" ; }
193
function killproc() {
195
[ $PID ] && kill $PID
199
# check if we have pidof. If not use ps and grep for the same job.
200
if [ -x /sbin/pidof ] ; then
201
function local_pidof() {
202
pidof -s -x -o $$ -o $PPID -o %PPID $1
205
function local_pidof() {
206
${PS} xaugww | sed 's/$/ /' | grep "[ /]$1 " | grep -v $$ | grep -v $PPID | grep -v %PPID | grep -v grep | awk '{print $2}'
211
# Check if we have runuser, since it will never hang waiting for a password.
212
# If we don't have it, use su for the same job.
214
if [ ! -x /sbin/runuser ] ; then
218
# Some additional places to look for executables
219
# (Should do this after init.d/functions and sysconfig/boinc, which sets PATH)
220
export PATH=${PATH}:${exec_prefix}/sbin:${bindir}
223
## Look for any local configuration settings which override all above
224
## Note: ./boinc-client.conf and ./boinc.conf are for testing purposes
228
/etc/sysconfig/boinc-client
229
/etc/default/boinc-client
230
/etc/boinc-client.conf
231
${sysconfdir}/sysconfig/boinc-client
232
${sysconfdir}/default/boinc-client
233
${sysconfdir}/boinc-client.conf
237
${sysconfdir}/sysconfig/boinc
238
${sysconfdir}/default/boinc
239
${sysconfdir}/boinc.conf
243
## find the correct config file
244
for config_file in $config_files ; do
245
if [ -f ${config_file} ] ; then
250
if [ "${config_file}" != "none" ]; then
251
# check whether we are using a deprecated name
252
if [ "x$NOWARNING" != "xyes" -a -z "`echo ${config_file} | grep boinc-client`" ]; then
253
fn=`basename $config_file`
254
dn=`dirname $config_file`
255
newname=`echo $fn | sed 's/boinc/boinc-client/'`
256
echo -n "The filename '${config_file}' is deprecated..."
259
echo -n "Please rename your config file to '${dn}/${newname}'"
263
# execute the config file.
267
## Add ${BOINCDIR} to the path, just in case the executables are stored there.
268
export PATH=${PATH}:${BOINCDIR}
270
## Create the working directory if it doesn't exist:
271
if [ ! -d $BOINCDIR ]; then
272
echo -n "Creating $BOINCDIR "
273
if mkdir -p $BOINCDIR 2>/dev/null ; then
274
if [ -n "$BOINCUSER" ] ; then
275
if chown $BOINCUSER $BOINCDIR ; then
290
## Check what user we are running as:
292
if [ -z "$BOINCUSER" ] ; then
293
BOINCUSER="${USERNOW}"
296
## Check that BOINCUSER actually exists
297
if [ -z "`grep ^${BOINCUSER}: /etc/passwd`" ] ; then
298
if [ -z "`ypcat passwd 2>/dev/null | grep ^${BOINCUSER}:`" ] ; then
299
if [ -z "`nidump passwd / 2>/dev/null | grep ^${BOINCUSER}:`" ] ; then
300
echo -n ERROR: user ${BOINCUSER} does not exist.
308
# if we are running as root, print a warning.
309
if [ "x$NOWARNING" != "xyes" -a "$BOINCUSER" = "root" ] ; then
310
echo -n WARNING: boinc-client will be running as root
315
# check whether we will be able to write to the BOINC directory
316
if [ "${USERNOW}" = "${BOINCUSER}" ] ; then
317
if [ ! -O ${BOINCDIR} ] ; then
318
echo -n ERROR: $BOINCDIR is not owned by $BOINCUSER.
323
elif [ "${USERNOW}" = "root" ] ; then
324
if [ -z `su -s /bin/sh $BOINCUSER -c "if test -O ${BOINCDIR} ; then echo success ; fi"` ]; then
325
echo -n ERROR: $BOINCDIR is not owned by $BOINCUSER.
333
## Locate the executable, either boinc_client, boinc,
334
## or boinc_M.mm_.... with highest version number
335
## We only do this if BOINCEXE set above isn't found or is not executable.
336
if [ ! -x $BOINCEXE ]; then
337
BOINCEXE=`$WHICH $BOINCEXE_NAME 2>/dev/null`
338
if [ ! -x "$BOINCEXE" ]; then
339
BOINCEXE=`$WHICH boinc 2>/dev/null`
343
if [ ! -x "$BOINCEXE" ]; then
344
echo -n "Cannot find an executable for the BOINC client."
350
## boinccmd will probably be in the same place as the boinc_client
351
if [ ! -x $BOINCCMD ]; then
352
BOINCCMD=`$WHICH $BOINCCMD_NAME 2>/dev/null`
353
if [ ! -x "$BOINCCMD" ]; then
354
BOINCCMD=`dirname $BOINCEXE 2>/dev/null`/${BOINCCMD_NAME}
359
if [ "x$NOWARNING" != "xyes" -a ! -x $BOINCCMD ]; then
360
echo -n "Cannot find the boinccmd executable. Reload will fail."
365
## Functions: $1 is one of start|stop|status|reload|restart
372
PID=`local_pidof $BOINCEXE_NAME`
374
if [ -f lockfile -o -f $LOCKFILE ] ; then
375
if [ -z "$PID" ] ; then
376
# a lockfile exists, but boinc_client isn't running
377
/bin/rm -f lockfile $LOCKFILE $PIDFILE 2>&1 > /dev/null
379
echo -n "Another instance of BOINC is running (PID=${PID})."
386
if [ ! -d projects ] ; then
387
echo -n "The BOINC client requires initialization."
392
NOCORE="ulimit -c 0 2>&1 >/dev/null"
393
echo -n "Starting BOINC client as a daemon: "
394
if [ "${BOINCUSER}" = "${USERNOW}" ] ; then
395
# I am BOINCUSER. Just start client as me.
397
$BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG &
399
runuser - $BOINCUSER -c "$NOCORE ; $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG"
402
PID=`local_pidof $BOINCEXE_NAME`
405
touch $LOCKFILE && echo_success || ( echo_failure ; echo )
411
if [ ! -f $PIDFILE -a ! -f lockfile -a ! -f $LOCKFILE ] ; then
412
echo -n "BOINC is not running (no lockfiles found)."
415
echo -n "Stopping BOINC client daemon: "
416
if [ -f $PIDFILE ] ; then
418
if [ -n "`${PS} $PID | grep $PID`" ] ; then
422
if [ -z "`${PS} $PID | grep $PID`" ] ; then
429
killproc $BOINCEXE_NAME && echo_success || echo_failure
431
# clean up in any case
432
rm -f lockfile 2>/dev/null >/dev/null
433
rm -f $LOCKFILE 2>/dev/null
434
rm -f $PIDFILE 2>/dev/null
439
if [ ! -f lockfile -a ! -f $LOCKFILE ] ; then
440
echo "BOINC is not running (no lockfiles found) -- starting service."
443
$BOINCCMD --read_cc_config >>$LOGFILE 2>>$ERRORLOG && echo_success || $0 restart
452
PID=`cat $PIDFILE 2>/dev/null`
453
if [ "$PID" != "" ]; then
454
# is it still running?
455
if [ -z "`${PS} $PID | grep $PID`" ]; then
456
# not running. Try the other tests.
460
if [ "$PID" == "" ]; then
461
PID=`local_pidof $BOINCEXE_NAME`
463
if [ "$PID" == "" ]; then
464
PID=`local_pidof $BOINCEXE`
466
if [ "$PID" != "" ]; then
467
echo "BOINC client is running (pid $PID)."
469
if [ -f $BOINCDIR/lockfile -o -f $LOCKFILE ]; then
470
echo "BOINC is stopped but lockfile(s) exist."
473
echo "BOINC client is stopped."
480
echo "Usage: boinc {start|stop|restart|reload|status}"