incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [17/50] git commit: init: LSB compliant init script
Date Thu, 26 Jul 2012 21:05:06 GMT
init: LSB compliant init script

With LSB there is no need for having different init script for different distributions.

This init script should be fully LSB compliant and should work on all Linux platforms we support.

RHEL, (Open)SUSE, Debian and Ubuntu all support at least LSB 3.1


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/4d9dd94b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/4d9dd94b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/4d9dd94b

Branch: refs/heads/rbd
Commit: 4d9dd94b53cb1e57bb3d160fff2c2eeb7abfc3fb
Parents: 7b18b72
Author: Wido den Hollander <wido@widodh.nl>
Authored: Wed Jul 25 14:06:22 2012 +0200
Committer: Wido den Hollander <wido@widodh.nl>
Committed: Wed Jul 25 14:08:41 2012 +0200

----------------------------------------------------------------------
 .../distro/ubuntu/SYSCONFDIR/init.d/cloud-agent.in |  155 +++++++--------
 1 files changed, 77 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4d9dd94b/agent/distro/ubuntu/SYSCONFDIR/init.d/cloud-agent.in
----------------------------------------------------------------------
diff --git a/agent/distro/ubuntu/SYSCONFDIR/init.d/cloud-agent.in b/agent/distro/ubuntu/SYSCONFDIR/init.d/cloud-agent.in
index 4f6f04d..b98efca 100755
--- a/agent/distro/ubuntu/SYSCONFDIR/init.d/cloud-agent.in
+++ b/agent/distro/ubuntu/SYSCONFDIR/init.d/cloud-agent.in
@@ -1,12 +1,17 @@
 #!/bin/bash
+
 ### BEGIN INIT INFO
 # Provides:          cloud agent
-# Required-Start:    $network 
-# Required-Stop:     $network 
+# Required-Start:    $network $local_fs
+# Required-Stop:     $network $local_fs
 # Default-Start:     3 4 5
 # Default-Stop:      0 1 2 6
-# X-Interactive:     true
-# Short-Description: Start/stop apache2 web server
+# Short-Description: Start/stop Apache CloudStack Agent
+# Description: This scripts Starts/Stops the Apache CloudStack agent
+##  The CloudStack Agent is a part of the Apache CloudStack project and is used
+##  for managing KVM-based Hypervisors and performing secondary storage tasks inside
+##  the Secondary Storage System Virtual Machine.
+## JSVC (Java daemonizing) is used for starting and stopping the agent
 ### END INIT INFO
 
 # Licensed to the Apache Software Foundation (ASF) under one
@@ -26,21 +31,17 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# WARNING: if this script is changed, then all other initscripts MUST BE changed to match
it as well
-
 . /lib/lsb/init-functions
-. /etc/default/rcS
-
-whatami=cloud-agent
 
-# set environment variables
-
-SHORTNAME="$whatami"
-PIDFILE=@PIDDIR@/"$whatami".pid
+SHORTNAME="cloud-agent"
+PIDFILE=@PIDDIR@/"$SHORTNAME".pid
 LOCKFILE=@LOCKDIR@/"$SHORTNAME"
 LOGFILE=@AGENTLOG@
 PROGNAME="Cloud Agent"
 CLASS="com.cloud.agent.AgentShell"
+PROG="jsvc"
+DAEMON="/usr/bin/jsvc"
+SHUTDOWN_WAIT="30"
 
 unset OPTIONS
 [ -r @SYSCONFDIR@/default/"$SHORTNAME" ] && source @SYSCONFDIR@/default/"$SHORTNAME"
