wok annotate boinc/stuff/boinc-client @ rev 23611

updated re2c (1.2.1 -> 1.3)
author Hans-G?nter Theisgen
date Tue Apr 14 06:45:07 2020 +0100 (2020-04-14)
parents 02c70d036ea0
children
rev   line source
samuel_trassare@11976 1 #!/bin/bash
samuel_trassare@11976 2 #
samuel_trassare@11976 3 # BOINC - start and stop the BOINC client daemon on Unix
samuel_trassare@11976 4 #
samuel_trassare@11976 5 # Unix start/stop script to run the BOINC client as a daemon at
samuel_trassare@11976 6 # system startup, as the 'boinc' user (not root!).
samuel_trassare@11976 7 #
samuel_trassare@11976 8 # This version should work on unixes that have bash, zsh, or ksh. If
samuel_trassare@11976 9 # started with another Bourne compatible shell, it will attempt to restart
samuel_trassare@11976 10 # in bash, zsh, or ksh.
samuel_trassare@11976 11 #
samuel_trassare@11976 12 # Metadata for chkconfig and the SUSE equivalent INIT info are included below.
samuel_trassare@11976 13 #
samuel_trassare@11976 14 # Usage: boinc { start | stop | status | reload | restart }
samuel_trassare@11976 15 #
samuel_trassare@11976 16
samuel_trassare@11976 17 # Defaults, which can be overridden by putting new NAME=value lines
samuel_trassare@11976 18 # in /etc/sysconfig/boinc-client, /etc/default/boinc-client,
samuel_trassare@11976 19 # /etc/boinc-client.conf, or the same files under ${sysconfdir}
samuel_trassare@11976 20
samuel_trassare@11976 21 ## These 4 installation dirs set by autoconf. ##########################
samuel_trassare@11976 22 prefix=`dirname /usr/.`
samuel_trassare@11976 23 exec_prefix=`dirname /usr/.`
samuel_trassare@11976 24 bindir=`dirname ${exec_prefix}/bin/.`
samuel_trassare@11976 25 sysconfdir=`dirname ${prefix}/etc/.`
samuel_trassare@11976 26 ########################################################################
samuel_trassare@11976 27
samuel_trassare@11976 28 # set the basic PATH
samuel_trassare@11976 29 PATH=/sbin:/bin:/usr/sbin:/usr/bin
samuel_trassare@11976 30 export PATH
samuel_trassare@11976 31
samuel_trassare@11976 32 # Use ps
samuel_trassare@11976 33 PS=ps
samuel_trassare@11976 34
samuel_trassare@11976 35 # Name of user to run as:
samuel_trassare@11976 36 #
samuel_trassare@11976 37 BOINCUSER=boinc
samuel_trassare@11976 38
samuel_trassare@11976 39 # Working directory. Could be /home/boinc, /var/lib/boinc, etc..
samuel_trassare@11976 40 # The reason I prefer /var/lib/boinc is that this works best for a
samuel_trassare@11976 41 # cluster of computers where /home/anything might be shared between machines
samuel_trassare@11976 42 #
samuel_trassare@11976 43 BOINCDIR=/var/lib/boinc
samuel_trassare@11976 44
samuel_trassare@11976 45 # Name of the client executable. This is the file "boinc" if you
samuel_trassare@11976 46 # unpacked the download file boinc_M.mm.rr_i686-pc-linux-gnu.sh,
samuel_trassare@11976 47 # but I like to rename it and put it in a public place.
samuel_trassare@11976 48 # (Hint: move boincmgr to /usr/local/bin too so anyone can easily use it).
samuel_trassare@11976 49 #
samuel_trassare@11976 50 BOINCEXE_NAME=boinc_client
samuel_trassare@11976 51 BOINCEXE=${bindir}/${BOINCEXE_NAME}
samuel_trassare@11976 52 BOINCCMD_NAME=boinccmd
samuel_trassare@11976 53 BOINCCMD=${bindir}/${BOINCCMD_NAME}
samuel_trassare@11976 54
samuel_trassare@11976 55 # Log files (you should rotate these occasionally)
samuel_trassare@11976 56 #
samuel_trassare@11976 57 LOGFILE=/var/log/${BOINCEXE_NAME}.log
samuel_trassare@11976 58 ERRORLOG=/var/log/${BOINCEXE_NAME}_err.log
samuel_trassare@11976 59
samuel_trassare@11976 60 # PID file
samuel_trassare@11976 61 PIDFILE=/var/run/${BOINCEXE_NAME}.pid
samuel_trassare@11976 62
samuel_trassare@11976 63 # BOINC options: for the command line when running the client.
samuel_trassare@11976 64 # Be aware that --allow_remote_gui_rpc opens up your machine to the world!
samuel_trassare@11976 65 #
samuel_trassare@11976 66 # Add this option if you want to allow boinc manager connections from remote
samuel_trassare@11976 67 # machines
samuel_trassare@11976 68 #BOINCOPTS="--allow_remote_gui_rpc"
samuel_trassare@11976 69 # Add this option if you want to turn off all logging
samuel_trassare@11976 70 #BOINCOPTS="--daemon"
samuel_trassare@11976 71 # Add this option if you want to redirect logging to the files stderrdae.txt
samuel_trassare@11976 72 # and stdoutdae.txt in BOINCDIR rather than LOGFILE and ERRORLOG
samuel_trassare@11976 73 #BOINCOPTS="--redirectio"
samuel_trassare@11976 74 # Add this option if you want to run only when no logins from anywhere are
samuel_trassare@11976 75 # active
samuel_trassare@11976 76 #BOINCOPTS="--check_all_logins"
samuel_trassare@11976 77 # The default is no options.
samuel_trassare@11976 78 BOINCOPTS="--dir $BOINCDIR"
samuel_trassare@11976 79
samuel_trassare@11976 80 # Subsys lock file ...
samuel_trassare@11976 81 LOCKFILE=/var/lock/${BOINCEXE_NAME}
samuel_trassare@11976 82
samuel_trassare@11976 83 # su on Linux seems to need this to be set to work properly in a script
samuel_trassare@11976 84 export TERM=dumb
samuel_trassare@11976 85
samuel_trassare@11976 86 ##
samuel_trassare@11976 87 # Init script function library. This stuff is Red Hat specific,
samuel_trassare@11976 88 # but if the functions are not found we create our own simple replacements.
samuel_trassare@11976 89 # (The idea for replacing the functions comes from OpenAFS. Thanks guys!)
samuel_trassare@11976 90
samuel_trassare@11976 91 if printf "Hello" >/dev/null 2>/dev/null ; then
samuel_trassare@11976 92 # printf works
samuel_trassare@11976 93 printcol='printf \033[60G%s'
samuel_trassare@11976 94 elif echo -en "Hello" >/dev/null 2>/dev/null ; then
samuel_trassare@11976 95 # echo -en works
samuel_trassare@11976 96 printcol='echo -en \033[60G'
samuel_trassare@11976 97 else
samuel_trassare@11976 98 # no printf make do with echo -n
samuel_trassare@11976 99 printcol="echo -n .........."
samuel_trassare@11976 100 fi
samuel_trassare@11976 101 function echo_success () { $printcol "[OK]" ; }
samuel_trassare@11976 102 function echo_failure () { $printcol "[FAILED]" ; }
samuel_trassare@11976 103 function echo_warning () { $printcol "[WARNING]" ; }
samuel_trassare@11976 104 function killproc() {
samuel_trassare@11976 105 PID=`local_pidof $1`
samuel_trassare@11976 106 [ $PID ] && kill $PID
samuel_trassare@11976 107 }
samuel_trassare@11976 108
samuel_trassare@11976 109 # Define pidof
samuel_trassare@11976 110 function local_pidof() {
samuel_trassare@11976 111 pidof -s -o $$ -o $PPID -o %PPID $1
samuel_trassare@11976 112 }
samuel_trassare@11976 113
samuel_trassare@11976 114 # Define runuser
samuel_trassare@11976 115 RUNUSER=su
samuel_trassare@11976 116
samuel_trassare@11976 117 # Some additional places to look for executables
samuel_trassare@11976 118 # (Should do this after init.d/functions and sysconfig/boinc, which sets PATH)
samuel_trassare@11976 119 export PATH=${PATH}:${exec_prefix}/sbin:${bindir}
samuel_trassare@11976 120
samuel_trassare@11976 121
samuel_trassare@11976 122 ## Look for any local configuration settings which override all above
samuel_trassare@11976 123 ## Note: ./boinc-client.conf and ./boinc.conf are for testing purposes
samuel_trassare@11976 124 config_files="
samuel_trassare@11976 125 ./boinc-client.conf
samuel_trassare@11976 126 ./boinc.conf
samuel_trassare@11976 127 /etc/boinc-client.conf
samuel_trassare@11976 128 /etc/boinc.conf
samuel_trassare@11976 129 none
samuel_trassare@11976 130 "
samuel_trassare@11976 131
samuel_trassare@11976 132 ## find the correct config file
samuel_trassare@11976 133 for config_file in $config_files ; do
samuel_trassare@11976 134 if [ -f ${config_file} ] ; then
samuel_trassare@11976 135 break;
samuel_trassare@11976 136 fi
samuel_trassare@11976 137 done
samuel_trassare@11976 138
samuel_trassare@11976 139 if [ "${config_file}" != "none" ]; then
samuel_trassare@11976 140 # check whether we are using a deprecated name
samuel_trassare@11976 141 if [ "x$NOWARNING" != "xyes" -a -z "`echo ${config_file} | grep boinc-client`" ]; then
samuel_trassare@11976 142 fn=`basename $config_file`
samuel_trassare@11976 143 dn=`dirname $config_file`
samuel_trassare@11976 144 newname=`echo $fn | sed 's/boinc/boinc-client/'`
samuel_trassare@11976 145 echo -n "The filename '${config_file}' is deprecated..."
samuel_trassare@11976 146 echo_warning
samuel_trassare@11976 147 echo
samuel_trassare@11976 148 echo -n "Please rename your config file to '${dn}/${newname}'"
samuel_trassare@11976 149 echo_warning
samuel_trassare@11976 150 echo
samuel_trassare@11976 151 fi
samuel_trassare@11976 152 # execute the config file.
samuel_trassare@11976 153 . ${config_file}
samuel_trassare@11976 154 fi
samuel_trassare@11976 155
samuel_trassare@11976 156
samuel_trassare@11976 157 ## Add ${BOINCDIR} to the path, just in case the executables are stored there.
samuel_trassare@11976 158 export PATH=${PATH}:${BOINCDIR}
samuel_trassare@11976 159
samuel_trassare@11976 160 ## Create the working directory if it doesn't exist:
samuel_trassare@11976 161 if [ ! -d $BOINCDIR ]; then
samuel_trassare@11976 162 echo -n "Creating $BOINCDIR "
samuel_trassare@11976 163 if mkdir -p $BOINCDIR 2>/dev/null ; then
samuel_trassare@11976 164 if [ -n "$BOINCUSER" ] ; then
samuel_trassare@11976 165 if chown $BOINCUSER $BOINCDIR ; then
samuel_trassare@11976 166 echo_success
samuel_trassare@11976 167 else
samuel_trassare@11976 168 echo_failure
samuel_trassare@11976 169 echo
samuel_trassare@11976 170 exit 7
samuel_trassare@11976 171 fi
samuel_trassare@11976 172 fi
samuel_trassare@11976 173 else
samuel_trassare@11976 174 echo_failure
samuel_trassare@11976 175 echo
samuel_trassare@11976 176 exit 7
samuel_trassare@11976 177 fi
samuel_trassare@11976 178 fi
samuel_trassare@11976 179
samuel_trassare@11976 180 ## Check what user we are running as:
samuel_trassare@11976 181 # we can't rely on the existence of "whoami" or "logname", so we'll use ps.
samuel_trassare@11976 182 USERNOW=`${PS} u $$ | tail -1 | awk '{print $2}'`
samuel_trassare@11976 183 if [ -z "$BOINCUSER" ] ; then
samuel_trassare@11976 184 BOINCUSER="${USERNOW}"
samuel_trassare@11976 185 fi
samuel_trassare@11976 186
samuel_trassare@11976 187 ## Check that BOINCUSER actually exists
samuel_trassare@11976 188 if [ -z "`grep ^${BOINCUSER}: /etc/passwd`" ] ; then
samuel_trassare@11976 189 if [ -z "`ypcat passwd 2>/dev/null | grep ^${BOINCUSER}:`" ] ; then
samuel_trassare@11976 190 if [ -z "`nidump passwd / 2>/dev/null | grep ^${BOINCUSER}:`" ] ; then
samuel_trassare@11976 191 echo -n ERROR: user ${BOINCUSER} does not exist.
samuel_trassare@11976 192 echo_failure
samuel_trassare@11976 193 echo
samuel_trassare@11976 194 exit 9
samuel_trassare@11976 195 fi
samuel_trassare@11976 196 fi
samuel_trassare@11976 197 fi
samuel_trassare@11976 198
samuel_trassare@11976 199 # if we are running as root, print a warning.
samuel_trassare@11976 200 if [ "x$NOWARNING" != "xyes" -a "$BOINCUSER" = "root" ] ; then
samuel_trassare@11976 201 echo -n WARNING: boinc-client will be running as root
samuel_trassare@11976 202 echo_warning
samuel_trassare@11976 203 echo
samuel_trassare@11976 204 fi
samuel_trassare@11976 205
samuel_trassare@11976 206 # check whether we will be able to write to the BOINC directory
samuel_trassare@11976 207 if [ "${USERNOW}" = "${BOINCUSER}" ] ; then
samuel_trassare@11976 208 if [ ! -O ${BOINCDIR} ] ; then
samuel_trassare@11976 209 echo -n ERROR: $BOINCDIR is not owned by $BOINCUSER.
samuel_trassare@11976 210 echo_failure
samuel_trassare@11976 211 echo
samuel_trassare@11976 212 exit 8
samuel_trassare@11976 213 fi
samuel_trassare@11976 214 elif [ "${USERNOW}" = "root" ] ; then
samuel_trassare@11976 215 cmd="if test -O ${BOINCDIR} ; then echo success ; fi"
samuel_trassare@11976 216 if [ -z `su $BOINCUSER -c "$cmd"` ]; then
samuel_trassare@11976 217 echo -n ERROR: $BOINCDIR is not owned by $BOINCUSER.
samuel_trassare@11976 218 echo_failure
samuel_trassare@11976 219 echo
samuel_trassare@11976 220 exit 8
samuel_trassare@11976 221 fi
samuel_trassare@11976 222 fi
samuel_trassare@11976 223
samuel_trassare@11976 224
samuel_trassare@11976 225 ## Locate the executable, either boinc_client, boinc,
samuel_trassare@11976 226 ## or boinc_M.mm_.... with highest version number
samuel_trassare@11976 227 ## We only do this if BOINCEXE set above isn't found or is not executable.
samuel_trassare@11976 228 if [ ! -x $BOINCEXE ]; then
samuel_trassare@11976 229 BOINCEXE=`$WHICH $BOINCEXE_NAME 2>/dev/null`
samuel_trassare@11976 230 if [ ! -x "$BOINCEXE" ]; then
samuel_trassare@11976 231 BOINCEXE=`$WHICH boinc 2>/dev/null`
samuel_trassare@11976 232 fi
samuel_trassare@11976 233 fi
samuel_trassare@11976 234
samuel_trassare@11976 235 if [ ! -x "$BOINCEXE" ]; then
samuel_trassare@11976 236 echo -n "Cannot find an executable for the BOINC client."
samuel_trassare@11976 237 echo_failure
samuel_trassare@11976 238 echo
samuel_trassare@11976 239 exit 2
samuel_trassare@11976 240 fi
samuel_trassare@11976 241
samuel_trassare@11976 242 ## boinccmd will probably be in the same place as the boinc_client
samuel_trassare@11976 243 if [ ! -x $BOINCCMD ]; then
samuel_trassare@11976 244 BOINCCMD=`$WHICH $BOINCCMD_NAME 2>/dev/null`
samuel_trassare@11976 245 if [ ! -x "$BOINCCMD" ]; then
samuel_trassare@11976 246 BOINCCMD=`dirname $BOINCEXE 2>/dev/null`/${BOINCCMD_NAME}
samuel_trassare@11976 247 fi
samuel_trassare@11976 248 fi
samuel_trassare@11976 249
samuel_trassare@11976 250
samuel_trassare@11976 251 if [ "x$NOWARNING" != "xyes" -a ! -x $BOINCCMD ]; then
samuel_trassare@11976 252 echo -n "Cannot find the boinccmd executable. Reload will fail."
samuel_trassare@11976 253 echo_warning
samuel_trassare@11976 254 echo
samuel_trassare@11976 255 fi
samuel_trassare@11976 256
samuel_trassare@11976 257 ## Functions: $1 is one of start|stop|status|reload|restart
samuel_trassare@11976 258
samuel_trassare@11976 259 export NOWARNING=no
samuel_trassare@11976 260
samuel_trassare@11976 261 case "$1" in
samuel_trassare@11976 262 start)
samuel_trassare@11976 263 cd $BOINCDIR
samuel_trassare@11976 264 PID=`local_pidof $BOINCEXE_NAME`
samuel_trassare@11976 265
samuel_trassare@11976 266 if [ -f lockfile -o -f $LOCKFILE ] ; then
samuel_trassare@11976 267 if [ -z "$PID" ] ; then
samuel_trassare@11976 268 # a lockfile exists, but boinc_client isn't running
samuel_trassare@11976 269 /bin/rm -f lockfile $LOCKFILE $PIDFILE 2>&1 > /dev/null
samuel_trassare@11976 270 else
samuel_trassare@11976 271 echo -n "Another instance of BOINC is running (PID=${PID})."
samuel_trassare@11976 272 echo_failure
samuel_trassare@11976 273 echo
samuel_trassare@11976 274 exit 1
samuel_trassare@11976 275 fi
samuel_trassare@11976 276 fi
samuel_trassare@11976 277
samuel_trassare@11976 278 if [ ! -d projects ] ; then
samuel_trassare@11976 279 echo -n "The BOINC client requires initialization."
samuel_trassare@11976 280 echo_warning
samuel_trassare@11976 281 echo
samuel_trassare@11976 282 fi
samuel_trassare@11976 283
samuel_trassare@11976 284 touch ${LOGFILE} ${ERRORLOG}
samuel_trassare@11976 285 NOCORE="ulimit -c 0 2>&1 >/dev/null"
samuel_trassare@11976 286 echo -n "Starting BOINC client as a daemon: "
samuel_trassare@11976 287 if [ "${BOINCUSER}" = "${USERNOW}" ] ; then
samuel_trassare@11976 288 # I am BOINCUSER. Just start client as me.
samuel_trassare@11976 289 $NOCORE
samuel_trassare@11976 290 $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG &
samuel_trassare@11976 291 else
samuel_trassare@11976 292 chown ${BOINCUSER} ${LOGFILE} ${ERRORLOG}
samuel_trassare@11976 293 if [ -f gui_rpc_auth.cfg ] ; then
samuel_trassare@11976 294 chmod g+r gui_rpc_auth.cfg
samuel_trassare@11976 295 fi
samuel_trassare@11976 296 ${RUNUSER} - $BOINCUSER -c "$NOCORE ; $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG" 2>/dev/null > /dev/null &
samuel_trassare@11976 297 fi
samuel_trassare@11976 298 sleep 3
samuel_trassare@11976 299 PID=`local_pidof $BOINCEXE_NAME`
samuel_trassare@11976 300 if [ $PID ]; then
samuel_trassare@11976 301 echo $PID > $PIDFILE
samuel_trassare@11976 302 touch $LOCKFILE && echo_success || ( echo_failure ; echo )
samuel_trassare@11976 303 fi
samuel_trassare@11976 304 echo
samuel_trassare@11976 305 ;;
samuel_trassare@11976 306 stop)
samuel_trassare@11976 307 cd $BOINCDIR
samuel_trassare@11976 308 if [ ! -f $PIDFILE -a ! -f lockfile -a ! -f $LOCKFILE ] ; then
samuel_trassare@11976 309 echo -n "BOINC is not running (no lockfiles found)."
samuel_trassare@11976 310 echo_success
samuel_trassare@11976 311 else
samuel_trassare@11976 312 echo -n "Stopping BOINC client daemon: "
samuel_trassare@11976 313 if [ -f $PIDFILE ] ; then
samuel_trassare@11976 314 PID=`cat $PIDFILE`
samuel_trassare@11976 315 if [ -n "`${PS} $PID | grep $PID`" ] ; then
samuel_trassare@11976 316 kill `cat $PIDFILE`
samuel_trassare@11976 317 sleep 5
samuel_trassare@11976 318 fi
samuel_trassare@11976 319 echo_success
samuel_trassare@11976 320 else
samuel_trassare@11976 321 killproc $BOINCEXE_NAME && echo_success || echo_failure
samuel_trassare@11976 322 fi
samuel_trassare@11976 323 # clean up in any case
samuel_trassare@11976 324 rm -f lockfile 2>/dev/null >/dev/null
samuel_trassare@11976 325 rm -f $LOCKFILE 2>/dev/null
samuel_trassare@11976 326 rm -f $PIDFILE 2>/dev/null
samuel_trassare@11976 327 fi
samuel_trassare@11976 328 echo
samuel_trassare@11976 329 ;;
samuel_trassare@11976 330 reload)
samuel_trassare@11976 331 if [ ! -f lockfile -a ! -f $LOCKFILE ] ; then
samuel_trassare@11976 332 echo "BOINC is not running (no lockfiles found) -- starting service."
samuel_trassare@11976 333 $0 start
samuel_trassare@11976 334 else
samuel_trassare@11976 335 $BOINCCMD --read_cc_config >>$LOGFILE 2>>$ERRORLOG && echo_success || $0 restart
samuel_trassare@11976 336 fi
samuel_trassare@11976 337 ;;
samuel_trassare@11976 338 restart)
samuel_trassare@11976 339 $0 stop
samuel_trassare@11976 340 $0 start
samuel_trassare@11976 341 ;;
samuel_trassare@11976 342
samuel_trassare@11976 343 status)
samuel_trassare@11976 344 PID=`cat $PIDFILE 2>/dev/null`
al@20904 345 if [ -n "$PID" ]; then
samuel_trassare@11976 346 # is it still running?
samuel_trassare@11976 347 if [ -z "`${PS} $PID | grep $PID`" ]; then
samuel_trassare@11976 348 # not running. Try the other tests.
samuel_trassare@11976 349 PID=""
samuel_trassare@11976 350 fi
samuel_trassare@11976 351 fi
al@20904 352 if [ -z "$PID" ]; then
samuel_trassare@11976 353 PID=`local_pidof $BOINCEXE_NAME`
samuel_trassare@11976 354 fi
al@20904 355 if [ -z "$PID" ]; then
samuel_trassare@11976 356 PID=`local_pidof $BOINCEXE`
samuel_trassare@11976 357 fi
al@20904 358 if [ -n "$PID" ]; then
samuel_trassare@11976 359 echo "BOINC client is running (pid $PID)."
samuel_trassare@11976 360 else
samuel_trassare@11976 361 if [ -f $BOINCDIR/lockfile -o -f $LOCKFILE ]; then
samuel_trassare@11976 362 echo "BOINC is stopped but lockfile(s) exist."
samuel_trassare@11976 363 exit 2
samuel_trassare@11976 364 else
samuel_trassare@11976 365 echo "BOINC client is stopped."
samuel_trassare@11976 366 exit 3
samuel_trassare@11976 367 fi
samuel_trassare@11976 368 fi
samuel_trassare@11976 369 ;;
samuel_trassare@11976 370
samuel_trassare@11976 371 *)
samuel_trassare@11976 372 echo "Usage: boinc {start|stop|restart|reload|status}"
samuel_trassare@11976 373 exit 1
samuel_trassare@11976 374 esac
samuel_trassare@11976 375
samuel_trassare@11976 376 exit
samuel_trassare@11976 377
samuel_trassare@11976 378 #EOF#