Add systemd service file
PATCH 1/1 Add systemd service file
Hi,
I'm attaching a patch that installs a systemd service on make install. See here for motivation:
http://article.gmane.org/gmane.comp.sysutils.systemd.devel/1289
The systemd-specific part is Ack'ed by Lennart.
Thanks.
-------------- next part --------------
Quoted 1 line
From
4e34b2d76428e244bcacb9554583290b2f08230fMon Sep 17 00:00:00 2001
From: Miklos Vajna <[email protected]>
Date: Fri, 18 Feb 2011 15:19:38 +0100
Subject: [PATCH] Add systemd service file
--- Makefile.in | 4 ++++ configure.in | 20 ++++++++++++++++++++ make.tmpl.in | 1 + systemd/Makefile.in | 16 ++++++++++++++++ systemd/lvm.service | 15 +++++++++++++++ 5 files changed, 56 insertions(+), 0 deletions(-) create mode 100644 systemd/Makefile.in create mode 100644 systemd/lvm.service
Makefile.in +4 -0
@@ -22,6 +22,10 @@ ifeq ("@UDEV_RULES@", "yes") SUBDIRS += udev endif +ifeq ("@SYSTEMD_SERVICE@", "yes") + SUBDIRS += systemd +endif + ifeq ("@INTL@", "yes") SUBDIRS += po endif
configure.in +20 -0
@@ -818,6 +818,23 @@ AC_ARG_ENABLE(udev_rules, AC_MSG_RESULT($UDEV_RULES) ################################################################################ +dnl -- Enable systemd service +PKG_PROG_PKG_CONFIG +AC_MSG_CHECKING(systemd system unit directory) +AC_ARG_WITH([systemdsystemunitdir], + AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]), + [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)]) +if test "x$with_systemdsystemunitdir" != xno; then + AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir]) +fi +AC_MSG_RESULT($systemdsystemunitdir) +if test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno; then + SYSTEMD_SERVICE=yes +else + SYSTEMD_SERVICE=no +fi + +################################################################################ dnl -- Compatibility mode AC_ARG_ENABLE(compat, AC_HELP_STRING([--enable-compat],
@@ -1368,6 +1385,7 @@ AC_SUBST(UDEV_LIBS) AC_SUBST(UDEV_PC) AC_SUBST(UDEV_RULES) AC_SUBST(UDEV_SYNC) +AC_SUBST(SYSTEMD_SERVICE) AC_SUBST(WRITE_INSTALL) AC_SUBST(interface) AC_SUBST(kerneldir)
@@ -1376,6 +1394,7 @@ AC_SUBST(kernelvsn) AC_SUBST(tmpdir) AC_SUBST(udev_prefix) AC_SUBST(udevdir) +AC_SUBST(systemdsystemunitdir) AC_SUBST(usrlibdir) AC_SUBST(usrsbindir)
@@ -1420,6 +1439,7 @@ test/Makefile test/api/Makefile tools/Makefile udev/Makefile +systemd/Makefile unit-tests/datastruct/Makefile unit-tests/regex/Makefile unit-tests/mm/Makefile
make.tmpl.in +1 -0
@@ -63,6 +63,7 @@ mandir = $(datarootdir)/man localedir = $(DESTDIR)@LOCALEDIR@ staticdir = $(DESTDIR)@STATICDIR@ udevdir = $(DESTDIR)@udevdir@ +systemdsystemunitdir = $(DESTDIR)@systemdsystemunitdir@ pkgconfigdir = $(usrlibdir)/pkgconfig initdir = $(DESTDIR)@sysconfdir@/rc.d/init.d ocf_scriptdir = $(DESTDIR)@OCFDIR@
systemd/Makefile.in new file +16 -0
@@ -0,0 +1,16 @@ +# This file is part of LVM2. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions +# of the GNU General Public License v.2. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +top_builddir = @top_builddir@ + +include $(top_builddir)/make.tmpl + +install: lvm.service + $(INSTALL_DATA) -D $< $(systemdsystemunitdir)/$<
systemd/lvm.service new file +15 -0
@@ -0,0 +1,15 @@ +[Unit] +Description=LVM activation +DefaultDependencies=no +After=udev-settle.service +Before=basic.target shutdown.target +Conflicts=shutdown.target + +[Service] +ExecStart=/sbin/vgchange -a y +Type=oneshot +TimeoutSec=0 +RemainAfterExit=yes + +[Install] +WantedBy=basic.target
Signature · 9 lines
1.7.3.4 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: not available URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20110218/73960f96/attachment.sig>
PATCH 1/1 Add systemd service file
Could you explain a bit more how the sequence of activations will work?
vgchange -ay is rather crude and not what everyone will require.
- Where do people configure (or have auto-detected) the LVs they want activated at boot?
- How do clustered VGs fit in? (look at the existing init script)
- How do stacked devices fit in?
Alasdair
PATCH 1/1 Add systemd service file
Quoted 1 line · Alasdair G Kergon
- How do stacked devices fit in?
What I'm suggesting is that a udev-rule-based solution should work
better than a service file. In the mean time, you'll probably need to
add several service files with various dependencies to cover the different possibilities. (lvchange must run after md is activated; lvchange must run before md is activate; lvchange must run before cluster is activated; lvchange must run after cluster is activated; same for other block-device creating components like cryptsetup, loop etc.)
Alasdair
PATCH 1/1 Add systemd service file
Quoted 7 lines · Alasdair G Kergon
What I'm suggesting is that a udev-rule-based solution should work
better than a service file. In the mean time, you'll probably need to
add several service files with various dependencies to cover the different possibilities. (lvchange must run after md is activated; lvchange must run before md is activate; lvchange must run before cluster is activated; lvchange must run after cluster is activated; same for other block-device creating components like cryptsetup, loop etc.)
My udev-fu is quite low - if that's possible, I'm happy with it as well. The goal is to avoid distro-specific init scripts.
However, vgchange is at the very end of fedora-storage-init, so we could simply add dependencies to run mdadm (when later someone writes service files for that) before vgchange and that would work as well.
A fixed execution order is already there with the current shell scripts, as far as I understand.
Thanks.
PATCH 1/1 Add systemd service file
In reply to Alasdair G KergonHi Alasdair,
Quoted 1 line · Alasdair G Kergon
Could you explain a bit more how the sequence of activations will work?
Sure - this is for the case of general desktop/server situations, when there are a few LVs. (Not thousands of it.)
This service file is invoked after udev settled, so all device nodes area available. An other dependency also makes sure that vgchange is invoked before we would run fsck on the LVs.
Quoted 1 line
vgchange -ay is rather crude and not what everyone will require.
Agreed, the service file is just installed, but not enabled, that's up to the distro packagers / system administrators. However, I think it suits the general case, I mean for example Fedora has 'vgchange -a y' as well in its fedora-storage-init script, and we had something similar in Frugalware's lvm2 sysv init script. The patch is to avoid every distribution have its own custom service file.
Quoted 2 lines
- Where do people configure (or have auto-detected) the LVs they want activated at boot?
Just like the fedora-storage-init script, this unconditionally enables all LVs.
Quoted 3 lines
- How do clustered VGs fit in? (look at the existing init script)
- How do stacked devices fit in?
This service file does not replace all existing init scripts - at least service files for lvm2-monitor, clvmd and cmirrord can be added in the future.
What it does is move part of the distro-specific scripts (in Fedora's case, fedora-storage-init) to a native systemd service, so that distro packager won't reinvent the wheel.
Sorry in case it seemed that this patch intents to replace all sysv init scripts at once. :)
Thanks,
Miklos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20110218/ae9c17da/attachment.sig>
PATCH 1/1 Add systemd service file
Dne 18.2.2011 18:04, Miklos Vajna napsal(a):
Quoted 17 lines
Hi Alasdair,
Quoted 1 line · Alasdair G Kergon
Could you explain a bit more how the sequence of activations will work?
Sure - this is for the case of general desktop/server situations, when there are a few LVs. (Not thousands of it.)
This service file is invoked after udev settled, so all device nodes area available. An other dependency also makes sure that vgchange is invoked before we would run fsck on the LVs.
Quoted 1 line
vgchange -ay is rather crude and not what everyone will require.
Agreed, the service file is just installed, but not enabled, that's up to the distro packagers / system administrators. However, I think it suits the general case, I mean for example Fedora has 'vgchange -a y' as
...
Quoted 8 lines
What it does is move part of the distro-specific scripts (in Fedora's case, fedora-storage-init) to a native systemd service, so that distro packager won't reinvent the wheel.
Sorry in case it seemed that this patch intents to replace all sysv init scripts at once. :)
I think at this moment, systemd init script is way too much 'distro-oriented' to make it usable from default package installation.
(We do not ship SysV nor Upstart script either)
It's probably for discussion how the 'startup' should be configurable, where to put configurable parts for startup script and how to handle dependencies. Currently I do not see big use for the currently proposed patch
(I think you are repeating here when initially systemd
automatically mounted all filesystems from fstab...)
Zdenek