From 972926e8e2e3ffbd60b4b02bd58bf95387cae0fd Mon Sep 17 00:00:00 2001 From: Miloš Jakubíček Date: Mar 18 2009 10:33:42 +0000 Subject: - Wait longer when checking start/stop result in the init script. Wed Mar 11 2009 Milos Jakubicek - 6.4.7-4.r17542svn - Rewritten init script: honours localisation, fixed reload action, doesn't output garbage into logfiles (resolves BZ#489378), do not leave stale init script process on startup, uses /etc/init.d/functions instead of own stuff. --- diff --git a/boinc-client-init-d b/boinc-client-init-d index 64b04af..7b6e3d1 100644 --- a/boinc-client-init-d +++ b/boinc-client-init-d @@ -1,24 +1,20 @@ -#!/bin/sh +#!/bin/bash # # BOINC - start and stop the BOINC client daemon on Unix # -# Unix start/stop script to run the BOINC client as a daemon at -# system startup, as the 'boinc' user (not root!). +# SysVInit start/stop script to run the BOINC client as a daemon at +# system startup, as the $BOINCUSER (not root!). # -# This version works on Red Hat Linux, Fedora, Mandrake, Debian, -# and Slackware Linux, and should work on generic Linux systems -# provided that they have 'pidof' (most do). -# Metadata for chkconfig and the SUSE equivalent INIT info are included below. +# This version has been modified for Fedora/RHEL. # -# Usage: boinc { start | stop | status | reload | restart } -# ### # chkconfig: - 98 02 # description: This script starts the local BOINC client as a daemon # For more information about BOINC (the Berkeley Open Infrastructure # for Network Computing) see http://boinc.berkeley.edu -# processname: boinc -# config: /etc/sysconfig/boinc +# processname: boinc-client +# pidfile: /var/run/boinc-client.pid +# config: /etc/sysconfig/boinc-client # ### BEGIN INIT INFO # Provides: boinc @@ -32,222 +28,166 @@ # for Network Computing) see http://boinc.berkeley.edu ### END INIT INFO # +# Based on the init script provided by: # Eric Myers - 27 July 2004 # Department of Physics and Astronomy, Vassar College, Poughkeepsie NY # Eric Myers # Spy Hill Research, Poughkeepsie, New York -# @(#) $Id: boinc-client-init-d,v 1.6 2009/03/08 21:14:14 mjakubicek Exp $ +# +# Rewritten by Milos Jakubicek - 10 March 2009 +# Faculty of Informatics, Masaryk University Brno, Czech Republic ######################################################################## # Defaults, which can be overridden by putting new NAME=value lines -# in /etc/sysconfig/boinc (for Red Hat/Fedora Linux and variants) -# or /etc/default/boinc (for Debian/Ubuntu and variants) +# in /etc/sysconfig/boinc-client # Name of user to run as: -# + BOINCUSER=boinc -# Working directory. Could be /home/boinc, /var/lib/boinc, etc.. -# The reason I prefer /var/lib/boinc is that this works best for a -# cluster of computers where /home/anything might be shared between machines -# -BOINCDIR=/var/lib/boinc +# Working directory. -# Name of the client executable. This is the file "boinc" if you -# unpacked the download file boinc_M.mm.rr_i686-pc-linux-gnu.sh, -# but I like to rename it and put it in a public place. -# (Hint: move boincmgr to /usr/local/bin too so anyone can easily use it). -# +BOINCDIR="/var/lib/boinc" -BOINCEXE=/usr/bin/boinc_client -BOINCCMD=/usr/bin/boinc_cmd +# Name of the client executable. -# Log and error files (you should rotate these occasionally) -# -LOGFILE=/var/log/boinc.log -ERRORLOG=/var/log/boincerr.log +BOINCEXE="/usr/bin/boinc_client" +BOINCCMD="/usr/bin/boinccmd" -# BOINC options: for the command line when running the client. -# Be aware that --allow_remote_gui_rpc opens up your machine to the world! -# -#BOINCOPTS="--allow_remote_gui_rpc" -BOINCOPTS=" --daemon" +# Log and error files (should be placed in /var/log/ to avoid SELinux related issues) -# Subsys lock file ... +LOGFILE="/var/log/boinc.log" +ERRORLOG="/var/log/boincerr.log" -# If there is the subsys directory, then use it ... -if [ -d /var/lock/subsys/ ]; then - LOCKFILE=/var/lock/subsys/boinc-client -elif [ -d /var/lock ]; then - LOCKFILE=/var/lock/boinc-client -fi +# BOINC options: for the command line when running the client. -# su on Linux seems to need this to be set to work properly in a script -export TERM dumb - - -## -# Init script function library. This stuff is Red Hat specific, -# 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 -else - export PATH=/sbin:/bin:/usr/sbin:/usr/bin - function echo_success () { echo -n " [ OK ] " ; } - function echo_failure () { echo -n " [FAILED] " ; } - function echo_warning () { echo -n " [WARNING] " ; } - function killproc() { - PID=`pidof -s -x -o $$ -o $PPID -o %PPID $1` - [ $PID ] && kill $PID ; } -fi +BOINCOPTS= +# Service name -## Look for any local configuration settings which override all above +prog=boinc-client -if [ -f /etc/sysconfig/boinc-client ]; then - . /etc/sysconfig/boinc-client -elif [ -f /etc/default/boinc-client ]; then - . /etc/default/boinc-client -fi +# Subsys lock file and pid file +LOCKFILE="/var/lock/subsys/$prog" -## Verify the working directory exists: +# Init script function library. -if [ ! -d $BOINCDIR ]; then - echo -n "Cannot find BOINC directory $BOINCDIR " - echo_failure - echo - exit 7 -fi +. /etc/rc.d/init.d/functions +# Look for any local configuration settings which override all above -# Some additional places to look for the client executable -# (Should do this after init.d/functions and sysconfig/boinc, which sets PATH) +[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog -export PATH=$BOINCDIR:/usr/local/bin:$PATH +# Verify the $BOINCDIR working directory exists +if [ ! -d $BOINCDIR ]; then + echo -n "Cannot find BOINC directory $BOINCDIR" + echo_failure + echo + exit 7 +fi -## Locate the executable, either boinc_client, boinc, -## or boinc_M.mm_.... with highest version number -## We only do this if BOINCEXE set above isn't found or is not executable. +# Verify the $BOINCEXE executable exists if [ ! -x $BOINCEXE ]; then - BOINCEXE=`/usr/bin/which boinc_client 2>/dev/null` - if [ ! -x "$BOINCEXE" ]; then - BOINCEXE=`/usr/bin/which boinc 2>/dev/null` - fi -fi - -if [ ! -x "$BOINCEXE" ]; then - echo -n "Cannot find an executable for the BOINC client." - echo_failure - echo - exit 2 + echo -n "Cannot find an executable for the BOINC client." + echo_failure + echo + exit 2 fi +# Warn if there're no projects attached +cd $BOINCDIR +if [ ! -d projects ] ; then + echo -n "BOINC client requires initialization (no projects attached)." + echo_warning + echo +fi -## Functions: $1 is one of start|stop|status|reload|restart +check_status() { + status $BOINCEXE +} -case "$1" in - start) - cd $BOINCDIR +start() { + check_status >& /dev/null && exit 0 + echo -n $"Starting $prog: " + + # Check that we're a privileged user + if [ `id -u` != 0 ] ; then + echo -n "Insufficient rights." + failure + echo + exit 4 + fi - if [ ! -d projects ] ; then - echo -n "The BOINC client requires initialization (no projects attached)." - echo_warning - echo - fi + # Check that log files exist, otherwise create them with proper ownership + if [ ! -e $LOGFILE ]; then + touch $LOGFILE && chown $BOINCUSER:$BOINCUSER $LOGFILE + fi + if [ ! -e $ERRORLOG ]; then + touch $ERRORLOG && chown $BOINCUSER:$BOINCUSER $ERRORLOG + fi - echo -n "Starting BOINC client as a daemon: " - - # Check that we're a privileged user - if [ `id -u` != 0 ] ; then - echo -n "Insufficient rights." - echo_failure - echo - exit 4 - fi + daemon --check $BOINCEXE --user $BOINCUSER +19 "$BOINCEXE $BOINCOPTS --dir $BOINCDIR >>$LOGFILE 2>>$ERRORLOG &" >& /dev/null - daemon --check $BOINCEXE --user $BOINCUSER +19 "$BOINCEXE" $BOINCOPTS --dir $BOINCDIR >>$LOGFILE 2>>$ERRORLOG & - try=0 - while [ $try -lt 10 ] ; do - PID=`pidof -s -x -o $$ -o $PPID -o %PPID $BOINCEXE` - if [ $PID ]; then - touch $LOCKFILE && echo_success || echo_failure - break - else - sleep 1 - fi - let try+=1 + # Check that boinc is running, give it a few tries + TRY=0 + while [ $TRY -lt 10 ] ; do + check_status >& /dev/null && { touch $LOCKFILE; success; echo; return; } || sleep 1 + let TRY+=1 done; - if [ -z $PID ]; then - echo_failure - fi - echo - ;; + check_status >& /dev/null && { touch $LOCKFILE; success; } || failure + echo +} + +stop() { + cd $BOINCDIR + check_status >& /dev/null || exit 0 + echo -n $"Stopping $prog: " + killproc -d 10 $BOINCEXE + rm -f $LOCKFILE + echo +} + +reload() { + check_status >& /dev/null || { start; exit; } + action "Reading configuration: " $BOINCCMD --read_cc_config +} + +restart() { + stop + start +} + +case "$1" in + start) + $1 + ;; stop) - cd $BOINCDIR - if [ ! -f lockfile -a ! -f $LOCKFILE ] ; then - echo -n "BOINC is not running (no lockfiles found)." - echo_success - else - echo -n "Stopping BOINC client daemon: " - killproc $BOINCEXE && echo_success || echo_failure - # clean up in any case - rm -f $BOINCDIR/lockfile - rm -f $LOCKFILE - fi - echo - ;; + $1 + ;; reload) - if [ ! -f lockfile -a ! -f $LOCKFILE ] ; then - echo -n "BOINC is not running (no lockfiles found) -- starting service." - $0 start - else - echo -n "Reading configuration: " - $BOINCCMD --read_cc_config >>$LOGFILE 2>>$ERRORLOG && echo_success || echo_failure - fi - echo + $1 + ;; + restart) + $1 ;; force-reload) - $0 reload - $0 restart - ;; + reload + restart + ;; condrestart|try-restart) - $0 status || exit 0 - $0 restart - ;; - restart) - $0 stop - $0 start - ;; - + check_status || exit 0 + restart + ;; status) - PID=`pidof -x -o $$ -o $PPID -o %PPID boinc_client` - if [ "$PID" == "" ]; then - PID=`pidof -x -o $$ -o $PPID -o %PPID $BOINCEXE` - fi - if [ "$PID" != "" ]; then - echo "BOINC client is running (pid $PID)." - else - if [ -f $BOINCDIR/lockfile -o -f $LOCKFILE ]; then - echo "BOINC is stopped but lockfile(s) exist." - exit 2 - else - echo "BOINC client is stopped." - exit 3 - fi - fi - ;; - + check_status + ;; *) - echo "Usage: boinc {start|stop|restart|condrestart|try-restart|reload|force-reload|status}" + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" exit 2 esac -exit - -#EOF# +exit $? diff --git a/boinc-client.spec b/boinc-client.spec index 60d3a35..518b231 100644 --- a/boinc-client.spec +++ b/boinc-client.spec @@ -4,7 +4,7 @@ Summary: The BOINC client core Name: boinc-client Version: 6.4.7 -Release: 3.r%{revision}svn%{?dist} +Release: 5.r%{revision}svn%{?dist} License: LGPLv2+ Group: Applications/Engineering URL: http://boinc.berkeley.edu/ @@ -189,11 +189,11 @@ fi # Otherwise pull \$BOINCDIR from the init script if [ -z \$BOINCDIR ]; then - BOINCDIR="\`grep 'BOINCDIR=' %{_sysconfdir}/init.d/%{name} | sed 's|BOINCDIR=||'\`"; + BOINCDIR=\`grep 'BOINCDIR=' %{_sysconfdir}/init.d/%{name} | tr '"' ' ' | sed 's|BOINCDIR=||'\`; fi cd \$BOINCDIR -boinc_gui +boinc_gui >& /dev/null EOF chmod a+x boincmgr popd @@ -313,6 +313,14 @@ fi %{_includedir}/boinc/* %changelog +* Tue Mar 17 2009 Milos Jakubicek - 6.4.7-5.r17542svn +- Wait longer when checking start/stop result in the init script. + +* Wed Mar 11 2009 Milos Jakubicek - 6.4.7-4.r17542svn +- Rewritten init script: honours localisation, fixed reload action, doesn't + output garbage into logfiles (resolves BZ#489378), do not leave stale init + script process on startup, uses /etc/init.d/functions instead of own stuff. + * Tue Mar 10 2009 Milos Jakubicek - 6.4.7-3.r17542svn - Fix damn typos in boincmgr wrapper script (resolves BZ#489463).