[sheepdog] [PATCH] initial systemd support

Vasiliy Tolstov v.tolstov at selfip.ru
Thu Oct 23 17:40:47 CEST 2014


Signed-off-by: Vasiliy Tolstov <v.tolstov at selfip.ru>
---
 configure.ac               | 33 +++++++++++++++++++++++++++++++++
 script/Makefile.am         | 11 +++++++----
 script/sheepdog.in         |  7 +++++++
 script/sheepdog.service.in | 15 +++++++++++++++
 4 files changed, 62 insertions(+), 4 deletions(-)
 create mode 100644 script/sheepdog.service.in

diff --git a/configure.ac b/configure.ac
index 69a2b40..6e7c141 100644
--- a/configure.ac
+++ b/configure.ac
@@ -265,6 +265,39 @@ AC_ARG_ENABLE([diskvnodes],
 	[ enable_diskvnodes="no" ],)
 AM_CONDITIONAL(BUILD_DISKVNODES, test x$enable_diskvnodes = xyes)
 
+AC_ARG_ENABLE(systemd, AS_HELP_STRING([--enable-systemd],[enable systemd support]),enable_systemd=$enableval,enable_systemd="no")
+
+dnl systemd detection
+if test x$enable_systemd = xno ; then
+    have_systemd=no;
+else
+    PKG_CHECK_MODULES([SYSTEMD],
+        [libsystemd >= 209],
+        [have_systemd=yes])
+fi
+
+if test x$have_systemd = xyes; then
+    AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
+fi
+
+if test x$enable_systemd = xyes -a x$have_systemd != xyes ; then
+    AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
+fi
+
+##### systemd unit files
+AC_ARG_WITH([systemdsystemunitdir],
+AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
+    [],
+    [
+    PKG_CHECK_EXISTS([systemd],
+      [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)],
+      [with_systemdsystemunitdir=no])
+    ])
+if test "x$with_systemdsystemunitdir" != xno; then
+   AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
+fi
+AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$have_systemd" != "xno" -a -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
+
 
 CP=cp
 OS_LDL="-ldl"
diff --git a/script/Makefile.am b/script/Makefile.am
index a2fa93e..5e88b59 100644
--- a/script/Makefile.am
+++ b/script/Makefile.am
@@ -1,12 +1,15 @@
 MAINTAINERCLEANFILES    = Makefile.in
 
-EXTRA_DIST		= sheepdog.in
+EXTRA_DIST		= sheepdog.in sheepdog.service.in
 
 noinst_HEADERS		= checkarch.sh vditest gen_man.pl gen_bash_completion.pl
 
 initscript_SCRIPTS	= sheepdog
 initscriptdir		= $(INITDDIR)
 
+systemd_DATA = sheepdog.service
+systemddir = $(systemdsystemunitdir)
+
 completion_DATA		= dog
 completiondir		= $(sysconfdir)/bash_completion.d
 
@@ -23,10 +26,10 @@ dog: gen_bash_completion.pl Makefile
 		-e 's#@''INITDDIR@#$(INITDDIR)#g' \
 		-e 's#@''LOCALSTATEDIR@#$(localstatedir)#g' \
 		$< > $@-t
-	chmod 0755 $@-t
+	if [ $@ != "sheepdog.service" ]; then chmod 0755 $@-t; fi
 	mv $@-t $@
 
-all-local: $(initscript_SCRIPTS) $(completion_DATA)
+all-local: $(initscript_SCRIPTS) $(systemd_SERVICES) $(completion_DATA)
 
 clean-local:
-	rm -rf $(initscript_SCRIPTS) $(completion_DATA)
+	rm -rf $(initscript_SCRIPTS) $(systemd_SERVICES) $(completion_DATA)
diff --git a/script/sheepdog.in b/script/sheepdog.in
index 81a6ebe..bb38eea 100755
--- a/script/sheepdog.in
+++ b/script/sheepdog.in
@@ -55,6 +55,13 @@ if [ -d @SYSCONFDIR@/default ]; then
 	[ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog"
 fi
 
+# gentoo/exherbo/sabayon based distros
+if [ -d @SYSCONFDIR@/conf.d ]; then
+  [ -f @SYSCONFDIR@/conf.d/$prog.conf ] && . @SYSCONFDIR@/conf.d/$prog.conf
+  [ -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.
diff --git a/script/sheepdog.service.in b/script/sheepdog.service.in
new file mode 100644
index 0000000..555083e
--- /dev/null
+++ b/script/sheepdog.service.in
@@ -0,0 +1,15 @@
+[Unit]
+Description=Sheepdog QEMU/KVM Block Storage
+After=network.target
+Wants=syslog.target
+
+[Service]
+EnvironmentFile=- at SYSCONFDIR@/conf.d/sheepdog.conf
+EnvironmentFile=- at SYSCONFDIR@/sysconfig/sheepdog
+EnvironmentFile=- at SYSCONFDIR@/default/sheepdog
+ExecStart=@SBINDIR@/sheep --pidfile @LOCALSTATEDIR@/run/sheep.pid ${SHEEP_OPTS:-"--cluster local --log syslog --pidfile @LOCALSTATEDIR@/run/sheep.pid --upgrade @LOCALSTATEDIR@/lib/sheepdog"}
+PIDFile=@LOCALSTATEDIR@/run/sheep.pid
+Type=forking
+
+[Install]
+WantedBy=multi-user.target
-- 
2.0.1




More information about the sheepdog mailing list