~ubuntu-branches/ubuntu/lucid/boinc/lucid

« back to all changes in this revision

Viewing changes to client/scripts/boinc-client.in

  • Committer: Bazaar Package Importer
  • Author(s): Frank S. Thomas, Frank S. Thomas
  • Date: 2008-05-31 08:02:47 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20080531080247-4ce890lp2rc768cr
Tags: 6.2.7-1
[ Frank S. Thomas ]
* New upstream release.
  - BOINC Manager: Redraw disk usage charts immediately after connecting to
    a (different) client. (closes: 463823)
* debian/copyright:
  - Added the instructions from debian/README.Debian-source about how
    repackaged BOINC tarballs can be reproduced because DevRef now
    recommends to put this here instead of in the afore-mentioned file.
  - Updated for the new release.
* Removed the obsolete debian/README.Debian-source.
* For consistency upstream renamed the core client and the command tool
  ("boinc_client" to "boinc" and "boinc_cmd" to "boinccmd"). Done the same
  in all packages and created symlinks with the old names for the binaries
  and man pages. Also added an entry in debian/boinc-client.NEWS explaining
  this change.
* debian/rules: Do not list Makefile.ins in the clean target individually,
  just remove all that can be found.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh 
 
2
#
 
3
# BOINC - start and stop the BOINC client daemon on Unix
 
4
#
 
5
#  Unix start/stop script to run the BOINC client as a daemon at
 
6
#  system startup, as the 'boinc' user (not root!).
 
7
#
 
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.
 
11
#
 
12
#  Metadata for chkconfig and the SUSE equivalent INIT info are included below.
 
13
#
 
14
#  Usage:  boinc { start | stop | status | reload | restart }
 
15
#  
 
16
###
 
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
 
21
# processname: boinc
 
22
# config: /etc/sysconfig/boinc
 
23
#
 
24
### BEGIN INIT INFO
 
25
# Provides: 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
 
34
### END INIT INFO
 
35
#
 
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 $
 
41
#
 
42
# Modified by Eric Korpela <korpela@ssl.berkeley.edu> - 11 Apr 2008
 
43
########################################################################
 
44
 
 
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}
 
48
 
 
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
########################################################################
 
55
 
 
56
# set the basic PATH
 
57
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/ucb/bin
 
58
 
 
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
 
62
  PS=/usr/ucb/ps
 
63
else
 
64
  PS=ps
 
65
fi
 
66
 
 
67
########################################################################
 
68
#
 
69
# Figure out if we are running under an acceptable shell 
 
70
# (bash, ksh, zsh) which supports functions.
 
71
#
 
72
########################################################################
 
73
SHELLS="bash ksh zsh"
 
74
# count how many times we've tried to restart
 
75
TRIES=$1
 
76
if [ -z "$TRIES" ] ; then
 
77
  TRIES=0
 
78
fi
 
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]"
 
90
        exit 1
 
91
      fi
 
92
      for try in $SHELLS ; do
 
93
        ex=`which $try`
 
94
        if [ ! -z "${ex}" -a -x "${ex}" ] ; then
 
95
          if ${ex} $0 $TRIES ; then
 
96
            # it worked, we can exit
 
97
            exit 0
 
98
          else
 
99
            # it failed for some reason that should have been printed
 
100
            # by the script
 
101
            exit 1
 
102
          fi
 
103
        fi
 
104
      done
 
105
      # if we got here, we tried everything.
 
106
      echo "ERROR: $0 requires bash, zsh, or ksh to run.        [FALIED]"
 
107
      exit 1
 
108
    fi
 
109
    #if we got here or below, were in an approved shell.
 
110
  fi
 
111
fi
 
112
########################################################################
 
113
 
 
114
 
 
115
# Name of user to run as:
 
116
#
 
117
BOINCUSER=boinc
 
118
 
 
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
 
122
#
 
123
BOINCDIR=/var/lib/boinc
 
124
 
 
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).
 
129
#
 
130
BOINCEXE_NAME=boinc_client
 
131
BOINCEXE=${bindir}/${BOINCEXE_NAME}
 
132
BOINCCMD_NAME=boinccmd
 
133
BOINCCMD=${bindir}/${BOINCCMD_NAME}
 
134
 
 
135
# Log files (you should rotate these occasionally)
 
136
#
 
137
LOGFILE=/var/log/${BOINCEXE_NAME}.log
 
