]> git.proxmox.com Git - mirror_corosync.git/commitdiff
qnetd: Add init script
authorJan Friesse <jfriesse@redhat.com>
Mon, 14 Dec 2015 17:27:09 +0000 (18:27 +0100)
committerJan Friesse <jfriesse@redhat.com>
Tue, 28 Jun 2016 11:58:39 +0000 (13:58 +0200)
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
init/.gitignore
init/Makefile.am
init/corosync-qnetd.in [new file with mode: 0755]
init/corosync-qnetd.service.in [new file with mode: 0644]
init/corosync-qnetd.sysconfig.example [new file with mode: 0644]
qdevices/corosync-qnetd.c

index 2d081824654128ece99f11d8639e321a3fa09270..53fa7d2e8ad000f7575689c44be0983d6b7b01f0 100644 (file)
@@ -2,3 +2,5 @@ corosync
 corosync-notifyd
 corosync.service
 corosync-notifyd.service
+corosync-qnetd
+corosync-qnetd.service
index 5af1bf6f94b5cb6471239a6e1038487d02368b01..863053f9f4a5d93d800756e20054ff707df4bca4 100644 (file)
@@ -47,6 +47,14 @@ initscriptdir           = $(INITDDIR)
 endif
 initscript_SCRIPTS  = corosync corosync-notifyd
 
+if BUILD_QDEVICES
+initscript_SCRIPTS  += corosync-qnetd
+EXTRA_DIST          += corosync-qnetd.sysconfig.example
+if INSTALL_SYSTEMD
+systemdconf_DATA   += corosync-qnetd.service
+endif
+endif
+
 if INSTALL_UPSTART
 upstartconfdir     = $(UPSTARTDIR)
 upstartconf_DATA   = corosync.conf corosync-notifyd.conf
