[virt-tools-list] [vhostmd 2/2] Add systemd service file
Jim Fehlig
jfehlig at suse.com
Wed Jun 6 19:46:55 UTC 2018
vhostmd is long overdue for a systemd service file. Add one, and
while at it support specifying the type of init system in the
configure script.
Signed-off-by: Jim Fehlig <jfehlig at suse.com>
---
Makefile.am | 36 +++++++++++++++++++++++++++++++++---
configure.ac | 24 +++++++++++++++++++++++-
vhostmd.service | 14 ++++++++++++++
3 files changed, 70 insertions(+), 4 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 8234d98..4f8af15 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,11 +7,41 @@ EXTRA_DIST = $(doc_DATA) vhostmd.init vhostmd.spec autogen.sh
AUTOMAKE_OPTIONS=dist-bzip2
-install-data-local:
+install-data-local: install-init-systemv install-init-systemd
$(MKDIR_P) $(DESTDIR)/etc/vhostmd
- $(MKDIR_P) $(DESTDIR)/etc/init.d
- $(MKDIR_P) $(DESTDIR)/usr/sbin
$(INSTALL_DATA) $(srcdir)/vhostmd.xml $(DESTDIR)/etc/vhostmd/vhostmd.conf
$(INSTALL_DATA) $(srcdir)/vhostmd.dtd $(DESTDIR)/etc/vhostmd
$(INSTALL_DATA) $(srcdir)/metric.dtd $(DESTDIR)/etc/vhostmd
+
+uninstall-local: uninstall-init-systemv uninstall-init-systemd
+ rm -f $(DESTDIR)/etc/vhostmd/vhostmd.conf
+ rm -f $(DESTDIR)/etc/vhostmd/vhostmd.dtd
+ rm -f $(DESTDIR)/etc/vhostmd/metric.dtd
+ rmdir $(DESTDIR)/etc/vhostmd || :
+
+if INIT_SCRIPT_SYSTEMV
+install-init-systemv: $(srcdir)/vhostmd.init
+ $(MKDIR_P) $(DESTDIR)$(sysconfdir)/init.d
$(INSTALL_SCRIPT) $(srcdir)/vhostmd.init $(DESTDIR)/etc/init.d/vhostmd
+
+uninstall-init-systemv:
+ rm -f $(DESTDIR)$(sysconfdir)/init.d/vhostmd
+ rmdir $(DESTDIR)$(sysconfdir)/init.d || :
+else ! INIT_SCRIPT_SYSTEMV
+install-init-systemv:
+uninstall-init-systemv:
+endif ! INIT_SCRIPT_SYSTEMV
+
+if INIT_SCRIPT_SYSTEMD
+SYSTEMD_UNIT_DIR = $(prefix)/lib/systemd/system
+install-init-systemd: $(srcdir)/vhostmd.service
+ $(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNIT_DIR)
+ $(INSTALL_DATA) $(srcdir)/vhostmd.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/vhostmd.service
+
+uninstall-init-systemd:
+ rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/vhostmd.service
+ rmdir $(DESTDIR)$(SYSTEMD_UNIT_DIR) || :
+else ! INIT_SCRIPT_SYSTEMD
+install-init-systemd:
+uninstall-init-systemd:
+endif ! INIT_SCRIPT_SYSTEMD
diff --git a/configure.ac b/configure.ac
index 27c8488..b0a07c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT(Virtual Host Metrics Daemon, 0.5, jfehlig at novell.com, vhostmd)
+AC_INIT(Virtual Host Metrics Daemon, 0.5, jfehlig at suse.com, vhostmd)
AC_CONFIG_SRCDIR(vhostmd/vhostmd.c)
AC_CONFIG_HEADERS([config.h])
@@ -82,6 +82,28 @@ AC_ARG_WITH([xenstore],
esac],[AC_CHECK_HEADER(xs.h, with_xenstore=true)])
AM_CONDITIONAL(WITH_XENSTORE, test x$with_xenstore = xtrue)
+# Configure argument to support type of init system
+AC_ARG_WITH([init_script],
+ [AS_HELP_STRING([--with-init-script],
+ [Type of init script to install: systemv, systemd, check @<:@default=check@:>@])],
+ [],
+ [with_init_script=check])
+init_systemv=no
+init_systemd=no
+if test "$with_init_script" = check && type systemctl >/dev/null 2>&1; then
+ init_systemd=yes
+else
+ init_systemv=yes
+fi
+case "${with_init_script}" in
+ systemv) init_systemv=yes;;
+ systemd) init_systemd=yes;;
+ check) ;;
+ *) AC_MSG_ERROR([Unknown initscript type $with_init_script]);;
+esac
+AM_CONDITIONAL([INIT_SCRIPT_SYSTEMV], test "$init_systemv" = "yes")
+AM_CONDITIONAL([INIT_SCRIPT_SYSTEMD], test "$init_systemd" = "yes")
+
AC_OUTPUT(vhostmd/Makefile
include/Makefile
libmetrics/Makefile
diff --git a/vhostmd.service b/vhostmd.service
new file mode 100644
index 0000000..9d50523
--- /dev/null
+++ b/vhostmd.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Daemon for collecting virutalization host metrics
+After=libvirtd.service
+Documentation=man:vhostmd(8)
+
+[Service]
+Type=forking
+ExecStart=/usr/sbin/vhostmd
+ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
--
2.16.3
More information about the virt-tools-list
mailing list