138
ERRORLOG=/var/log/${BOINCEXE_NAME}_err.log
 
139
 
 
140
# PID file
 
141
PIDFILE=/var/run/${BOINCEXE_NAME}.pid
 
142
 
 
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!
 
145
#
 
146
# Add this option if you want to allow boinc manager connections from remote
 
147
# machines
 
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 
 
155
# active
 
156
#BOINCOPTS="--check_all_logins"
 
157
# The default is no options.
 
158
BOINCOPTS=
 
159
 
 
160
# Subsys lock file ...
 
161
 
 
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
 
167
fi
 
168
 
 
169
# su on Linux seems to need this to be set to work properly in a script
 
170
export TERM=dumb
 
171
 
 
172
 
 
173
##
 
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!)
 
177
 
 
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
 
181
           # printf works
 
182
           printcol='printf \033[60G%s'
 
183
        if `echo -en "Hello" >/dev/null 2>/dev/null` ; then
 
184
           # echo -en works
 
185
           printcol='echo -en \033[60G'
 
186
        else
 
187
           # no printf make do with echo -n
 
188
           printcol="echo -n .........."
 
189
        fi
 
190
        function echo_success () { $printcol "[OK]" ; }
 
191
        function echo_failure () { $printcol "[FAILED]" ; }
 
192
        function echo_warning () { $printcol "[WARNING]" ; }
 
193
        function killproc() {
 
194
             PID=`local_pidof $1`
 
195
             [ $PID ] && kill $PID 
 
196
        }
 
197
fi
 
198
 
 
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 
 
203
  } 
 
204
else
 
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}'
 
207
  }
 
208
fi
 
209
 
 
210
#
 
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.
 
213
 
214
if [ ! -x /sbin/runuser ] ; then
 
215
  alias runuser=su
 
216
fi
 
217
 
 
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}
 
221
 
 
222
 
 
223
## Look for any local configuration settings which override all above
 
224
## Note: ./boinc-client.conf and ./boinc.conf are for testing purposes
 
225
config_files="
 
226
./boinc-client.conf
 
227
./boinc.conf
 
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
 
234
/etc/sysconfig/boinc
 
235
/etc/default/boinc
 
236
/etc/boinc.conf
 
237
${sysconfdir}/sysconfig/boinc
 
238
${sysconfdir}/default/boinc
 
239
${sysconfdir}/boinc.conf
 
240
none
 
241
"
 
242
 
 
243
## find the correct config file
 
244
for config_file in $config_files ; do
 
245
  if [ -f ${config_file} ] ; then 
 
246
    break; 
 
247
  fi
 
248
done
 
249
 
 
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..."
 
257
    echo_warning
 
258
    echo
 
259
    echo -n "Please rename your config file to '${dn}/${newname}'"
 
260
    echo_warning
 
261
    echo
 
262
  fi
 
263
  # execute the config file.
 
264
  . ${config_file}
 
265
fi
 
266
 
 
267
## Add ${BOINCDIR} to the path, just in case the executables are stored there.
 
268
export PATH=${PATH}:${BOINCDIR}
 
269
 
 
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
 
276
        echo_success
 
277
      else
 
278
        echo_failure
 
279
        echo
 
280
        exit 7
 
281
      fi
 
282
    fi
 
283
  else
 
284
    echo_failure
 
285
    echo
 
286
    exit 7
 
287
  fi
 
288
fi
 
289
 
 
290
## Check what user we are running as:
 
291
USERNOW=`whoami`
 
292
if [ -z "$BOINCUSER" ] ; then
 
293
  BOINCUSER="${USERNOW}"
 
294
fi
 
295
 
 
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.
 
301
       echo_failure
 
302
       echo
 
303
       exit 9
 
304
    fi
 
305
  fi
 
306
fi
 
307
 
 
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
 
311
  echo_warning
 
312
  echo
 
313
fi
 
314
 
 
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.
 
319
    echo_failure
 
320
    echo
 
321
    exit 8
 
322
  fi
 
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.
 
326
    echo_failure
 
327
    echo
 
328
    exit 8
 
329
  fi
 
330
fi
 
