SVN: rc-scripts/branches/upstart_native/rc.d: init.d/functions rc.sysinit

jajcus jajcus at pld-linux.org
Thu May 6 12:31:11 CEST 2010


Author: jajcus
Date: Thu May  6 12:31:10 2010
New Revision: 11385

Modified:
   rc-scripts/branches/upstart_native/rc.d/init.d/functions
   rc-scripts/branches/upstart_native/rc.d/rc.sysinit
Log:
- rewriting 'service', 'chkconfig' and others will give us only a mess, not
  LSB compatibility. Let's to it a different way…


Modified: rc-scripts/branches/upstart_native/rc.d/init.d/functions
==============================================================================
--- rc-scripts/branches/upstart_native/rc.d/init.d/functions	(original)
+++ rc-scripts/branches/upstart_native/rc.d/init.d/functions	Thu May  6 12:31:10 2010
@@ -1103,32 +1103,167 @@
 	/sbin/initctl emit "$@"
 }
 
-_check_init () {
-	# check if the init script can be run this way
-	# make sure the old-styl init scripts are not
-	# used
-	if ! use_upstart ; then
+is_upstart_task() {
+	# Return 0 if the given service is an upstart task.
+	grep -q '^task' "/etc/init/$1.conf"
+}
+is_upstart_running() {
+	# Return 0 if the given service is running via upstart
+	initctl status "$1" 2>/dev/null | grep -q running
+}
+upstart_start() {
+	local service=$1
+	is_upstart_running "${service}" && return 0
+	msg_starting "${service}"
+	if errors=$(/sbin/initctl start ${service} 2>&1) ; then
+		ok
 		return 0
-	fi	
-	if is_yes $CHECK_INIT_OVERRIDE ; then
+	else
+		fail
+		echo "$errors" >&2
+		return 1
+	fi
+}
+upstart_stop() {
+	local service=$1
+	if ! is_upstart_running "${service}" && ! is_upstart_task "${service}" ; then
+		return 0
+	fi
+	msg_stopping "${service}"
+	if errors=$(/sbin/initctl stop ${service}) ; then
+		ok
+		return 0
+	else
+		fail
+		echo "$errors" >&2
+		return 1
+	fi
+}
+upstart_reload() {
+	local service=$1
+	if ! is_upstart_running "${service}" && ! is_upstart_task "${service}" ; then
+		return 0
+	fi
+	msg_reloading "${service}"
+	if errors=$(/sbin/initctl reload ${service}) ; then
+		ok
+		return 0
+	else
+		fail
+		echo "$errors" >&2
+		return 1
+	fi
+}
+upstart_status() {
+	# get service status
+	# should be compliant with
+        # http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
+	local service=$1
+	local status
+	if is_upstart_task "${service}" ; then
+		# we probably should have a way to handle task status
 		return 0
 	fi
-	local name=$(basename "$1")
-	local command=$(basename "$2")
+	if ! status=$(/sbin/initctl status "${service}") ; then
+		# program or service status is not known
+		return 4
+	fi
+	if strstr "$status" "running" ; then
+		# program is running or service is OK
+		return 0
+	else
+		# program is not running
+		return 3
+	fi
+	# TODO: other statuses
+}
+
+_upstart_controlled () {
+	# If the service is to be handled by upstart
+	# execute the start/stop/etc. commands the upstart way
+	if ! use_upstart ; then
+		return 0
+	fi	
+	local script=$1
+	shift
+	local command=$1
+	shift
+	local commands="$*"
+	local name=$(basename "$script")
 	if [ ! -f /etc/init/${name}.conf ] ; then
 		return 0
 	fi
+	if [ -n "$commands" ] ; then
+		local cmd
+		local found=0
+		# is there a better way
+		for cmd in $commands ; do
+			if [ "$command" = "$cmd" ] ; then
+				found=1
+				break;
+			fi
+		done
+		if [ $found = 0 ] ; then
+			# let the script handle it
+			return 0
+		fi
+	fi
 	case "$command" in
-		start|stop|status)
-			echo "Use 'initctl $command $name' to control this service"
-			exit 1
+		start)
+			upstart_start $name
+			exit $?
+			;;
+		stop)
+			upstart_stop $name
+			exit $?
+			;;
+		status)
+			upstart_status $name
+			exit $?
+			;;
+		restart)
+			upstart_stop $name
+			upstart_start $name
+			exit $?
+			;;
+		reload)
+			if is_upstart_task "$name" ; then
+				nls "$command not implemented for $name"
+				exit 3
+			else
+				upstart_reload "$name"
+				exit $?
+			fi
+			;;
+		force-reload)
+			if is_upstart_task "$name" ; then
+				upstart_stop "$name"
+				upstart_start "$name"
+				exit $?
+			else
+				upstart_reload "$name"
+				exit $?
+			fi
 			;;
 		*)
