Просмотр исходного кода

merge trunk revision 2554:
r2554 | fabbione | 2009-11-30 11:56:28 -0700 (Mon, 30 Nov 2009) | 3 lines

Clean up init scripts and make a single generic one



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2609 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 16 лет назад
Родитель
Сommit
3b369ae17c
8 измененных файлов с 182 добавлено и 252 удалено
  1. 7 0
      configure.ac
  2. 2 3
      corosync.spec.in
  3. 27 1
      init/Makefile.am
  4. 0 6
      init/README
  5. 0 145
      init/generic
  6. 146 0
      init/generic.in
  7. 0 26
      init/mvlcge
  8. 0 71
      init/redhat

+ 7 - 0
configure.ac

@@ -205,6 +205,11 @@ AC_ARG_ENABLE([rdma],
 	[ enable_rdma="no" ])
 AM_CONDITIONAL(BUILD_RDMA, test x$enable_rdma = xyes)
 
+AC_ARG_WITH([initddir],
+	[  --with-initddir=DIR     : path to init script directory. ],
+	[ INITDDIR="$withval" ],
+	[ INITDDIR="$sysconfdir/init.d" ])
+
 AC_ARG_WITH([lcrso-dir],
 	[  --with-lcrso-dir=DIR    : corosync lcrso files. ],
 	[ LCRSODIR="$withval" ],
@@ -390,6 +395,7 @@ CPPFLAGS="$ENV_CPPFLAGS $ANSI_CPPFLAGS $OS_CPPFLAGS"
 LDFLAGS="$ENV_LDFLAGS $COVERAGE_LDFLAGS $OS_LDFLAGS"
 
 # substitute what we need:
+AC_SUBST([INITDDIR])
 AC_SUBST([LCRSODIR])
 AC_SUBST([SOCKETDIR])
 
@@ -438,6 +444,7 @@ AC_MSG_RESULT([  Header files             = ${includedir}])
 AC_MSG_RESULT([  Arch-independent files   = ${datadir}])
 AC_MSG_RESULT([  State information        = ${localstatedir}])
 AC_MSG_RESULT([  System configuration     = ${sysconfdir}])
+AC_MSG_RESULT([  System init.d directory  = ${INITDDIR}])
 AC_MSG_RESULT([  corosync config dir      = ${COROSYSCONFDIR}])
 AC_MSG_RESULT([  LCRSO                    = ${LCRSODIR}])
 AC_MSG_RESULT([  SOCKETDIR                = ${SOCKETDIR}])

+ 2 - 3
corosync.spec.in

@@ -40,7 +40,8 @@ export rdmacm_CFLAGS=-I/usr/include/rdma \
 export rdmacm_LIBS=-lrdmacm \
 %{configure} \
 	--enable-nss \
-	--enable-rdma
+	--enable-rdma \
+	--with-initddir=%{_initddir}
 
 %build
 make %{_smp_mflags}
@@ -49,8 +50,6 @@ make %{_smp_mflags}
 rm -rf %{buildroot}
 
 make install DESTDIR=%{buildroot}
-install -d %{buildroot}%{_initddir}
-install -m 755 init/redhat %{buildroot}%{_initddir}/corosync
 
 ## tree fixup
 # drop static libs

+ 27 - 1
init/Makefile.am

@@ -34,4 +34,30 @@
 
 MAINTAINERCLEANFILES	= Makefile.in
 
-EXTRA_DIST		= generic mvlcge README redhat
+EXTRA_DIST		= generic.in
+
+target_INIT		= generic
+
+%: %.in Makefile
+	rm -f $@-t $@
+	sed \
+		-e 's#@''SBINDIR@#$(sbindir)#g' \
+		-e 's#@''SYSCONFDIR@#$(sysconfdir)#g' \
+		-e 's#@''INITDDIR@#$(INITDDIR)#g' \
+		-e 's#@''LOCALSTATEDIR@#$(localstatedir)#g' \
+	    $< > $@-t
+	chmod 0755 $@-t
+	mv $@-t $@
+
+all-local: $(target_INIT)
+
+clean-local:
+	rm -rf $(target_INIT)
+
+install-exec-local:
+	$(INSTALL) -d $(DESTDIR)/$(INITDDIR)
+	$(INSTALL) -m 755 generic $(DESTDIR)/$(INITDDIR)/corosync
+
+uninstall-local:
+	cd $(DESTDIR)/$(INITDDIR) && \
+		rm -f corosync

+ 0 - 6
init/README

@@ -1,6 +0,0 @@
-This directory contains init scripts used to start and stop the Corosync Cluster
-Engine.
-
-redhat contains an init script for Red Hat systems.
-mvlcge contains an init script for MontaVista Linux systems.
-generic contains an init script for Generic Systems.

+ 0 - 145
init/generic

@@ -1,145 +0,0 @@
-#!/bin/sh
-#
-# corosync       Start the Corosync Cluster Engine
-#
-# Author:       Andrew Beekhof <abeekhof@suse.de>
-# License:      Revised BSD
-#
-# chkconfig: - 20 20
-# processname:  corosync
-# description:  Corosync Cluster Engine
-#
-### BEGIN INIT INFO
-# Description: corosync....
-#
-# Short-Description: Corosync Cluster Engine.
-# Provides: corosync
-# Required-Start: $network
-# Should-Start: $syslog
-# Required-Stop: $network
-# Default-Start: 3 5
-# Default-Stop: 0 6
-### END INIT INFO
-
-do_force=0
-prog="corosync"
-lockfile="/var/lock/subsys/$prog"
-
-internal_status() {
-    killall -0 corosync > /dev/null 2>&1
-    return $?
-}
-
-status() {
-    if
-	! internal_status
-    then
-	echo "Stopped"
-	return 7
-    fi
-
-    echo "Running"
-    return 0
-}
-
-start() {
-    echo -n $"Starting Corosync Cluster Engine ($prog): "
-    if
-	! internal_status
-    then
-	echo -n "starting... "
-	$prog 2>&1 > /dev/null 2>&1
-	echo -n "rc=$?: "
-    fi
-
-    sleep 2 # give it time to fail... $? isn't definitive
-
-    if
-	internal_status
-    then
-	echo "OK"
-	return 0
-    fi
-
-    echo "Failed"
-    return 1
-}
-
-do_force=0
-do_forever=1
-
-stop() {
-    echo -n $"Stopping Corosync Cluster Engine ($prog): "
-
-    killall -QUIT corosync
-
-    if [ $do_forever = 0 ]; then
-	for i in 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20; do
-	    if
-		internal_status
-	    then
-		sleep 2
-		echo -n "."
-	    else
-		rm -f "$lockfile"
-		echo "OK"
-		return 0
-	    fi
-	done
-
-	if [ $do_force = 1 ]; then
-	    echo -n "Escalating... "
-	    killall -KILL corosync
-	    sleep 5
-
-	    if
-		! internal_status
-	    then
-		rm -f "$lockfile"
-		echo "OK"
-		return 0
-	    fi
-	fi
-
-	echo "Failed"
-	return 1
-    fi
-
-    while
-        internal_status
-    do
-	sleep 1
-	echo -n "."
-    done
-
-    rm -f "$lockfile"
-    echo "OK"
-    return 0
-}
-
-restart() {
-    stop
-    start
-}
-
-case "$1" in
-    start|stop|restart)
-        $1
-        ;;
-    force-stop)
-	do_force=1
-        stop
-        ;;
-    reload|force-reload)
-        restart
-        ;;
-    condrestart|try-restart)
-        [ ! -f "$lockfile" ] || restart
-        ;;
-    status)
-        status $prog
-        ;;
-    *)
-        echo $"Usage: $0 {start|stop|restart|try-restart|condrestart|reload|force-reload|force-stop|status}"
-        exit 2
-esac

