This patch adds an LSB style init script to the build system.  It also
installs it within the created RPM file.

Please ignore last patch, was missing generic.in file.

Signed-off-by: Steven Dake <[email protected]>
---
 configure.ac       |    1 +
 script/Makefile.am |   28 ++++++++++
 script/generic.in  |  141 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 sheepdog.spec.in   |    1 +
 4 files changed, 171 insertions(+), 0 deletions(-)
 create mode 100755 script/generic.in

diff --git a/configure.ac b/configure.ac
index bf4d86e..b09b9e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -274,6 +274,7 @@ AC_SUBST([OS_DYFLAGS])
 
 AM_CONDITIONAL(BUILD_HTML_DOCS, test -n "${GROFF}")
 
+AC_SUBST([INITDDIR])
 AC_SUBST([LINT_FLAGS])
 
 AC_DEFINE_UNQUOTED([LOCALSTATEDIR], "$(eval echo ${localstatedir})", 
[localstate directory])
diff --git a/script/Makefile.am b/script/Makefile.am
index 3e6c380..22987ca 100644
--- a/script/Makefile.am
+++ b/script/Makefile.am
@@ -1,3 +1,31 @@
 MAINTAINERCLEANFILES    = Makefile.in
 
+EXTRA_DIST             = generic.in
+
 noinst_HEADERS         = bash_completion_collie checkarch.sh check-dog.pl 
start-sheepdog stop-sheepdog vditest
+
+target_INIT             = generic
+
+%: %.in Makefile
+       rm -f $...@-t $@
+       sed \
+               -e 's#@''sbin...@#$(sbindir)#g' \
+               -e 's#@''sysconf...@#$(sysconfdir)#g' \
+               -e 's#@''initd...@#$(INITDDIR)#g' \
+               -e 's#@''localstate...@#$(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)/sheepdog
+
+uninstall-local:
+       cd $(DESTDIR)/$(INITDDIR) && \
+               rm -f sheepdog
diff --git a/script/generic.in b/script/generic.in
new file mode 100755
index 0000000..a57ebc5
--- /dev/null
+++ b/script/generic.in
@@ -0,0 +1,141 @@
+#!/bin/bash
+# chkconfig: - 21 21
+# description: Sheepdog
+# processname: sheep
+#
+### BEGIN INIT INFO
+# Provides:            sheepdog
+# Required-Start:      $network
+# Should-Start:                $syslog
+# Required-Stop:       $network
+# Default-Start:
+# Default-Stop:
+# Short-Description:   Starts and stops Sheepdog.
+# Description:         Starts and stops Sheepdog.
+### END INIT INFO
+desc="Sheepdog QEMU/KVM Block Storage"
+prog="sheep"
+
+# set secure PATH
+PATH="/sbin:/bin:/usr/sbin:/usr/bin:@SBINDIR@"
+sheepdo...@sbindir@/sheep
+
+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
+
+# 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##*/}"
+}
+
+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 -p 7000 @LOCALSTATEDIR@/lib/sheepdog > /dev/null 2>&1
+
+               # give it time to fail
+               sleep 2
+               if status $prog > /dev/null 2>&1; then
+                       touch $LOCK_FILE
+                       success
+               else
+                       failure
+                       rtrn=1
+               fi
+       fi
+       echo
+}
+
+stop()
+{
+       ! status $prog > /dev/null 2>&1 && return
+
+       echo -n "Stopping $desc ($prog): "
+       killproc $prog
+       RETVAL=$?
+       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/sheepdog.spec.in b/sheepdog.spec.in
index 852fe51..ea9eb5e 100644
--- a/sheepdog.spec.in
+++ b/sheepdog.spec.in
@@ -45,6 +45,7 @@ This package contains the Sheepdog server, and command line 
tool.
 %doc COPYING README
 %{_sbindir}/sheep
 %{_sbindir}/collie
+%{_initddir}/sheepdog
 %dir %{_localstatedir}/lib/sheepdog
 
 %changelog
-- 
1.7.2.1

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to