diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-06-19 08:15:58 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-06-19 08:16:18 +0200 |
commit | 993739802c84e59334ea15fc564cfc143ffbdc97 (patch) | |
tree | 841387898549eb6c8a489b5086fc9d63a5bf7c02 | |
parent | bd4ea14f372d8140ee7ab79d1d7ced9f1a89f8dc (diff) | |
download | init-system-helpers-993739802c84e59334ea15fc564cfc143ffbdc97.tar.gz |
add deb-systemd-invoke, a wrapper which respects (basic) policy.d
-rw-r--r-- | Makefile.PL | 1 | ||||
-rw-r--r-- | autoscripts/postinst-systemd-restart | 2 | ||||
-rw-r--r-- | autoscripts/postinst-systemd-start | 2 | ||||
-rw-r--r-- | autoscripts/prerm-systemd | 2 | ||||
-rw-r--r-- | autoscripts/prerm-systemd-restart | 2 | ||||
-rw-r--r-- | debian/init-system-helpers.install | 2 | ||||
-rwxr-xr-x | script/deb-systemd-invoke | 85 |
7 files changed, 92 insertions, 4 deletions
diff --git a/Makefile.PL b/Makefile.PL index 10e47e8..749aed9 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,6 +4,7 @@ name 'init-system-helpers'; version '1.2'; install_script 'deb-systemd-helper'; +install_script 'deb-systemd-invoke'; install_script 'dh_systemd_enable'; install_script 'dh_systemd_start'; diff --git a/autoscripts/postinst-systemd-restart b/autoscripts/postinst-systemd-restart index 1b1e7c8..8fe18ce 100644 --- a/autoscripts/postinst-systemd-restart +++ b/autoscripts/postinst-systemd-restart @@ -1,4 +1,4 @@ if [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true - systemctl try-restart #UNITFILES# >/dev/null || true + deb-systemd-invoke try-restart #UNITFILES# >/dev/null || true fi diff --git a/autoscripts/postinst-systemd-start b/autoscripts/postinst-systemd-start index e91e213..8134a04 100644 --- a/autoscripts/postinst-systemd-start +++ b/autoscripts/postinst-systemd-start @@ -1,4 +1,4 @@ if [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true - systemctl start #UNITFILES# >/dev/null || true + deb-systemd-invoke start #UNITFILES# >/dev/null || true fi diff --git a/autoscripts/prerm-systemd b/autoscripts/prerm-systemd index aa36110..6cc7242 100644 --- a/autoscripts/prerm-systemd +++ b/autoscripts/prerm-systemd @@ -1,3 +1,3 @@ if [ -d /run/systemd/system ]; then - systemctl stop #UNITFILES# >/dev/null + deb-systemd-invoke stop #UNITFILES# >/dev/null fi diff --git a/autoscripts/prerm-systemd-restart b/autoscripts/prerm-systemd-restart index 6f4e584..51abb0b 100644 --- a/autoscripts/prerm-systemd-restart +++ b/autoscripts/prerm-systemd-restart @@ -1,3 +1,3 @@ if [ -d /run/systemd/system ] && [ "$1" = remove ]; then - systemctl stop #UNITFILES# >/dev/null + deb-systemd-invoke stop #UNITFILES# >/dev/null fi diff --git a/debian/init-system-helpers.install b/debian/init-system-helpers.install index 3813300..66dc4f6 100644 --- a/debian/init-system-helpers.install +++ b/debian/init-system-helpers.install @@ -1,2 +1,4 @@ usr/bin/deb-systemd-helper +usr/bin/deb-systemd-invoke usr/share/man/man1/deb-systemd-helper.1p +usr/share/man/man1/deb-systemd-invoke.1p diff --git a/script/deb-systemd-invoke b/script/deb-systemd-invoke new file mode 100755 index 0000000..d157530 --- /dev/null +++ b/script/deb-systemd-invoke @@ -0,0 +1,85 @@ +#!/usr/bin/env perl +# vim:ts=4:sw=4:expandtab +# © 2013 Michael Stapelberg <stapelberg@debian.org> +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Michael Stapelberg nor the +# names of contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# . +# THIS SOFTWARE IS PROVIDED BY Michael Stapelberg ''AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL Michael Stapelberg BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=head1 NAME + +deb-systemd-invoke - wrapper around systemctl, respecting policy-rc.d + +=head1 SYNOPSIS + +B<deb-systemd-invoke> start|stop|restart S<I<unit file> ...> + +=head1 DESCRIPTION + +B<deb-systemd-invoke> is a Debian-specific helper script which asks +/usr/sbin/policy-rc.d before performing a systemctl call. + +The "enable" action will only be performed once (when first installing the +package). On the first "enable", an state file is created which will be deleted +upon "disable", but only when _DEB_SYSTEMD_HELPER_PURGE=1 to distinguish purge +from remove. + +B<deb-systemd-invoke> is intended to be used from maintscripts to start +systemd unit files. It is specifically NOT intended to be used interactively by +users. Instead, users should run systemd and use systemctl, or not bother about +the systemd enabled state in case they are not running systemd. + +=cut + +use strict; +use warnings; + +if (@ARGV < 2) { + print STDERR "Syntax: $0 <action> <unit file> [<unit file> ...]\n"; + exit 1; +} + +my $policyhelper = '/usr/sbin/policy-rc.d'; +my @units = @ARGV; +my $action = shift @units; +if (-x $policyhelper) { + for my $unit (@units) { + system(qq|$policyhelper $unit "$action"|); + + # 104 means run + # 101 means do not run + my $exitcode = ($? >> 8); + if ($exitcode == 101) { + print STDERR "$policyhelper returned 101, not running '" . join(' ', @ARGV) . "'\n"; + exit 0; + } elsif ($exitcode != 104) { + print STDERR "deb-systemd-invoke only supports $policyhelper return code 101 and 104!\n"; + print STDERR "Got return code $exitcode, ignoring.\n"; + } + } +} + +exec '/bin/systemctl', @ARGV; |