+ 146 - 0
init/generic.in

@@ -0,0 +1,146 @@
+#!/bin/bash
+
+# Authors:
+#  Andrew Beekhof <abeekhof@redhat.com>
+#  Fabio M. Di Nitto <fdinitto@redhat.com>
+#
+# License: Revised BSD
+
+# chkconfig: - 20 20
+# description: Corosync Cluster Engine
+# processname: corosync
+#
+### BEGIN INIT INFO
+# Provides:		corosync
+# Required-Start:	$network
+# Should-Start:		$syslog
+# Required-Stop:	$network
+# Default-Start:
+# Default-Stop:
+# Short-Description:	Starts and stops Corosync Cluster Engine.
+# Description:		Starts and stops Corosync Cluster Engine.
+### END INIT INFO
+
+desc="Corosync Cluster Engine"
+prog="corosync"
+
+# 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)
+	rtrn=$?
+	if [ $rtrn -ne 0 ]; then
+		echo "$1 is stopped"
+	else
+		echo "$1 (pid $pid) is running..."
+	fi
+	return $rtrn
+}
+
+# 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
+
+start()
+{
+	echo -n "Starting $desc ($prog): "
+
+	# 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 > /dev/null 2>&1
+
+		# give it time to fail
+		sleep 2
+		if status $prog > /dev/null 2>&1; then
+			touch $LOCK_FILE
+			pidof $prog > @LOCALSTATEDIR@/run/$prog.pid
+			success
+		else
+			failure
+			rtrn=1
+		fi
+	fi
+	echo
+}
+
+stop()
+{
+	echo -n "Signaling $desc ($prog) to terminate: "
+	killall -TERM $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
+	rm -f @LOCALSTATEDIR@/run/$prog.pid
+	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

+ 0 - 26
init/mvlcge

@@ -1,26 +0,0 @@
-#! /bin/sh
-#
-# Application Interface Specification Startup
-# chkconfig: 2345 20 20
-
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-
-test -f /usr/sbin/corosync | exit 0
-
-case "$1" in
-	start)
- 		echo -n "Starting Corosync Cluster Engine: "
-		start-stop-daemon --start --quiet --exec /usr/sbin/corosync
-		echo "."
-
-		;;
-       	stop)
-		echo -n "Stopping Corosync Cluster Engine: "
-		start-stop-daemon --stop --quiet --exec /usr/sbin/corosync
-		echo "."
-               	;;
-       	*)
-               echo "Usage: /etc/init.d/corosync {start|stop}" >&2
-               exit 1
-               ;;
-esac

