--- client/scripts/boinc-client.in.orig Wed Sep 03 13:08:27 2008 +++ client/scripts/boinc-client.in Wed Sep 03 13:21:19 2008 @@ -25,7 +25,7 @@ # Provides: boinc # Required-Start: $network # Required-Stop: $network -# Default-Start: 3 4 5 +# Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: This script monitors the BOINC client. # Description: This script starts the local BOINC client as a daemon @@ -54,12 +54,13 @@ ######################################################################## # set the basic PATH -export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/ucb/bin +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/ucb/bin +export PATH # Find the correct ps to use. On solaris /usr/ucb/ps is the one to use # on everything else, we hope the first one in the path is the right one. -if [ -x /usr/ucb/ps ] ; then - PS=/usr/ucb/ps +if [ -x /bin/ps ] ; then + PS=/bin/ps else PS=ps fi @@ -72,7 +73,7 @@ ######################################################################## SHELLS="bash ksh zsh" # count how many times we've tried to restart -TRIES=$1 +TRIES=$2 if [ -z "$TRIES" ] ; then TRIES=0 fi @@ -92,7 +93,7 @@ for try in $SHELLS ; do ex=`which $try` if [ ! -z "${ex}" -a -x "${ex}" ] ; then - if ${ex} $0 $TRIES ; then + if ${ex} $0 $1 $TRIES ; then # it worked, we can exit exit 0 else @@ -114,7 +115,7 @@ # Name of user to run as: # -BOINCUSER=boinc +BOINCUSER=root # Working directory. Could be /home/boinc, /var/lib/boinc, etc.. # The reason I prefer /var/lib/boinc is that this works best for a @@ -129,7 +130,7 @@ # BOINCEXE_NAME=boinc_client BOINCEXE=${bindir}/${BOINCEXE_NAME} -BOINCCMD_NAME=boinccmd +BOINCCMD_NAME=boinc_cmd BOINCCMD=${bindir}/${BOINCCMD_NAME} # Log files (you should rotate these occasionally) @@ -161,9 +162,11 @@ # If there is the subsys directory, then use it ... if [ -d /var/lock/subsys/ ]; then - LOCKFILE=/var/lock/subsys/boinc-client + LOCKFILE=/var/lock/subsys/${BOINCEXE_NAME} elif [ -d /var/lock ]; then - LOCKFILE=/var/lock/boinc-client + LOCKFILE=/var/lock/${BOINCEXE_NAME} +elif [ -d /var/run ]; then + LOCKFILE=/var/run/${BOINCEXE_NAME}.lock fi # su on Linux seems to need this to be set to work properly in a script @@ -175,25 +178,26 @@ # but if the functions are not found we create our own simple replacements. # (The idea for replacing the functions comes from OpenAFS. Thanks guys!) -if [ -f /etc/rc.d/init.d/functions ] ; then - . /etc/rc.d/init.d/functions - if `printf "Hello" >/dev/null 2>/dev/null` ; then +if [ -f /etc/init.d/functions ] ; then + . /etc/init.d/functions +else + if printf "Hello" >/dev/null 2>/dev/null ; then # printf works printcol='printf \033[60G%s' - if `echo -en "Hello" >/dev/null 2>/dev/null` ; then + elif echo -en "Hello" >/dev/null 2>/dev/null ; then # echo -en works printcol='echo -en \033[60G' - else + else # no printf make do with echo -n printcol="echo -n .........." - fi - function echo_success () { $printcol "[OK]" ; } - function echo_failure () { $printcol "[FAILED]" ; } - function echo_warning () { $printcol "[WARNING]" ; } - function killproc() { + fi + function echo_success () { $printcol "[OK]" ; } + function echo_failure () { $printcol "[FAILED]" ; } + function echo_warning () { $printcol "[WARNING]" ; } + function killproc() { PID=`local_pidof $1` [ $PID ] && kill $PID - } + } fi # check if we have pidof. If not use ps and grep for the same job. @@ -212,7 +216,9 @@ # If we don't have it, use su for the same job. # if [ ! -x /sbin/runuser ] ; then - alias runuser=su + RUNUSER=su +else + RUNUSER=runuser fi # Some additional places to look for executables @@ -226,16 +232,16 @@ ./boinc-client.conf ./boinc.conf /etc/sysconfig/boinc-client -/etc/default/boinc-client -/etc/boinc-client.conf -${sysconfdir}/sysconfig/boinc-client -${sysconfdir}/default/boinc-client -${sysconfdir}/boinc-client.conf /etc/sysconfig/boinc +/etc/default/boinc-client /etc/default/boinc +/etc/boinc-client.conf /etc/boinc.conf +${sysconfdir}/sysconfig/boinc-client ${sysconfdir}/sysconfig/boinc +${sysconfdir}/default/boinc-client ${sysconfdir}/default/boinc +${sysconfdir}/boinc-client.conf ${sysconfdir}/boinc.conf none " @@ -264,6 +270,9 @@ . ${config_file} fi +## Get group-id for user $BOINCUSER in stringformat +BOINCGROUP=`id -gn $BOINCUSER` + ## Add ${BOINCDIR} to the path, just in case the executables are stored there. export PATH=${PATH}:${BOINCDIR} @@ -272,7 +281,7 @@ echo -n "Creating $BOINCDIR " if mkdir -p $BOINCDIR 2>/dev/null ; then if [ -n "$BOINCUSER" ] ; then - if chown $BOINCUSER $BOINCDIR ; then + if chown $BOINCUSER:$BOINCGROUP $BOINCDIR ; then echo_success else echo_failure @@ -288,7 +297,8 @@ fi ## Check what user we are running as: -USERNOW=`whoami` +# we can't rely on the existence of "whoami" or "logname", so we'll use ps. +USERNOW=`${PS} u $$ | tail -1 | awk '{print $1}'` if [ -z "$BOINCUSER" ] ; then BOINCUSER="${USERNOW}" fi @@ -321,7 +331,8 @@ exit 8 fi elif [ "${USERNOW}" = "root" ] ; then - if [ -z `su -s /bin/sh $BOINCUSER -c "if test -O ${BOINCDIR} ; then echo success ; fi"` ]; then + cmd="if test -O ${BOINCDIR} ; then echo success ; fi" + if [ -z `su $BOINCUSER -c "$cmd"` ]; then echo -n ERROR: $BOINCDIR is not owned by $BOINCUSER. echo_failure echo @@ -389,6 +400,7 @@ echo fi + touch ${LOGFILE} ${ERRORLOG} NOCORE="ulimit -c 0 2>&1 >/dev/null" echo -n "Starting BOINC client as a daemon: " if [ "${BOINCUSER}" = "${USERNOW}" ] ; then @@ -396,7 +408,8 @@ $NOCORE $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG & else - runuser - $BOINCUSER -c "$NOCORE ; $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG" + chown ${BOINCUSER}:$BOINCGROUP ${LOGFILE} ${ERRORLOG} + ${RUNUSER} - $BOINCUSER -c "$NOCORE ; $BOINCEXE $BOINCOPTS >>$LOGFILE 2>>$ERRORLOG" 2>/dev/null > /dev/null & fi sleep 3 PID=`local_pidof $BOINCEXE_NAME`