Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 193581 - sci-misc/boinc - initscript problem with stop/restart
Summary: sci-misc/boinc - initscript problem with stop/restart
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: AMD64 Linux
: High normal (vote)
Assignee: Tomáš Chvátal (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-23 23:35 UTC by Martin Šuška
Modified: 2009-02-01 15:11 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
diff for boinc initscript (boinc.init.diff,5.85 KB, text/plain)
2007-09-24 07:39 UTC, Martin Šuška
Details
boinc conf file diff (boinc.conf.diff,510 bytes, text/plain)
2007-09-24 07:40 UTC, Martin Šuška
Details
unified diff for boinc initscript (boinc.init.udiff,6.44 KB, text/plain)
2007-09-24 08:06 UTC, Martin Šuška
Details
unified diff for boinc configuration file (boinc.conf.udiff,916 bytes, text/plain)
2007-09-24 08:07 UTC, Martin Šuška
Details
Fix (boinc.patch,309 bytes, patch)
2008-05-11 14:20 UTC, Itay Perl
Details | Diff
Better fix. (boinc.patch,360 bytes, patch)
2008-05-11 14:28 UTC, Itay Perl
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Šuška 2007-09-23 23:35:17 UTC
I emerged sci-misc/boinc and I had some problems with running it and mainly with stoping the daemon. When I "stopped" it and tried to run it again message
WARNING:  "boinc" has already been started.
appeared and it was hard to find why
 - there was lockfile but also there was file link boinc in /var/lib/init.d/started

Reproducible: Always

Steps to Reproduce:
1. emerge sci-misc/boinc
2. run /etc/init.d/boinc start
3. run /etc/init.d/boinc stop
4. run /etc/init.d/boinc start again

Actual Results:  
Message WARNING:  "boinc" has already been started. appears, but no process is running.

Expected Results:  
It stops process corretly

I altered boinc runscript to:

#!/sbin/runscript

opts="${opts} attach"

depend() {
	use dns
	need net
}

start() {
	ebegin "Starting BOINC"

	if [ ! -d ${RUNTIMEDIR} ]; then
		einfo "Directory ${RUNTIMEDIR} not existing, creating now."
		/bin/mkdir ${RUNTIMEDIR}
		/bin/chown ${USER}:${GROUP} ${RUNTIMEDIR}
		if [ ! -d ${RUNTIMEDIR} ]; then
			eerror "Directory ${RUNTIMEDIR} could not be created!"
			return 1
		fi
	fi

	cd ${RUNTIMEDIR}

	#if [ ! -f lockfile ]; then
	#	einfo "File ${RUNTIMEDIR}/lockfile does not exist, assuming first run."
	#	einfo "You need to setup an account on the BOINC project homepage beforehand! Go to http://boinc.berkeley.edu/ and locate your project."
	#	einfo "Then either run /etc/init.d/boinc attach or connect with a gui client and attach to a project with that."
	#fi

	# if the log file doesn't exist, create it with root privs, then change ownership to boinc
	if [ ! -f ${LOGFILE} ]; then
		touch ${LOGFILE}
		chown ${USER}:${GROUP} ${LOGFILE}
	else
		day=`date +"%F_%T"`
		mv ${LOGFILE} ${LOGFILE}_${day}.old
		touch ${LOGFILE}
		chown ${USER}:${GROUP} ${LOGFILE}
	fi

	if [ ${ALLOW_REMOTE_RPC} = "yes" ]; then
		ARGS="${ARGS} -allow_remote_gui_rpc"
	fi

	# if NO_GUI variable is defined
	if [ ! -z ${NO_GUI} ]
	    then
		if [ "x"$NO_GUI = "x-no_gui_rpc" ]
		    then
			ARGS="${ARGS} $NO_GUI"
		    else
			# log error
			eerror "Expected value of NO_GUI variable is '-no_gui_rpc' if set. Actual value is '${NO_GUI}'."
			return 1
		fi
	fi

	if [ ! -z ${BOINC_HOME} ]
	    then
		if [ ! -d ${BOINC_HOME} ]
		    then
			eerror "Directory ${BOINC_HOME} not exist"
			return 1
		    else
			check_permissions ${BOINC_HOME} ${USER} 2 # 2 = write
			if [ $? -ne 0 ]
			    then
				eerror "No permisions to write to '${BOINC_HOME}' directory for user '${USER}' nor group '${GROUP}'."
				return 1
			fi
		fi
	    else
		eerror "'BOINC_HOME' variable not set"
		return 1
	fi

	if [ -z ${PIDFILE} ]
	    then
		eerror "'PIDFILE' variable not set"
		return 1
	    else
		piddir=`echo ${PIDFILE} | sed -n s'/\(.*\/\)[^\/]*/\1/'p`
		if [ -d ${piddir} ]
		    then
			check_permissions ${piddir} ${USER} 2 # 2 = write
			if [ $? -ne 0 ]
			    then
				eerror "No permissions to write to '${piddir}' directory."
				return 1
			fi
		    else
			eerror "Directory '${piddir}' doesn't exist"
			return 1
		fi
	fi

	#setsid start-stop-daemon --quiet --start  --chdir ${RUNTIMEDIR} \
	#	--pidfile "/var/run/boinc.pid"--exec ${BOINCBIN} --chuid ${USER}:${GROUP} \
	#	--nicelevel ${NICELEVEL} -- ${ARGS} > ${LOGFILE} 2>&1 &

	setsid start-stop-daemon --quiet --start --exec ${BOINCBIN} --chuid ${USER}:${GROUP} \
		--nicelevel ${NICELEVEL} --chdir ${BOINC_HOME} --make-pidfile --pidfile "${PIDFILE}" -- -dir ${BOINC_HOME} > ${LOGFILE} 2>&1 &

	eend $?
}

attach() {
	# stop running boinc
	if [ -f ${PIDFILE} ] # if pidfile exists
	    then
		pid=`head -n 1 ${PIDFILE}`
		# if there is boinc process running with pid from pidfile
		if [ -z "`ps aux|grep ${pid}|grep boinc|grep -v grep`" ]
		    then
			start-stop-daemon --quiet --stop --pidfile ${PIDFILE} --
		fi
	fi
	
	printf "    Enter the Project URL: "
	read url
	printf "    Enter your Account Key: "
	read key

	ebegin "Attaching to project"
		setsid start-stop-daemon --quiet --start --exec ${BOINCBIN} --chuid ${USER}:${GROUP} \
			--nicelevel ${NICELEVEL} --chdir ${BOINC_HOME} --make-pidfile --pidfile "${PIDFILE}" --\
			-attach_project ${url} ${key} > ${LOGFILE} 2>&1 &
	eend $?
}

stop() {
	ebegin "Stopping BOINC"
	# start-stop-daemon --stop --quiet --exec ${BOINCBIN} --pidfile "/var/run/boinc.pid"
	start-stop-daemon --quiet --stop --pidfile ${PIDFILE} -- > ${LOGFILE} 2>&1 &
	eend $?
}

restart() {
	svc_stop
	sleep 6
	svc_start
}

check_permissions() {
	if [ -z "`grep $2 /etc/passwd`" ] # check if user is in the system
		then
			echo "User $2 does not exist."
			return -1
	fi
	
	if [ -z "$2" ] # user parameter missing
		then
			user=`id --user --name`
		else
			user=$2
	fi
	
	if [ "x"$2 == "xroot" ]
		then
			echo "root have all privileges"
			return 0
	fi
	
	
	if [ -z "$3" ] # permission not requested
		then
			3=7
	fi
	
	perm=`stat --format=%a $1`
	
	if [ ${perm} -lt 10 ]
		then 
			perm="00"${perm}
	elif [ ${perm} -lt 100 ]
		then
			perm="0"${perm}
	fi
	
	owner=`echo ${perm} | sed -n s'/\(.\)../\1/'p`
	group=`echo ${perm} | sed -n s'/.\(.\)./\1/'p`
	other=`echo ${perm} | sed -n s'/..\(.\)/\1/'p`
	
	permFromOther=$((${other}&$3))
	
	if [ ${permFromOther} -eq $3 ]
		then
			# all users have requested rights for file
			return 0
	fi
	
	ownerUser=`stat --format=%U $1`
	
	if [ ${ownerUser} = ${user} ]
		then
			permFromOwner=$((${owner}&$3))
		else
			permFromOwner=0
	fi
	
	if [ ${permFromOwner} -eq $3 ]
		then
			# owner have requested permissions
			return 0
	fi 
	
	# get group name
	groupName=`stat --format=%G $1`
	
	# check if user is in group, remove first part
	inOwnerGroup=`id --name --groups ${user} | grep ${groupName}`
	
	if [ -z "${inOwnerGroup}" ]
		then
			# user is not in group that owns file
			permFromGroup=0
		else
			permFromGroup=$((${group}&$3))
	fi
	
	# last check is if together the permissions give required permission
	userAndGroupPerm=$((${permFromOwner}|${permFromGroup}))
	perms=$((${userAndGroupPerm}|${permFromOther}))
	permissionsSum=$((${perms}&$3))
	if [ ${permissionsSum} -eq $3 ]
		then
			return 0
		else
			return 1
	fi
}

And it works fine for me now.
Comment 1 Jakub Moc (RETIRED) gentoo-dev 2007-09-24 05:57:31 UTC
Reopen with a unified diff against current initscript attached, please. Really no idea what you changed.
Comment 2 Martin Šuška 2007-09-24 07:39:33 UTC
Created attachment 131751 [details]
diff for boinc initscript

requested diff
Comment 3 Martin Šuška 2007-09-24 07:40:39 UTC
Created attachment 131752 [details]
boinc conf file diff

there are some new variables in configuration file, so I added that diff too
Comment 4 Martin Šuška 2007-09-24 07:41:38 UTC
Requested diff file(s) added.
Comment 5 Jakub Moc (RETIRED) gentoo-dev 2007-09-24 07:59:59 UTC
Uhm, unified diff (the readable one) != context diff; see the nice manpage ;)
Comment 6 Martin Šuška 2007-09-24 08:06:32 UTC
Created attachment 131753 [details]
unified diff for boinc initscript
Comment 7 Martin Šuška 2007-09-24 08:07:13 UTC
Created attachment 131755 [details]
unified diff for boinc configuration file
Comment 8 Martin Šuška 2007-09-24 08:08:54 UTC
Sorry, I didn't realized what you requested, I didn't know this option. Thanks I learned something :-) 
Comment 9 Itay Perl 2008-05-11 14:20:57 UTC
Created attachment 152839 [details, diff]
Fix

The issue is still there.
The boinc client takes a few seconds to shut down, so the init script fails. The attached fix works for me.
Comment 10 Itay Perl 2008-05-11 14:28:28 UTC
Created attachment 152841 [details, diff]
Better fix.

restart() doesn't have to wait.
Comment 11 Jeroen Roovers (RETIRED) gentoo-dev 2009-01-09 15:04:41 UTC
# ChangeLog for sci-misc/boinc
# Copyright 1999-2009 Gentoo Foundation; Distributed under the GPL v2
# $Header: /var/cvsroot/gentoo-x86/sci-misc/boinc/ChangeLog,v 1.45 2009/01/02 20:40:21 cryos Exp $

  02 Jan 2009; Marcus D. Hanwell <cryos@gentoo.org> metadata.xml:
  Removed myself as maintainer.
Comment 12 Tomáš Chvátal (RETIRED) gentoo-dev 2009-02-01 15:11:35 UTC
Something similar is in new boinc initscript (since version 6.4.5).
Enjoy and report all problems you encounter :]