Use an upstart job to manage mcollectived 93/7093/3 6.1
authorAlexei Sheplyakov <asheplyakov@mirantis.com>
Thu, 28 May 2015 12:08:21 +0000 (15:08 +0300)
committerAlexei Sheplyakov <asheplyakov@mirantis.com>
Thu, 28 May 2015 14:48:44 +0000 (17:48 +0300)
sys v init scripts are inherently racy since creating a PID file takes
a while. In particular collectived needs about 0.6 seconds to daemonize
itself and create its PID file. If the service gets restarted in this
interval the second instance of the daemon gets started without stopping
the previous one. Apparently mcollectived gets restarted very often
during the final phase of IBP. Hence get rid of sys V init script and
use an upstart job to manage mcollectived.

openstack-ci-packtest-deb is expected to fail without the corresponding
nailgun patches:
 https://review.openstack.org/186027
 https://review.openstack.org/186028

Related-Bug: #1454741
Merge-After: https://review.openstack.org/186027
Change-Id: I70d75f77e96447ae20034e170385b46484f51d5e

debian/changelog
debian/mcollective.init [deleted file]
debian/mcollective.upstart [new file with mode: 0644]

index 9f7ab2c4862a236883fdcd85f12b66b7f23f9779..e9af4ff0900f80af151358c74713075a4ed495ef 100644 (file)
@@ -1,3 +1,9 @@
+mcollective (2.3.3-1~u14.04+mos3) mos6.1; urgency=medium
+
+  * Use upstart job to manage the service. Solves LP #1454741 for real
+
+ -- Alexei Sheplyakov <asheplyakov@mirantis.com>  Thu, 28 May 2015 14:55:09 +0300
+
 mcollective (2.3.3-1~u14.04+mos2) mos6.1; urgency=medium
 
   * Update package revision accroding to the policy;
@@ -5,7 +11,7 @@ mcollective (2.3.3-1~u14.04+mos2) mos6.1; urgency=medium
   * Update init script (fix LP #1454741);
   * Update debian/rules (use dh instead of custom build script);
 
- -- Aleksandr Mogylchenko <amogylchenko@mirantis.com> Wed, 27 May 2015 20:02:00 +0200
+ -- Aleksandr Mogylchenko <amogylchenko@mirantis.com>  Wed, 27 May 2015 20:02:00 +0200
 
 mcollective (2.3.3-1puppetlabs1) unstable sid squeeze wheezy precise; urgency=low
 
diff --git a/debian/mcollective.init b/debian/mcollective.init
deleted file mode 100755 (executable)
index eaad7fb..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-#! /bin/sh
-### BEGIN INIT INFO
-# Provides:          mcollective
-# Required-Start:    $network $named $remote_fs $syslog
-# Required-Stop:     $network $named $remote_fs $syslog
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: MCollective daemon
-# Description:       Marionette Collective daemon - build server
-#                    orchestration or parallel job execution systems.
-### END INIT INFO
-
-# Author: Jonas Genannt <jonas.genannt@capi2name.de>
-
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-DESC="Marionette Collective daemon"
-NAME=mcollective
-DAEMON=/usr/sbin/mcollectived
-PIDFILE=/var/run/$NAME.pid
-DAEMON_ARGS="--config=/etc/mcollective/server.cfg --pid=$PIDFILE"
-SCRIPTNAME=/etc/init.d/$NAME
-RUN=yes
-
-# Exit if the package is not installed
-[ -x "$DAEMON" ] || exit 0
-
-[ -r /etc/default/$NAME ] && . /etc/default/$NAME
-
-. /lib/init/vars.sh
-
-. /lib/lsb/init-functions
-
-# XXX: cloud-init writes daemonize=0 into the server.conf
-# (https://github.com/stackforge/fuel-web/blob/master/fuel_agent/cloud-init-templates/cloud_config_ubuntu.jinja2#L50)
-# Undo that error here
-# FIXME: remove this hack after fixing the template
-
-conf_fixup()
-{
-       local conf=/etc/mcollective/server.cfg
-       if grep -q -e 'daemonize\s*=\s*0' $conf; then
-               sed -i $conf -re 's/^\s*daemonize\s*=\s*0\s*$/daemonize=1/'
-       fi
-}
-
-do_start()
-{
-       if [ "$RUN" != "yes" ] ; then
-               log_progress_msg "(disabled)"
-               log_end_msg 0
-
-               exit 0
-       fi
-       conf_fixup
-       start-stop-daemon --start --quiet --pidfile $PIDFILE \
-               --startas $DAEMON -- $DAEMON_ARGS \
-               || return 2
-}
-
-do_stop()
-{
-       if [ -s $PIDFILE ]; then
-               kill `cat ${PIDFILE}` >/dev/null 2>&1
-       fi
-       rm -f $PIDFILE
-       return "0"
-}
-
-case "$1" in
-  start)
-       [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
-       do_start
-       case "$?" in
-               0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
-               2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
-       esac
-       ;;
-  stop)
-       [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
-       do_stop
-       case "$?" in
-               0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
-               2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
-       esac
-       ;;
-  status)
-       status_of_proc -p "${PIDFILE}" "$DAEMON" "$NAME" && exit 0 || exit $?
-       ;;
-  restart|force-reload)
-       log_daemon_msg "Restarting $DESC" "$NAME"
-       do_stop
-       case "$?" in
-         0|1)
-               do_start
-               case "$?" in
-                       0) log_end_msg 0 ;;
-                       1) log_end_msg 1 ;; # Old process is still running
-                       *) log_end_msg 1 ;; # Failed to start
-               esac
-               ;;
-         *)
-               # Failed to stop
-               log_end_msg 1
-               ;;
-       esac
-       ;;
-  *)
-       echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
-       exit 3
-       ;;
-esac
-
-:
diff --git a/debian/mcollective.upstart b/debian/mcollective.upstart
new file mode 100644 (file)
index 0000000..4aa4af3
--- /dev/null
@@ -0,0 +1,15 @@
+
+description "Marionette Collective daemon"
+
+start on runlevel [2345]
+stop on runlevel [!2345]
+
+respawn
+
+pre-start script
+       if grep -q -e 'daemonize\s*=\s*1' /etc/mcollective/server.cfg; then
+               sed -i /etc/mcollective/server.cfg -re 's/^\s*daemonize\s*=\s*1.*/daemonize=0/'
+       fi
+end script
+
+exec /usr/sbin/mcollectived --config /etc/mcollective/server.cfg