@@ -81,53 +82,53 @@ wait_for_network() {
 }
 
 start() {
-        log_daemon_msg $"Starting $PROGNAME" "$SHORTNAME"
-	if [ -s "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then
-	      log_progress_msg "apparently already running"
-	      log_end_msg 0
-	      exit 0
-	fi
-	if hostname --fqdn >/dev/null 2>&1 ; then
-		true
-	else
-		log_failure_msg "The host name does not resolve properly to an IP address.  Cannot start
$PROGNAME"
-		log_end_msg 1
-		exit 1
-	fi
-
-        wait_for_network
-
-	if jsvc -cp "$CLASSPATH" -pidfile "$PIDFILE" $CLASS
-		RETVAL=$?
-	    then
-		rc=0
-		sleep 1
-		if ! kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then
-		    log_failure_msg "$PROG failed to start"
-		    rc=1
-		fi
-	else
-		rc=1
-	fi
-
-	if [ $rc -eq 0 ]; then
-		log_end_msg 0
-	else
-		log_end_msg 1
-		rm -f "$PIDFILE"
-	fi
+    log_daemon_msg "Starting $PROGNAME" "$SHORTNAME"
+    if [ -s "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") >/dev/null 2>&1;
then
+          log_progress_msg "apparently already running"
+          log_end_msg 0
+          exit 0
+    fi
+
+    if hostname --fqdn >/dev/null 2>&1 ; then
+        true
+    else
+        log_failure_msg "The host name does not resolve properly to an IP address. Cannot
start $PROGNAME"
+        log_end_msg 1
+        exit 1
+    fi
+
+    wait_for_network
+
+    if start_daemon -p $PIDFILE $DAEMON -cp "$CLASSPATH" -pidfile "$PIDFILE" $CLASS
+        RETVAL=$?
+    then
+        rc=0
+        sleep 1
+        if ! kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then
+            log_failure_msg "$PROG failed to start"
+            rc=1
+        fi
+    else
+        rc=1
+    fi
+
+    if [ $rc -eq 0 ]; then
+        log_end_msg 0
+    else
+        log_end_msg 1
+        rm -f "$PIDFILE"
+    fi
 }
 
 stop() {
-    SHUTDOWN_WAIT="30"
     count="0"
 
-    echo -n $"Stopping $PROGNAME" "$SHORTNAME"
-    jsvc -pidfile "$PIDFILE" -stop $CLASS
+    log_daemon_msg "Stopping $PROGNAME" "$SHORTNAME"
+    killproc -p $PIDFILE $DAEMON
 
     until [ "$count" -gt "$SHUTDOWN_WAIT" ]
     do
-        agentPid=`ps aux|grep [j]svc|grep cloud-agent`
+        agentPid=$(ps aux|grep [j]svc|grep $SHORTNAME)
         if [ "$?" -gt "0" ];then
             break
         fi
@@ -135,40 +136,38 @@ stop() {
         let count="${count}+1"
     done
 
-    agentPid=`ps aux|grep [j]svc|grep cloud-agent`
+    agentPid=$(ps aux|grep [j]svc|grep $SHORTNAME)
     if [ "$?" -eq "0" ]; then
-         agentPid=`ps aux|grep [j]svc|awk '{print $2}'`
-         if [ "$agentPid" != "" ]; then
-              kill -9 $agentPid
-         fi
+        agentPid=$(ps aux|grep [j]svc|awk '{print $2}')
+        if [ "$agentPid" != "" ]; then
+            log_warning_msg "$PROG still running, forcing kill"
+            kill -9 $agentPid
+        fi
     fi
 
     log_end_msg $?
     rm -f "$PIDFILE"
 }
 
-
-# See how we were called.
 case "$1" in
-  start)
-	start
-	;;
-  stop)
-	stop
-	;;
-  status)
+    start)
+        start
+        ;;
+    stop)
+        stop
+        ;;
+    status)
         status_of_proc -p "$PIDFILE" "$PROG" "$SHORTNAME"
-	RETVAL=$?
-	;;
-  restart)
-	stop
-	sleep 3
-	start
-	;;
-  *)
-	echo $"Usage: $whatami {start|stop|restart|status|help}"
-	RETVAL=3
+        RETVAL=$?
+        ;;
+    restart | force-reload)
+        stop
+        sleep 3
+        start
+        ;;
+    *)
+    echo "Usage: $0 {start|stop|restart|force-reload|status}"
+    RETVAL=3
 esac
 
-exit $RETVAL
-
+exit $RETVAL
\ No newline at end of file


Mime
View raw message