diff --git a/init/corosync-qnetd.in b/init/corosync-qnetd.in
new file mode 100755 (executable)
index 0000000..41087d8
--- /dev/null
@@ -0,0 +1,164 @@
+#!@BASHPATH@
+
+# Authors:
+#  Jan Friesse <jfriesse@redhat.com>
+#
+# License: Revised BSD
+
+# chkconfig: - 20 80
+# description: Corosync Qdevice Network daemon
+# processname: corosync-qnetd
+#
+### BEGIN INIT INFO
+# Provides:            corosync-qnetd
+# Required-Start:      $network $syslog
+# Required-Stop:       $network $syslog
+# Default-Start:
+# Default-Stop:
+# Short-Description:   Starts and stops Corosync Qdevice Network daemon.
+# Description:         Starts and stops Corosync Qdevice Network daemon.
+### END INIT INFO
+
+desc="Corosync Qdevice Network daemon"
+prog="corosync-qnetd"
+
+# set secure PATH
+PATH="/sbin:/bin:/usr/sbin:/usr/bin:@SBINDIR@"
+
+success()
+{
+       echo -ne "[  OK  ]\r"
+}
+
+failure()
+{
+       echo -ne "[FAILED]\r"
+}
+
+status()
+{
+       pid=$(pidof $1 2>/dev/null)
+       res=$?
+       if [ $res -ne 0 ]; then
+               echo "$1 is stopped"
+       else
+               echo "$1 (pid $pid) is running..."
+       fi
+       return $res
+}
+
+# rpm based distros
+if [ -d @SYSCONFDIR@/sysconfig ]; then
+       [ -f @INITDDIR@/functions ] && . @INITDDIR@/functions
+       [ -f @SYSCONFDIR@/sysconfig/$prog ] && . @SYSCONFDIR@/sysconfig/$prog
+       [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog"
+fi
+
+# deb based distros
+if [ -d @SYSCONFDIR@/default ]; then
+       [ -f @SYSCONFDIR@/default/$prog ] && . @SYSCONFDIR@/default/$prog
+       [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog"
+fi
+
+# The version of __pids_pidof in /etc/init.d/functions calls pidof with -x
+# This means it matches scripts, including this one.
+# Redefine it here so that status (from the same file) works.
+# Otherwise simultaneous calls to stop() will loop forever
+__pids_pidof() {
+        pidof -c -o $$ -o $PPID -o %PPID "$1" || \
+                pidof -c -o $$ -o $PPID -o %PPID "${1##*/}"
+}
+
+cluster_disabled_at_boot()
+{
+       if grep -q nocluster /proc/cmdline && \
+          [ "$(tty)" = "/dev/console" ]; then
+               echo -e "not configured to run at boot"
+               failure
+               return 1
+       fi
+       return 0
+}
+
+start()
+{
+       echo -n "Starting $desc ($prog): "
+
+       ! cluster_disabled_at_boot && return
+
+       # most recent distributions use tmpfs for @LOCALSTATEDIR@/run
+       # to avoid to clean it up on every boot.
+       # they also assume that init scripts will create
+       # required subdirectories for proper operations
+       mkdir -p @LOCALSTATEDIR@/run
+
+       if status $prog > /dev/null 2>&1; then
+               success
+       else
+               $prog $COROSYNC_QNETD_OPTIONS > /dev/null 2>&1
+
+               if [ "$?" != 0 ]; then
+                       failure
+                       rtrn=1
+               else
+                       touch $LOCK_FILE
+                       success
+               fi
+       fi
+       echo
+}
+
+stop()
+{
+       ! status $prog > /dev/null 2>&1 && return
+
+       echo -n "Signaling $desc ($prog) to terminate: "
+       kill -TERM $(pidof $prog) > /dev/null 2>&1
+       success
+       echo
+
+       echo -n "Waiting for $prog services to unload:"
+       while status $prog > /dev/null 2>&1; do
+               sleep 1
+               echo -n "."
+       done
+
+       rm -f $LOCK_FILE
+       success
+       echo
+}
+
+restart()
+{
+       stop
+       start
+}
+
+rtrn=0
+
+case "$1" in
+start)
+       start
+;;
+restart|reload|force-reload)
+       restart
+;;
+condrestart|try-restart)
+       if status $prog > /dev/null 2>&1; then
+               restart
+       fi
+;;
+status)
+       status $prog
+       rtrn=$?
+;;
+stop)
+       stop
+;;
+*)
+       echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
+       rtrn=2
+;;
+esac
+
+exit $rtrn
diff --git a/init/corosync-qnetd.service.in b/init/corosync-qnetd.service.in
new file mode 100644 (file)
index 0000000..553b194
--- /dev/null
@@ -0,0 +1,13 @@
+[Unit]
+Description=Corosync Cluster Engine
+ConditionKernelCommandLine=!nocluster
+Requires=network-online.target
+After=network-online.target
+
+[Service]
+ExecStart=@INITWRAPPERSDIR@/corosync start
+ExecStop=@INITWRAPPERSDIR@/corosync stop
+Type=forking
+
+[Install]
+WantedBy=multi-user.target
diff --git a/init/corosync-qnetd.sysconfig.example b/init/corosync-qnetd.sysconfig.example
new file mode 100644 (file)
index 0000000..528b44f
--- /dev/null
@@ -0,0 +1,6 @@
+# Corosync Qdevice Network daemon init script configuration file
+
+# COROSYNC_QNETD_OPTIONS specifies options passed to corosync-qnetd command
+# (default is no options).
+# See "man corosync-qnetd" for detailed descriptions of the options.
+COROSYNC_QNETD_OPTIONS=""
index b8860b43310fea9f8b31229aadfd1c16afc1d636..f98cc6f5c861af2d2bdebdac6864b1571954c9bb 100644 (file)
@@ -318,6 +318,13 @@ main(int argc, char *argv[])
        qnetd_log_set_debug(debug_log);
        qnetd_log_set_priority_bump(bump_log_priority);
 
+       /*
+        * Daemonize
+        */
+       if (!foreground) {
+               utils_tty_detach();
+       }
+
        if (utils_flock(QNETD_LOCK_FILE, getpid(), qnetd_log_printf) != 0) {
                exit(1);
        }
@@ -366,13 +373,6 @@ main(int argc, char *argv[])
        qnetd_log_printf(LOG_DEBUG, "Registering algorithms");
        algorithms_register();
 
-       /*
-        * Daemonize
-        */
-       if (!foreground) {
-               utils_tty_detach();
-       }
-
        qnetd_log_printf(LOG_DEBUG, "QNetd ready to provide service");
        /*
         * MAIN LOOP