331
 
 
332
 
 
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`
 
340
  fi
 
341
fi
 
342
 
 
343
if [ ! -x "$BOINCEXE" ]; then
 
344
  echo -n "Cannot find an executable for the BOINC client."
 
345
  echo_failure
 
346
  echo 
 
347
  exit 2
 
348
fi
 
349
 
 
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}
 
355
  fi
 
356
fi
 
357
 
 
358
 
 
359
if [ "x$NOWARNING" != "xyes" -a ! -x $BOINCCMD ]; then
 
360
  echo -n "Cannot find the boinccmd executable.  Reload will fail."
 
361
  echo_warning
 
362
  echo
 
363
fi
 
364
 
 
365
## Functions: $1 is one of  start|stop|status|reload|restart
 
366
 
 
367
export NOWARNING=yes
 
368
 
 
369
case "$1" in
 
370
  start)
 
371
        cd $BOINCDIR
 
372
        PID=`local_pidof $BOINCEXE_NAME`
 
373
 
 
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
 
378
          else 
 
379
            echo -n "Another instance of BOINC is running (PID=${PID})."
 
380
            echo_failure
 
381
            echo 
 
382
            exit 1
 
383
          fi
 
384
        fi
 
385
 
 
386
        if [ ! -d projects ] ; then
 
387
          echo -n "The BOINC client requires initialization."
 
388
          echo_warning
 
389
          echo 
 
390
        fi
 
391
 
 
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.
 
396
           $NOCORE
 
397
           $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG &
 
398
        else
 
399
           runuser - $BOINCUSER -c "$NOCORE ; $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG"
 
400
        fi
 
401
        sleep 3  
 
402
        PID=`local_pidof $BOINCEXE_NAME`
 
403
        if [ $PID ]; then
 
404
          echo $PID > $PIDFILE
 
405
          touch $LOCKFILE && echo_success || ( echo_failure ; echo )
 
406
        fi
 
407
        echo
 
408
        ;;
 
409
  stop)
 
410
        cd $BOINCDIR
 
411
        if [ ! -f $PIDFILE -a ! -f lockfile -a ! -f $LOCKFILE ] ; then
 
412
          echo -n "BOINC is not running (no lockfiles found)."
 
413
          echo_success
 
414
        else
 
415
          echo -n "Stopping BOINC client daemon:  "    
 
416
          if [ -f $PIDFILE ] ; then
 
417
            PID=`cat $PIDFILE`
 
418
            if [ -n "`${PS} $PID | grep $PID`" ] ; then
 
419
              kill `cat $PIDFILE`
 
420
              sleep 5
 
421
            fi
 
422
            if [ -z "`${PS} $PID | grep $PID`" ] ; then
 
423
              echo_success
 
424
            else
 
425
              echo_failure
 
426
              echo
 
427
            fi
 
428
          else
 
429
            killproc $BOINCEXE_NAME  && echo_success  || echo_failure 
 
430
          fi
 
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
 
435
        fi
 
436
        echo
 
437
        ;;
 
438
  reload)
 
439
        if [ ! -f lockfile -a ! -f $LOCKFILE ] ; then
 
440
          echo  "BOINC is not running (no lockfiles found) -- starting service."
 
441
          $0 start
 
442
        else
 
443
          $BOINCCMD --read_cc_config >>$LOGFILE 2>>$ERRORLOG && echo_success || $0 restart
 
444
        fi
 
445
        ;;
 
446
  restart)
 
447
        $0 stop
 
448
        $0 start
 
449
        ;;
 
450
 
 
451
  status)
 
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.
 
457
            PID=""
 
458
          fi
 
459
        fi
 
460
        if [ "$PID" == "" ]; then
 
461
          PID=`local_pidof $BOINCEXE_NAME`
 
462
        fi
 
463
        if [ "$PID" == "" ]; then
 
464
          PID=`local_pidof $BOINCEXE`
 
465
        fi
 
466
        if [ "$PID" != "" ]; then
 
467
          echo "BOINC client is running (pid $PID)."
 
468
        else
 
469
          if [ -f $BOINCDIR/lockfile -o -f $LOCKFILE ]; then 
 
470
             echo "BOINC is stopped but lockfile(s) exist."
 
471
             exit 2
 
472
          else 
 
473
             echo "BOINC client is stopped."
 
474
             exit 3
 
475
          fi
 
476
        fi
 
477
        ;;
 
478
 
 
479
  *)
 
480
        echo "Usage: boinc {start|stop|restart|reload|status}"
 
481
        exit 1
 
482
esac
 
483
 
 
484
exit
 
485
 
 
486
#EOF#