+ 0 - 71
init/redhat

@@ -1,71 +0,0 @@
-#!/bin/sh
-#
-# Corosync daemon init script for Red Hat Linux and compatibles.
-#
-# chkconfig: - 20 20
-# processname:  corosync
-# pidfile:      /var/run/corosync.pid
-# description:  Corosync Cluster Engine
-
-# Source function library
-. /etc/rc.d/init.d/functions
-
-prog="corosync"
-exec="/usr/sbin/corosync"
-lockfile="/var/lock/subsys/corosync"
-DAEMON_COREFILE_LIMIT=unlimited
-
-[ -x "$exec" ] || exit 0
-
-start() {
-    echo -n $"Starting Corosync Cluster Engine ($prog): "
-    daemon $exec
-    retval=$?
-    [ "$retval" -eq 0 ] && touch "$lockfile"
-    echo
-    return $retval
-}
-
-stop() {
-    echo -n $"Stopping Corosync Cluster Engine ($prog): "
-    # If no signal is specified, -TERM is used but _also_ -KILL 3s later
-    # This is far too aggressive for a cluster resource manager running on top of Corosync
-    killproc $prog -TERM
-    echo
-
-    echo -n $"Waiting for services to unload:"
-    while
-        pidofproc $prog > /dev/null 2>&1
-    do
-        sleep 2
-    done
-
-    success $"$base shutdown"
-    echo
-
-    rm -f "$lockfile"
-    return 0
-}
-
-restart() {
-    stop
-    start
-}
-
-case "$1" in
-    start|stop|restart)
-        $1
-        ;;
-    reload|force-reload)
-        restart
-        ;;
-    condrestart|try-restart)
-        [ ! -f "$lockfile" ] || restart
-        ;;
-    status)
-        status $prog
-        ;;
-    *)
-        echo $"Usage: $0 {start|stop|restart|try-restart|condrestart|reload|force-reload|status}"
-        exit 2
-esac