+		        msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
+			exit 3
 			;;
 	esac
-	return 0
+	return 1 # should not happen
 }
-alias check_init='_check_init $0 "$@"'
+
+# Usage:
+#   somewhere at the begining of init script:
+#     upstart_controlled
+#		- to pass implement all upstart commands via initctl
+#                 start, stop, status, restart, reload and force_reload
+#		  are implemented
+#     upstart_controlled command...
+#		- to pass handle only specific commands the upstart way
+#                 and leave the rest to the script
+#
+alias upstart_controlled='_check_init $0 "$@"'
 
 rc_gettext_init
 rc_cache_init

Modified: rc-scripts/branches/upstart_native/rc.d/rc.sysinit
==============================================================================
--- rc-scripts/branches/upstart_native/rc.d/rc.sysinit	(original)
+++ rc-scripts/branches/upstart_native/rc.d/rc.sysinit	Thu May  6 12:31:10 2010
@@ -120,9 +120,6 @@
 
 	# Only read this once.
 	cmdline=$(cat /proc/cmdline)
-	if strstr "$cmdline" "pld.no-upstart" ; then
-		USE_UPSTART="no"
-	fi
 
 	# sysfs is also needed before any other things (under kernel > 2.5)
 	if grep -q sysfs /proc/filesystems 2>/dev/null ; then
@@ -523,9 +520,6 @@
 	elif is_fsmounted cpuset /dev/cpuset; then
 		mount -f -t cpuset none /dev/cpuset
 	fi
-	
-	emit root-filesystem
-	emit virtual-filesystems
 
 	if [ ! -f /proc/modules ]; then
 		USEMODULES=
@@ -892,12 +886,6 @@
 		run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -aug
 	fi
 
-	emit local-filesystems
-
-	# FIXME: this should be delayed until remote filesystems are mounted,
-	#        especialy when /usr or other standard fs is remote
-	emit filesystem
-
 	# Turn on process accounting
 	if [ -x /etc/rc.d/rc.acct ]; then
 		/etc/rc.d/rc.acct start
@@ -923,11 +911,6 @@
 	# ... and here finish configuring parameters
 	sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
 else
-	emit root-filesystem
-	emit virtual-filesystems
-	emit local-filesystems
-	emit filesystem
-
 	# /var/log should be writable now, so start saving the boot output
 	if [ "$RC_BOOTLOG" ]; then
 		echo > /var/log/boot.msg
@@ -996,7 +979,6 @@
 	run_cmd "Enabling swap space" true
 	# Right, now turn on swap in case we swap to files
 	swapon -a >/dev/null 2>&1
-	emit all-swaps
 
 	# If a SCSI tape has been detected, load the st module unconditionally
 	# since many SCSI tapes don't deal well with st being loaded and unloaded
@@ -1022,8 +1004,6 @@
 	done
 	cp -f /var/log/dmesg /var/log/dmesg.0
 	chmod 0600 /var/log/dmesg /var/log/dmesg.0
-else
-	emit all-swaps
 fi
 
 if ! is_no "$RC_PROMPT"; then
@@ -1047,6 +1027,3 @@
 	rm -f /var/run/getkey_done
 fi
 echo
-
-emit pld.sysinit-done
-


More information about the pld-cvs-commit mailing list