summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2012-07-29 19:46:53 +0200
committerJoey Hess <joey@kitenet.net>2012-10-28 13:55:49 -0400
commit515ab3ada00addcc89b19dfcb5e4f1e1ff489aad (patch)
treebdd104fcc9785da5bd165ee048fe819973989bc6
parent331434d0bb2f7bd1996566abb20e975cb234c878 (diff)
Support systemd in dh_installinit and postinst/postrm
-rw-r--r--autoscripts/postinst-init6
-rw-r--r--autoscripts/postinst-init-nostart6
-rw-r--r--autoscripts/postinst-init-restart6
-rw-r--r--autoscripts/postrm-init7
-rwxr-xr-xdh_installinit47
5 files changed, 67 insertions, 5 deletions
diff --git a/autoscripts/postinst-init b/autoscripts/postinst-init
index 2430b2c0..f5371ce8 100644
--- a/autoscripts/postinst-init
+++ b/autoscripts/postinst-init
@@ -1,4 +1,10 @@
if [ -x "/etc/init.d/#SCRIPT#" ]; then
+ # In case this system is running systemd, we need to ensure that all
+ # necessary tmpfiles (if any) are created before starting.
+ if [ -d /sys/fs/cgroup/systemd ] ; then
+ systemd-tmpfiles --create >/dev/null || true
+ fi
+
update-rc.d #SCRIPT# #INITPARMS# >/dev/null
invoke-rc.d #SCRIPT# start || #ERROR_HANDLER#
fi
diff --git a/autoscripts/postinst-init-nostart b/autoscripts/postinst-init-nostart
index 7a1bd5e8..ec6bdbd6 100644
--- a/autoscripts/postinst-init-nostart
+++ b/autoscripts/postinst-init-nostart
@@ -1,3 +1,9 @@
if [ -x "/etc/init.d/#SCRIPT#" ]; then
+ # In case this system is running systemd, we need to ensure that all
+ # necessary tmpfiles (if any) are created before starting.
+ if [ -d /sys/fs/cgroup/systemd ] ; then
+ systemd-tmpfiles --create >/dev/null || true
+ fi
+
update-rc.d #SCRIPT# #INITPARMS# >/dev/null || #ERROR_HANDLER#
fi
diff --git a/autoscripts/postinst-init-restart b/autoscripts/postinst-init-restart
index 35bba207..862f9cc3 100644
--- a/autoscripts/postinst-init-restart
+++ b/autoscripts/postinst-init-restart
@@ -1,4 +1,10 @@
if [ -x "/etc/init.d/#SCRIPT#" ]; then
+ # In case this system is running systemd, we need to ensure that all
+ # necessary tmpfiles (if any) are created before starting.
+ if [ -d /sys/fs/cgroup/systemd ] ; then
+ systemd-tmpfiles --create >/dev/null || true
+ fi
+
update-rc.d #SCRIPT# #INITPARMS# >/dev/null
if [ -n "$2" ]; then
_dh_action=restart
diff --git a/autoscripts/postrm-init b/autoscripts/postrm-init
index 1c292982..61dcfc53 100644
--- a/autoscripts/postrm-init
+++ b/autoscripts/postrm-init
@@ -1,3 +1,10 @@
if [ "$1" = "purge" ] ; then
update-rc.d #SCRIPT# remove >/dev/null
fi
+
+
+# In case this system is running systemd, we make systemd reload the unit files
+# to pick up changes.
+if [ -d /sys/fs/cgroup/systemd ] ; then
+ systemctl --system daemon-reload >/dev/null || true
+fi
diff --git a/dh_installinit b/dh_installinit
index 9c8c1550..65e143a5 100755
--- a/dh_installinit
+++ b/dh_installinit
@@ -2,7 +2,7 @@
=head1 NAME
-dh_installinit - install init scripts and/or upstart jobs into package build directories
+dh_installinit - install init scripts and/or upstart jobs and/or systemd services into package build directories
=cut
@@ -42,6 +42,16 @@ build directory.
If this exists, it is installed into etc/init/I<package>.conf in the package
build directory.
+=item debian/I<package>.service
+
+If this exists, it is installed into lib/systemd/system/I<package>.service in
+the package build directory.
+
+=item debian/I<package>.tmpfile
+
+If this exists, it is installed into usr/lib/tmpfiles.d/I<package>.conf in the
+package build directory.
+
=back
=head1 OPTIONS
@@ -55,9 +65,10 @@ Do not modify F<postinst>/F<postrm>/F<prerm> scripts.
=item B<-o>, B<--onlyscripts>
Only modify F<postinst>/F<postrm>/F<prerm> scripts, do not actually install any init
-script, default files, or upstart job. May be useful if the init script or
-upstart job is shipped and/or installed by upstream in a way that doesn't
-make it easy to let B<dh_installinit> find it.
+script, default files, upstart job or systemd service file. May be useful if
+the init script, upstart job or systemd service file is shipped and/or
+installed by upstream in a way that doesn't make it easy to let
+B<dh_installinit> find it.
=item B<-R>, B<--restart-after-upgrade>
@@ -171,6 +182,26 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
$script=$package;
}
+ my $service=pkgfile($package,"service");
+ if ($service ne '' && ! $dh{ONLYSCRIPTS}) {
+ my $path="$tmp/lib/systemd/system";
+ if (! -d "$path") {
+ doit("install","-d","$path");
+ }
+
+ doit("install","-p","-m644",$service,"$path/$script.service");
+ }
+
+ my $tmpfile=pkgfile($package,"tmpfile");
+ if ($tmpfile ne '' && ! $dh{ONLYSCRIPTS}) {
+ my $path="$tmp/usr/lib/tmpfiles.d";
+ if (! -d "$path") {
+ doit("install","-d","$path");
+ }
+
+ doit("install","-p","-m644",$tmpfile,"$path/$script.conf");
+ }
+
my $job=pkgfile($package,"upstart");
if ($job ne '' && ! $dh{ONLYSCRIPTS}) {
@@ -203,7 +234,11 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
error("Can't use --init-script with an upstart job");
}
- if ($job ne '' || $init ne '' || $dh{ONLYSCRIPTS}) {
+ # NB: The case that only $tmpfile is set makes no sense. The
+ # tmpfiles.d(5) mechanism is only available when using systemd (at
+ # least currently), so there has to be an init script which does the
+ # same thing for sysvinit.
+ if ($service ne '' || $job ne '' || $init ne '' || $dh{ONLYSCRIPTS}) {
# This is set by the -u "foo" command line switch, it's
# the parameters to pass to update-rc.d. If not set,
# we have to say "defaults".
@@ -265,4 +300,6 @@ Joey Hess <joeyh@debian.org>
Steve Langasek <steve.langasek@canonical.com>
+Michael Stapelberg <stapelberg@debian.org>
+
=cut