aboutsummaryrefslogtreecommitdiff
path: root/debian/libpam0g.postinst
diff options
context:
space:
mode:
authorSam Hartman <hartmans@debian.org>2021-02-24 13:27:05 -0500
committerSteve Langasek <steve.langasek@canonical.com>2021-09-15 17:52:36 -0700
commit952595e2b7cbcb2c7964c4c60c5d4a8fc5f56046 (patch)
treec656488832c93eab030ef16d1ff09719fa886fd2 /debian/libpam0g.postinst
parenteade3115c8869136ed5a8579a6c8797b4b822796 (diff)
downloadpam-952595e2b7cbcb2c7964c4c60c5d4a8fc5f56046.tar.gz
pam-952595e2b7cbcb2c7964c4c60c5d4a8fc5f56046.tar.bz2
pam-952595e2b7cbcb2c7964c4c60c5d4a8fc5f56046.zip
debian/libpam0g.postinst: Handle systemd units
Debian policy now considers init scripts optional. When booted with systemd, use systemd facilities for determining whether a service is enabled and restarting. We might want to try restarting services that are running even if disabled. I don't think we did that in the init script case, and I don't know a good way to determine which units should be restarted. * Update template description because the services are no longer considered init scripts on most systems. It wouldn't be worth the translation churn alone, but we have another template change in the same version. * Override lintian warning regarding calling systemctl. oops lintian
Diffstat (limited to 'debian/libpam0g.postinst')
-rw-r--r--debian/libpam0g.postinst54
1 files changed, 41 insertions, 13 deletions
diff --git a/debian/libpam0g.postinst b/debian/libpam0g.postinst
index 55928557..23320c8f 100644
--- a/debian/libpam0g.postinst
+++ b/debian/libpam0g.postinst
@@ -52,7 +52,44 @@ filerc() {
echo ""
}
-installed_services() {
+if test -d /run/systemd/system; then
+ is_service_configured() {
+ systemctl is-enabled --quiet $1 || return 1
+ }
+ restart_service() {
+ if systemctl try-restart $1; then
+ :
+ else
+ failed = "$failed $1"
+ fi
+ }
+else # not systemd
+ is_service_configured() {
+ idl="/etc/init.d/${service}"
+ if [ -n "$idl" ] && [ -x $idl ]; then
+return 0
+ else
+ return 1
+ fi
+ }
+
+ restart_service() {
+ service="$1"
+ idl="invoke-rc.d ${service}"
+ echo -n " $service: stopping..." 2>&1
+ $idl stop > /dev/null 2>&1 || true
+ sleep 1
+ echo -n "starting..." 2>&1
+ if $idl start > /dev/null 2>&1; then
+ echo "done." 2>&1
+ else
+ echo "FAILED! ($?)" 2>&1
+ failed="$service $failed"
+ fi
+ }
+fi
+
+ installed_services() {
check="$@"
# Only get the ones that are installed, and configured
@@ -75,10 +112,10 @@ installed_services() {
for service in $check; do
idl="/etc/init.d/${service}"
- if [ -n "$idl" ] && [ -x $idl ]; then
+ if is_service_configured $service; then
services="$service $services"
else
- echo "WARNING: init script for $service not found." >&2
+ echo "WARNING: $service not configured." >&2
fi
done
echo "$services"
@@ -152,16 +189,7 @@ then
continue
;;
esac
- echo -n " $service: stopping..."
- $idl stop > /dev/null 2>&1 || true
- sleep 1
- echo -n "starting..."
- if $idl start > /dev/null 2>&1; then
- echo "done."
- else
- echo "FAILED! ($?)"
- failed="$service $failed"
- fi
+ restart_service "$service"
done
echo
if [ -n "$failed" ]; then