wok-6.x diff boinc/stuff/boinc-client @ rev 15772

linux-source: install initrd.cpio
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jan 07 23:03:08 2014 +0000 (2014-01-07)
parents
children 02c70d036ea0
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/boinc/stuff/boinc-client	Tue Jan 07 23:03:08 2014 +0000
     1.3 @@ -0,0 +1,378 @@
     1.4 +#!/bin/bash 
     1.5 +#
     1.6 +# BOINC - start and stop the BOINC client daemon on Unix
     1.7 +#
     1.8 +#  Unix start/stop script to run the BOINC client as a daemon at
     1.9 +#  system startup, as the 'boinc' user (not root!).
    1.10 +#
    1.11 +#  This version should work on unixes that have bash, zsh, or ksh.  If 
    1.12 +#  started with another Bourne compatible shell, it will attempt to restart 
    1.13 +#  in bash, zsh, or ksh.
    1.14 +#
    1.15 +#  Metadata for chkconfig and the SUSE equivalent INIT info are included below.
    1.16 +#
    1.17 +#  Usage:  boinc { start | stop | status | reload | restart }
    1.18 +#  
    1.19 +
    1.20 +# Defaults, which can be overridden by putting new NAME=value lines 
    1.21 +#  in /etc/sysconfig/boinc-client, /etc/default/boinc-client, 
    1.22 +#  /etc/boinc-client.conf, or the same files under ${sysconfdir}
    1.23 +
    1.24 +## These 4 installation dirs set by autoconf. ##########################
    1.25 +prefix=`dirname /usr/.`
    1.26 +exec_prefix=`dirname /usr/.`
    1.27 +bindir=`dirname ${exec_prefix}/bin/.`
    1.28 +sysconfdir=`dirname ${prefix}/etc/.`
    1.29 +########################################################################
    1.30 +
    1.31 +# set the basic PATH
    1.32 +PATH=/sbin:/bin:/usr/sbin:/usr/bin
    1.33 +export PATH
    1.34 +
    1.35 +# Use ps
    1.36 +PS=ps
    1.37 +
    1.38 +# Name of user to run as:
    1.39 +#
    1.40 +BOINCUSER=boinc
    1.41 +
    1.42 +# Working directory.  Could be /home/boinc, /var/lib/boinc, etc..
    1.43 +# The reason I prefer /var/lib/boinc is that this works best for a 
    1.44 +# cluster of computers where /home/anything might be shared between machines
    1.45 +#
    1.46 +BOINCDIR=/var/lib/boinc
    1.47 +
    1.48 +# Name of the client executable.  This is the file "boinc" if you 
    1.49 +# unpacked the download file  boinc_M.mm.rr_i686-pc-linux-gnu.sh,
    1.50 +# but I like to rename it and put it in a public place.
    1.51 +# (Hint: move boincmgr to /usr/local/bin too so anyone can easily use it).
    1.52 +#
    1.53 +BOINCEXE_NAME=boinc_client
    1.54 +BOINCEXE=${bindir}/${BOINCEXE_NAME}
    1.55 +BOINCCMD_NAME=boinccmd
    1.56 +BOINCCMD=${bindir}/${BOINCCMD_NAME}
    1.57 +
    1.58 +# Log files (you should rotate these occasionally)
    1.59 +#
    1.60 +LOGFILE=/var/log/${BOINCEXE_NAME}.log
    1.61 +ERRORLOG=/var/log/${BOINCEXE_NAME}_err.log
    1.62 +
    1.63 +# PID file
    1.64 +PIDFILE=/var/run/${BOINCEXE_NAME}.pid
    1.65 +
    1.66 +# BOINC options: for the command line when running the client.  
    1.67 +# Be aware that --allow_remote_gui_rpc opens up your machine to the world!
    1.68 +#
    1.69 +# Add this option if you want to allow boinc manager connections from remote
    1.70 +# machines
    1.71 +#BOINCOPTS="--allow_remote_gui_rpc"   
    1.72 +# Add this option if you want to turn off all logging
    1.73 +#BOINCOPTS="--daemon"
    1.74 +# Add this option if you want to redirect logging to the files stderrdae.txt
    1.75 +# and stdoutdae.txt in BOINCDIR rather than LOGFILE and ERRORLOG
    1.76 +#BOINCOPTS="--redirectio"
    1.77 +# Add this option if you want to run only when no logins from anywhere are 
    1.78 +# active
    1.79 +#BOINCOPTS="--check_all_logins"
    1.80 +# The default is no options.
    1.81 +BOINCOPTS="--dir $BOINCDIR"
    1.82 +
    1.83 +# Subsys lock file ...
    1.84 +LOCKFILE=/var/lock/${BOINCEXE_NAME}
    1.85 +
    1.86 +# su on Linux seems to need this to be set to work properly in a script
    1.87 +export TERM=dumb
    1.88 +
    1.89 +##
    1.90 +# Init script function library.   This stuff is Red Hat specific,
    1.91 +# but if the functions are not found we create our own simple replacements.
    1.92 +# (The idea for replacing the functions comes from OpenAFS.  Thanks guys!)
    1.93 +
    1.94 +if printf "Hello" >/dev/null 2>/dev/null ; then
    1.95 +     # printf works
    1.96 +     printcol='printf \033[60G%s'
    1.97 +elif echo -en "Hello" >/dev/null 2>/dev/null ; then
    1.98 +     # echo -en works
    1.99 +     printcol='echo -en \033[60G'
   1.100 +else
   1.101 +     # no printf make do with echo -n
   1.102 +     printcol="echo -n .........."
   1.103 +fi
   1.104 +function echo_success () { $printcol "[OK]" ; }
   1.105 +function echo_failure () { $printcol "[FAILED]" ; }
   1.106 +function echo_warning () { $printcol "[WARNING]" ; }
   1.107 +function killproc() {
   1.108 +     PID=`local_pidof $1`
   1.109 +     [ $PID ] && kill $PID 
   1.110 +}
   1.111 +
   1.112 +# Define pidof
   1.113 +function local_pidof() { 
   1.114 +  pidof -s -o $$ -o $PPID -o %PPID $1 
   1.115 +} 
   1.116 +
   1.117 +# Define runuser
   1.118 +RUNUSER=su
   1.119 +
   1.120 +# Some additional places to look for executables
   1.121 +# (Should do this after init.d/functions and sysconfig/boinc, which sets PATH)
   1.122 +export PATH=${PATH}:${exec_prefix}/sbin:${bindir}
   1.123 +
   1.124 +
   1.125 +## Look for any local configuration settings which override all above
   1.126 +## Note: ./boinc-client.conf and ./boinc.conf are for testing purposes
   1.127 +config_files="
   1.128 +./boinc-client.conf
   1.129 +./boinc.conf
   1.130 +/etc/boinc-client.conf
   1.131 +/etc/boinc.conf
   1.132 +none
   1.133 +"
   1.134 +
   1.135 +## find the correct config file
   1.136 +for config_file in $config_files ; do
   1.137 +  if [ -f ${config_file} ] ; then 
   1.138 +    break; 
   1.139 +  fi
   1.140 +done
   1.141 +
   1.142 +if [ "${config_file}" != "none" ]; then
   1.143 +  # check whether we are using a deprecated name
   1.144 +  if [ "x$NOWARNING" != "xyes" -a -z "`echo ${config_file} | grep boinc-client`" ]; then
   1.145 +    fn=`basename $config_file`
   1.146 +    dn=`dirname $config_file`
   1.147 +    newname=`echo $fn | sed 's/boinc/boinc-client/'`
   1.148 +    echo -n "The filename '${config_file}' is deprecated..."
   1.149 +    echo_warning
   1.150 +    echo
   1.151 +    echo -n "Please rename your config file to '${dn}/${newname}'"
   1.152 +    echo_warning
   1.153 +    echo
   1.154 +  fi
   1.155 +  # execute the config file.
   1.156 +  . ${config_file}
   1.157 +fi
   1.158 +
   1.159 +
   1.160 +## Add ${BOINCDIR} to the path, just in case the executables are stored there.
   1.161 +export PATH=${PATH}:${BOINCDIR}
   1.162 +
   1.163 +## Create the working directory if it doesn't exist:
   1.164 +if [ ! -d $BOINCDIR ]; then
   1.165 +  echo -n "Creating $BOINCDIR "
   1.166 +  if mkdir -p $BOINCDIR 2>/dev/null ; then
   1.167 +    if [ -n "$BOINCUSER" ] ; then
   1.168 +      if chown $BOINCUSER $BOINCDIR ; then
   1.169 +        echo_success
   1.170 +      else
   1.171 +        echo_failure
   1.172 +        echo
   1.173 +        exit 7
   1.174 +      fi
   1.175 +    fi
   1.176 +  else
   1.177 +    echo_failure
   1.178 +    echo
   1.179 +    exit 7
   1.180 +  fi
   1.181 +fi
   1.182 +
   1.183 +## Check what user we are running as:
   1.184 +# we can't rely on the existence of "whoami" or "logname", so we'll use ps.
   1.185 +USERNOW=`${PS} u $$ | tail -1 | awk '{print $2}'`
   1.186 +if [ -z "$BOINCUSER" ] ; then
   1.187 +  BOINCUSER="${USERNOW}"
   1.188 +fi
   1.189 +
   1.190 +## Check that BOINCUSER actually exists
   1.191 +if [ -z "`grep ^${BOINCUSER}: /etc/passwd`" ] ; then
   1.192 +  if [ -z "`ypcat passwd 2>/dev/null | grep ^${BOINCUSER}:`" ] ; then 
   1.193 +    if [ -z "`nidump passwd / 2>/dev/null | grep ^${BOINCUSER}:`" ] ; then 
   1.194 +       echo -n ERROR: user ${BOINCUSER} does not exist.
   1.195 +       echo_failure
   1.196 +       echo
   1.197 +       exit 9
   1.198 +    fi
   1.199 +  fi
   1.200 +fi
   1.201 +
   1.202 +# if we are running as root, print a warning.
   1.203 +if [ "x$NOWARNING" != "xyes" -a  "$BOINCUSER" = "root" ] ; then
   1.204 +  echo -n WARNING: boinc-client will be running as root
   1.205 +  echo_warning
   1.206 +  echo
   1.207 +fi
   1.208 +
   1.209 +# check whether we will be able to write to the BOINC directory
   1.210 +if [ "${USERNOW}" = "${BOINCUSER}" ] ; then
   1.211 +  if [ ! -O ${BOINCDIR} ] ; then
   1.212 +    echo -n ERROR: $BOINCDIR is not owned by $BOINCUSER.
   1.213 +    echo_failure
   1.214 +    echo
   1.215 +    exit 8
   1.216 +  fi
   1.217 +elif [ "${USERNOW}" = "root" ] ; then
   1.218 +  cmd="if test -O ${BOINCDIR} ; then echo success ; fi"
   1.219 +  if [ -z `su $BOINCUSER -c "$cmd"` ]; then
   1.220 +    echo -n ERROR: $BOINCDIR is not owned by $BOINCUSER.
   1.221 +    echo_failure
   1.222 +    echo
   1.223 +    exit 8
   1.224 +  fi
   1.225 +fi
   1.226 +
   1.227 +
   1.228 +## Locate the executable, either boinc_client, boinc, 
   1.229 +## or boinc_M.mm_.... with highest version number
   1.230 +## We only do this if BOINCEXE set above isn't found or is not executable.
   1.231 +if [ ! -x $BOINCEXE ]; then
   1.232 +  BOINCEXE=`$WHICH $BOINCEXE_NAME 2>/dev/null`
   1.233 +  if [ ! -x "$BOINCEXE" ]; then
   1.234 +    BOINCEXE=`$WHICH boinc 2>/dev/null`
   1.235 +  fi
   1.236 +fi
   1.237 +
   1.238 +if [ ! -x "$BOINCEXE" ]; then
   1.239 +  echo -n "Cannot find an executable for the BOINC client."
   1.240 +  echo_failure
   1.241 +  echo 
   1.242 +  exit 2
   1.243 +fi
   1.244 +
   1.245 +## boinccmd will probably be in the same place as the boinc_client
   1.246 +if [ ! -x $BOINCCMD ]; then
   1.247 +  BOINCCMD=`$WHICH $BOINCCMD_NAME 2>/dev/null`
   1.248 +  if [ ! -x "$BOINCCMD" ]; then
   1.249 +    BOINCCMD=`dirname $BOINCEXE 2>/dev/null`/${BOINCCMD_NAME}
   1.250 +  fi
   1.251 +fi
   1.252 +
   1.253 +
   1.254 +if [ "x$NOWARNING" != "xyes" -a ! -x $BOINCCMD ]; then
   1.255 +  echo -n "Cannot find the boinccmd executable.  Reload will fail."
   1.256 +  echo_warning
   1.257 +  echo
   1.258 +fi
   1.259 +
   1.260 +## Functions: $1 is one of  start|stop|status|reload|restart
   1.261 +
   1.262 +export NOWARNING=no
   1.263 +
   1.264 +case "$1" in
   1.265 +  start)
   1.266 +        cd $BOINCDIR
   1.267 +        PID=`local_pidof $BOINCEXE_NAME`
   1.268 +
   1.269 +        if [ -f lockfile -o -f $LOCKFILE ] ; then
   1.270 +          if [ -z "$PID" ] ; then
   1.271 +            # a lockfile exists, but boinc_client isn't running
   1.272 +            /bin/rm -f lockfile $LOCKFILE $PIDFILE 2>&1 > /dev/null
   1.273 +          else 
   1.274 +            echo -n "Another instance of BOINC is running (PID=${PID})."
   1.275 +            echo_failure
   1.276 +            echo 
   1.277 +            exit 1
   1.278 +          fi
   1.279 +        fi
   1.280 +
   1.281 +        if [ ! -d projects ] ; then
   1.282 +          echo -n "The BOINC client requires initialization."
   1.283 +          echo_warning
   1.284 +          echo 
   1.285 +        fi
   1.286 +
   1.287 +        touch ${LOGFILE} ${ERRORLOG}
   1.288 +        NOCORE="ulimit -c 0 2>&1 >/dev/null"
   1.289 +        echo -n "Starting BOINC client as a daemon:  "
   1.290 +        if [ "${BOINCUSER}" = "${USERNOW}" ] ; then 
   1.291 +           # I am BOINCUSER.  Just start client as me.
   1.292 +           $NOCORE
   1.293 +           $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG &
   1.294 +        else
   1.295 +           chown ${BOINCUSER} ${LOGFILE} ${ERRORLOG}
   1.296 +           if [ -f gui_rpc_auth.cfg ] ; then
   1.297 +              chmod g+r gui_rpc_auth.cfg 
   1.298 +           fi
   1.299 +           ${RUNUSER} - $BOINCUSER -c "$NOCORE ; $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG" 2>/dev/null > /dev/null &
   1.300 +        fi
   1.301 +        sleep 3  
   1.302 +        PID=`local_pidof $BOINCEXE_NAME`
   1.303 +        if [ $PID ]; then
   1.304 +          echo $PID > $PIDFILE
   1.305 +          touch $LOCKFILE && echo_success || ( echo_failure ; echo )
   1.306 +        fi
   1.307 +        echo
   1.308 +        ;;
   1.309 +  stop)
   1.310 +        cd $BOINCDIR
   1.311 +        if [ ! -f $PIDFILE -a ! -f lockfile -a ! -f $LOCKFILE ] ; then
   1.312 +          echo -n "BOINC is not running (no lockfiles found)."
   1.313 +          echo_success
   1.314 +        else
   1.315 +          echo -n "Stopping BOINC client daemon:  "    
   1.316 +          if [ -f $PIDFILE ] ; then
   1.317 +            PID=`cat $PIDFILE`
   1.318 +            if [ -n "`${PS} $PID | grep $PID`" ] ; then
   1.319 +              kill `cat $PIDFILE`
   1.320 +              sleep 5
   1.321 +            fi
   1.322 +            echo_success
   1.323 +          else
   1.324 +            killproc $BOINCEXE_NAME  && echo_success  || echo_failure 
   1.325 +          fi
   1.326 +          # clean up in any case
   1.327 +          rm -f lockfile 2>/dev/null >/dev/null
   1.328 +          rm -f $LOCKFILE 2>/dev/null
   1.329 +          rm -f $PIDFILE 2>/dev/null
   1.330 +        fi
   1.331 +        echo
   1.332 +        ;;
   1.333 +  reload)
   1.334 +        if [ ! -f lockfile -a ! -f $LOCKFILE ] ; then
   1.335 +          echo  "BOINC is not running (no lockfiles found) -- starting service."
   1.336 +          $0 start
   1.337 +        else
   1.338 +          $BOINCCMD --read_cc_config >>$LOGFILE 2>>$ERRORLOG && echo_success || $0 restart
   1.339 +        fi
   1.340 +        ;;
   1.341 +  restart)
   1.342 +        $0 stop
   1.343 +        $0 start
   1.344 +        ;;
   1.345 +
   1.346 +  status)
   1.347 +        PID=`cat $PIDFILE 2>/dev/null`
   1.348 +        if [ "$PID" != "" ]; then
   1.349 +          # is it still running?
   1.350 +          if [ -z "`${PS} $PID | grep $PID`" ]; then
   1.351 +            # not running.  Try the other tests.
   1.352 +            PID=""
   1.353 +          fi
   1.354 +        fi
   1.355 +        if [ "$PID" == "" ]; then
   1.356 +          PID=`local_pidof $BOINCEXE_NAME`
   1.357 +        fi
   1.358 +        if [ "$PID" == "" ]; then
   1.359 +          PID=`local_pidof $BOINCEXE`
   1.360 +        fi
   1.361 +        if [ "$PID" != "" ]; then
   1.362 +          echo "BOINC client is running (pid $PID)."
   1.363 +        else
   1.364 +          if [ -f $BOINCDIR/lockfile -o -f $LOCKFILE ]; then 
   1.365 +             echo "BOINC is stopped but lockfile(s) exist."
   1.366 +             exit 2
   1.367 +          else 
   1.368 +             echo "BOINC client is stopped."
   1.369 +             exit 3
   1.370 +          fi
   1.371 +        fi
   1.372 +        ;;
   1.373 +
   1.374 +  *)
   1.375 +        echo "Usage: boinc {start|stop|restart|reload|status}"
   1.376 +        exit 1
   1.377 +esac
   1.378 +
   1.379 +exit
   1.380 +
   1.381 +#EOF#