SOURCES: mldonkey.init - use functions for restart

glen glen at pld-linux.org
Mon Oct 2 00:02:06 CEST 2006


Author: glen                         Date: Sun Oct  1 22:02:06 2006 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- use functions for restart

---- Files affected:
SOURCES:
   mldonkey.init (1.28 -> 1.29) 

---- Diffs:

================================================================
Index: SOURCES/mldonkey.init
diff -u SOURCES/mldonkey.init:1.28 SOURCES/mldonkey.init:1.29
--- SOURCES/mldonkey.init:1.28	Tue Oct 11 11:23:49 2005
+++ SOURCES/mldonkey.init	Mon Oct  2 00:02:01 2006
@@ -41,103 +41,101 @@
 }
 
 start() {
-	msg_starting mldonkey
-
-	daemon --fork --user $USER "cd ~$USER && exec $MLDONKEY_PATH > ${LOG:-/dev/null} 2>&1"
-	RETVAL=$?
-
-	# wait for it, it might die if config files are corrupted
-	timeout=0
-	while [ "$(getpids)" ]; do
-		if [ $timeout -ge 5 ]; then
-			break
-		fi
-
-		timeout=$((timeout + 1))
-		sleep 1
-	done
-
-	if ! getpids > /dev/null; then
-		nls "%s could not be started! Check logfile: %s" MLDonkey "$LOG"
-		RETVAL=0
-	fi
-
-	# TEMP FIX, rc-scripts fails to keep nice level, when su is used
-	# keep it, until rc-scripts is fixed.
-	for pid in $(getpids); do
-		renice ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} -p $pid > /dev/null
-	done
-
-	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mldonkey
-}
-
-stop() {
-	# first nicely, via web interface
-	BASE="http://"
-	if [[ -n ${USERNAME} && -n ${PASSWORD} ]]; then
-		BASE=${BASE}${USERNAME}:${PASSWORD}@
-	fi
+	if [ ! -f /var/lock/subsys/mldonkey ]; then
+		msg_starting mldonkey
 
-	msg_stopping mldonkey
-	BASE=${BASE}${SERVER}:${PORT}
-	wget -t 1 --spider ${BASE}/submit?q=close_fds -q
-	wget -t 1 --spider ${BASE}/submit?q=save -q
-	wget -t 1 --spider ${BASE}/submit?q=kill -q
-
-	if [ "$(getpids)" ]; then
-		fail
-		show "Waiting for MLDonkey to stop"
-		busy
+		daemon --fork --user $USER "cd ~$USER && exec $MLDONKEY_PATH > ${LOG:-/dev/null} 2>&1"
+		RETVAL=$?
 
-		RETVAL=0
+		# wait for it, it might die if config files are corrupted
 		timeout=0
 		while [ "$(getpids)" ]; do
-			if [ $timeout -ge 60 ]; then
-				RETVAL=1
+			if [ $timeout -ge 5 ]; then
 				break
 			fi
 
-			sleep 1
 			timeout=$((timeout + 1))
+			sleep 1
 		done
-	fi
 
-	# forcibly.
-	# killproc() sais itself ok or fail, therefore the 'if' statement here
-	if [ "$(getpids)" ]; then
-		killproc $PROG
-		RETVAL=$?
+		if ! getpids > /dev/null; then
+			nls "%s could not be started! Check logfile: %s" MLDonkey "$LOG"
+			RETVAL=0
+		fi
+
+		# TEMP FIX, rc-scripts fails to keep nice level, when su is used
+		# keep it, until rc-scripts is fixed.
+		for pid in $(getpids); do
+			renice ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} -p $pid > /dev/null
+		done
+
+		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mldonkey
 	else
-		[ $RETVAL -eq 0 ] && ok || fail
+		msg_already_running mldonkey
 	fi
+}
+
+stop() {
+	if [ -f /var/lock/subsys/mldonkey ]; then
+		# first nicely, via web interface
+		BASE="http://"
+		if [[ -n ${USERNAME} && -n ${PASSWORD} ]]; then
+			BASE=${BASE}${USERNAME}:${PASSWORD}@
+		fi
 
-	rm -f /var/lock/subsys/mldonkey >/dev/null 2>&1
+		msg_stopping mldonkey
+		BASE=${BASE}${SERVER}:${PORT}
+		wget -t 1 --spider ${BASE}/submit?q=close_fds -q
+		wget -t 1 --spider ${BASE}/submit?q=save -q
+		wget -t 1 --spider ${BASE}/submit?q=kill -q
+
+		if [ "$(getpids)" ]; then
+			fail
+			show "Waiting for MLDonkey to stop"
+			busy
+
+			RETVAL=0
+			timeout=0
+			while [ "$(getpids)" ]; do
+				if [ $timeout -ge 60 ]; then
+					RETVAL=1
+					break
+				fi
+
+				sleep 1
+				timeout=$((timeout + 1))
+			done
+		fi
 
+		# forcibly.
+		# killproc() sais itself ok or fail, therefore the 'if' statement here
+		if [ "$(getpids)" ]; then
+			killproc $PROG
+			RETVAL=$?
+		else
+			[ $RETVAL -eq 0 ] && ok || fail
+		fi
+
+		rm -f /var/lock/subsys/mldonkey >/dev/null 2>&1
+	else
+		msg_not_running mldonkey
+	fi
 }
 
 RETVAL=0
 case "$1" in
   start)
-	if [ ! -f /var/lock/subsys/mldonkey ]; then
-		start
-	else
-		msg_already_running mldonkey
-	fi
+	start
 	;;
   stop)
-	if [ -f /var/lock/subsys/mldonkey ]; then
-		stop
-	else
-		msg_not_running mldonkey
-	fi
+	stop
 	;;
   restart|force-reload)
-	$0 stop
-	$0 start
-	exit $?
+	stop
+	start
 	;;
   clean)
-	$0 stop && sleep 20
+	stop && sleep 20
 	rm ~mldonkey/*.tmp >/dev/null 2>&1
 	rm ~mldonkey/mlnet.pid >/dev/null 2>&1
 	;;
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/SOURCES/mldonkey.init?r1=1.28&r2=1.29&f=u



More information about the pld-cvs-commit mailing list