first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / database / configuration / boinc / etc / init.d / boinc
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 works on Red Hat Linux, Fedora Core, Mandrake, Debian,
9 #  and Slackware Linux, and should work on generic Linux systems
10 #  provided that they have 'pidof' (most do).   
11 #  Metadata for chkconfig and the SUSE equivalent INIT info are included below.
12 #
13 #  Usage:  boinc { start | stop | status | restart }
14 #  
15 ###
16 # chkconfig: 345 98 03
17 # description: This script starts the local BOINC client as a daemon
18 #         For more information about BOINC (the Berkeley Open Infrastructure
19 #         for Network Computing) see http://boinc.berkeley.edu
20 # processname: boinc
21 # config: /etc/sysconfig/boinc
22 #
23 ### BEGIN INIT INFO
24 # Provides: boinc
25 # Required-Start: $network
26 # Required-Stop:  $network
27 # Default-Start: 3 4 5
28 # Default-Stop: 0 1 2 6
29 # Description: This script starts the local BOINC client as a daemon
30 #         For more information about BOINC (the Berkeley Open Infrastructure
31 #         for Network Computing) see http://boinc.berkeley.edu
32 ### END INIT INFO
33 #
34 # Eric Myers <myers@vassar.edu>  - 27 July 2004
35 # Department of Physics and Astronomy, Vassar College, Poughkeepsie NY
36 # Eric Myers <myers@spy-hill.net> 
37 # Spy Hill Research, Poughkeepsie, New York
38 # @(#) $Id: boinc,v 1.8 2007/09/02 01:05:35 myers Exp $
39 ########################################################################
40
41 ##
42 # Defaults, which can be overridden in /etc/sysconfig/boinc  (Red Hat)
43 #           or /etc/default/boinc (Debian)
44
45 BOINCUSER=boinc
46 BOINCDIR=/home/boinc
47 BUILD_ARCH=i686-pc-linux-gnu
48 BOINCEXE=/usr/local/bin/boinc_client
49
50
51 # Log and error files (you should rotate these occasionally)
52 LOGFILE=boinc.log
53 ERRORLOG=error.log
54
55 # Additional BOINC options:
56 #   Be wary of -allow_remote_gui_rpc, as it can open your machine up
57 #   to the world if you don't set a password, or if you set a poor one.
58 #   Should be okay if you are behind a NAT firewall.  
59
60 #BOINCOPTS="-allow_remote_gui_rpc"   # opens up your machine to the world!
61
62
63 # Mandrake 10.1 really wants a subsys lock file ...
64 if [ -d /var/lock/subsys ]; then
65   LOCKDIR=/var/lock/subsys
66 elif [ -d /var/lock ]; then
67   LOCKDIR=/var/lock
68 fi
69
70 # su on Linux seems to need this to be set to work properly in a script
71 export TERM dumb
72
73
74 ##
75 # Init script function library.   This stuff is Red Hat specific,
76 #   but if the functions are not found we create our own simple replacements.
77 #   (The idea for replacing the functions comes from OpenAFS.  Thanks guys!)
78
79 if [ -f /etc/rc.d/init.d/functions ] ; then
80         . /etc/rc.d/init.d/functions
81 else
82         export PATH=/sbin:/bin:/usr/sbin:/usr/bin
83         function echo_success () { echo -n "    [  OK  ]  " ; }
84         function echo_failure () { echo -n "    [FAILED]  " ; }
85         function echo_warning () { echo -n "    [WARNING] " ; }
86         function killproc() {
87              PID=$(pidof -s -x -o $$ -o $PPID -o %PPID $1) 
88              [ $PID ] && kill $PID ; }
89 fi
90
91
92 ## Look for any local configuration settings which override all above
93
94 if [ -f /etc/sysconfig/boinc ]; then
95   . /etc/sysconfig/boinc
96 elif [ -f /etc/default/boinc ]; then
97   . /etc/default/boinc
98 fi
99
100
101 ## Verify the working directory exists:
102
103 if [ ! -d $BOINCDIR ]; then
104   echo -n "Cannot find BOINC directory $BOINCDIR "
105   echo_failure
106   echo 
107   exit 7
108 fi
109
110
111 # Some additional places to look for the client executable
112 # (Should do this after init.d/functions and sysconfig/boinc, which sets PATH)
113
114 export PATH=$BOINCDIR:/usr/local/bin:$PATH
115
116
117 ## Locate the executable, either boinc_client, boinc, 
118 ## or boinc_M.mm_.... with highest version number
119 ## We only do this if BOINCEXE set above isn't found and executable.
120
121 if [ ! -x $BOINCEXE ]; then
122   BOINCEXE=$(/usr/bin/which boinc_client 2>/dev/null)
123   if [ ! -x "$BOINCEXE" ]; then
124     BOINCEXE=$(/usr/bin/which boinc 2>/dev/null)
125     if [ ! -x "$BOINCEXE" ]; then
126       BOINCEXE=$(/bin/ls -1 $BOINCDIR/boinc_*_$BUILD_ARCH 2>/dev/null | tail  -1 )
127     fi
128   fi
129 fi
130
131 if [ ! -x "$BOINCEXE" ]; then
132   echo -n "Cannot find an executable for the BOINC client."
133   echo_failure
134   echo 
135   exit 2
136 fi
137
138
139
140 ## Functions: $1 is one of  start|stop|status|restart
141
142 case "$1" in
143   start)
144         cd $BOINCDIR
145
146         if [ -f lockfile ] ; then
147           echo -n "Another instance of BOINC is running (lockfile exists)."
148           echo_failure
149           echo 
150           exit 4  
151         fi
152
153         if [ ! -d projects ] ; then
154           echo -n "The BOINC client requires initialization."
155           echo_warning
156           echo 
157         fi
158
159         echo -n "Starting BOINC client as a daemon:  "
160         su $BOINCUSER -c "$BOINCEXE $BOINCOPTS" >>$LOGFILE 2>>$ERRORLOG &
161         sleep 1  
162         PID=$(pidof -s -x -o $$ -o $PPID -o %PPID $BOINCEXE)
163         if [ $PID ]; then
164           [ -d $LOCKDIR ] && touch $LOCKDIR/boinc
165           echo_success
166         else
167           echo_failure
168         fi
169         echo 
170         ;;
171
172   stop)
173         cd $BOINCDIR
174         if [ ! -f lockfile -a ! -f $LOCKDIR/boinc ] ; then
175           echo -n "BOINC is not running (no lockfiles found)."
176           echo_success
177         else
178           echo -n "Stopping BOINC client daemon:  "    
179           killproc $BOINCEXE  && echo_success  || echo_failure 
180           # clean up in any case
181           rm -f $BOINCDIR/lockfile
182           rm -f $LOCKDIR/boinc
183         fi
184         echo 
185         ;;
186
187   restart)
188         $0 stop
189         $0 start
190         ;;
191
192   status)
193         PID=$(pidof -x -o $$ -o $PPID -o %PPID boinc_client)
194         if [ "$PID" == "" ]; then
195           PID=$(pidof -x -o $$ -o $PPID -o %PPID $BOINCEXE)
196         fi
197         if [ "$PID" != "" ]; then
198           echo "BOINC client is running (pid $PID)."
199         else
200           if [ -f $BOINCDIR/lockfile -o -f $LOCKDIR/boinc ]; then 
201              echo "BOINC is stopped but lockfile(s) exist."
202           else 
203              echo "BOINC client is stopped."
204           fi
205         fi
206         ;;
207
208   *)
209         echo "Usage: boinc {start|stop|restart|status}"
210         exit 1
211 esac
212
213 exit
214
215 #EOF#