2011-10-10 11:50:26 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2012-10-05 18:14:54 +02:00
|
|
|
# systemd trigger to enable/disable services, create/remove files via
|
|
|
|
# systemd-tmpfiles(5) and load/unload modules via modules-load.d(5).
|
2011-11-10 11:16:04 +01:00
|
|
|
#
|
2012-10-05 18:14:54 +02:00
|
|
|
# The following env vars are recognized:
|
|
|
|
# - systemd_services (expects at least two arguments: service name
|
|
|
|
# and a boolean to restart automatically the service on upgrade).
|
|
|
|
# - systemd_tmpfiles (expects a black separated list of fileanmes).
|
|
|
|
# - systemd_modules (expects a blank separated list of filenames).
|
2011-11-10 11:16:04 +01:00
|
|
|
#
|
2012-10-05 18:14:54 +02:00
|
|
|
# Examples:
|
|
|
|
|
|
|
|
# systemd_services="foo.service off blah.service on"
|
|
|
|
# systemd_tmpfiles="foo.conf blah.conf"
|
|
|
|
# systemd_modules="foo.conf blah.conf"
|
2011-10-10 11:50:26 +02:00
|
|
|
#
|
|
|
|
# Arguments: $ACTION = [run/targets]
|
|
|
|
# $TARGET = [post-install/pre-remove]
|
|
|
|
# $PKGNAME
|
|
|
|
# $VERSION
|
|
|
|
# $UPDATE = [yes/no]
|
|
|
|
#
|
|
|
|
ACTION="$1"
|
|
|
|
TARGET="$2"
|
|
|
|
PKGNAME="$3"
|
|
|
|
VERSION="$4"
|
|
|
|
UPDATE="$5"
|
|
|
|
|
|
|
|
export PATH="$PATH:/usr/local/bin"
|
|
|
|
|
|
|
|
case "$ACTION" in
|
|
|
|
targets)
|
|
|
|
echo "post-install pre-remove"
|
|
|
|
;;
|
|
|
|
run)
|
|
|
|
[ ! -x bin/systemctl ] && exit 0
|
2012-10-05 18:14:54 +02:00
|
|
|
[ -z "$systemd_services" -a -z "$systemd_tmpfiles" -a -z "$systemd_modules" ] && exit 1
|
2011-10-10 11:50:26 +02:00
|
|
|
|
2012-01-26 19:49:36 +01:00
|
|
|
systemd-notify --booted
|
|
|
|
if [ $? -eq 0 ]; then
|
2011-10-10 11:50:26 +02:00
|
|
|
systemd_booted=yes
|
|
|
|
fi
|
|
|
|
|
2011-11-10 13:24:50 +01:00
|
|
|
set -- ${systemd_services}
|
2011-11-10 11:16:04 +01:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
_srv="$1"
|
|
|
|
case "$2" in
|
|
|
|
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
|
|
|
|
restart=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
unset restart
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ "$TARGET" = "pre-remove" ]; then
|
|
|
|
if [ "$UPDATE" = "no" ]; then
|
|
|
|
# package is being removed.
|
2012-03-09 11:47:56 +01:00
|
|
|
# stop and disable the unit.
|
2012-01-26 19:49:36 +01:00
|
|
|
echo "Stopping systemd service ${_srv}..."
|
2013-02-25 23:20:53 +01:00
|
|
|
systemctl stop ${_srv} >/dev/null 2>&1 || :
|
2012-03-09 11:47:56 +01:00
|
|
|
echo "Disabling systemd service ${_srv}..."
|
2013-02-25 23:20:53 +01:00
|
|
|
systemctl --no-reload disable ${_srv} >/dev/null 2>&1 || :
|
2012-05-27 20:03:12 +02:00
|
|
|
else
|
|
|
|
# Package update, just disable the unit.
|
|
|
|
echo "Disabling systemd service ${_srv}..."
|
2013-02-25 23:20:53 +01:00
|
|
|
systemctl --no-reload disable ${_srv} >/dev/null 2>&1 || :
|
2012-10-05 18:14:54 +02:00
|
|
|
|
2011-10-10 11:50:26 +02:00
|
|
|
fi
|
2012-10-05 18:14:54 +02:00
|
|
|
else
|
2011-11-10 11:16:04 +01:00
|
|
|
if [ "$UPDATE" = "no" ]; then
|
|
|
|
# package is being installed.
|
|
|
|
# enable (but don't start) the unit by default.
|
2012-01-26 19:49:36 +01:00
|
|
|
echo "Enabling systemd service ${_srv}..."
|
2013-02-25 23:20:53 +01:00
|
|
|
systemctl enable ${_srv} >/dev/null 2>&1 || :
|
2012-01-26 19:49:36 +01:00
|
|
|
if [ -n "$systemd_booted" ]; then
|
2011-11-10 11:16:04 +01:00
|
|
|
# reload systemd if running.
|
2013-02-25 23:20:53 +01:00
|
|
|
systemctl daemon-reload >/dev/null 2>&1 || :
|
2011-11-10 11:16:04 +01:00
|
|
|
fi
|
2012-01-26 19:49:36 +01:00
|
|
|
cat <<_EOF
|
|
|
|
==========================================================================
|
|
|
|
|
|
|
|
The service "${_srv}" has been enabled by default,
|
|
|
|
that means that it will be started in next boot. To start it immediately,
|
|
|
|
execute the following command (as root):
|
|
|
|
|
|
|
|
$ systemctl start ${_srv}
|
|
|
|
|
|
|
|
And to stop it:
|
|
|
|
|
|
|
|
$ systemctl stop ${_srv}
|
|
|
|
|
|
|
|
Refer to the systemd documentation if more information is required.
|
|
|
|
|
|
|
|
==========================================================================
|
|
|
|
_EOF
|
2011-11-10 11:16:04 +01:00
|
|
|
else
|
2012-06-02 13:00:53 +02:00
|
|
|
# Enable the unit in case it wasn't added.
|
2013-02-25 23:20:53 +01:00
|
|
|
systemctl enable ${_srv} >/dev/null 2>&1 || :
|
2012-06-02 13:00:53 +02:00
|
|
|
|
2011-11-10 11:16:04 +01:00
|
|
|
# package is being updated.
|
2012-01-26 19:49:36 +01:00
|
|
|
if [ -n "$system_booted" ]; then
|
2011-11-10 11:16:04 +01:00
|
|
|
# reload systemd if running.
|
2013-02-25 23:20:53 +01:00
|
|
|
systemctl daemon-reload >/dev/null 2>&1 || :
|
2011-11-10 11:16:04 +01:00
|
|
|
fi
|
|
|
|
if [ -n "$restart" ]; then
|
|
|
|
# try restarting package service.
|
2013-02-25 23:20:53 +01:00
|
|
|
systemctl try-restart ${_srv} >/dev/null 2>&1 || :
|
2011-11-10 11:16:04 +01:00
|
|
|
else
|
|
|
|
echo "systemd ${_srv} service must be restarted manually!"
|
|
|
|
fi
|
2011-10-10 11:50:26 +02:00
|
|
|
fi
|
|
|
|
fi
|
2011-11-10 11:16:04 +01:00
|
|
|
shift; shift
|
|
|
|
done
|
2012-10-05 18:14:54 +02:00
|
|
|
if [ "$TARGET" = "pre-remove" ]; then
|
|
|
|
# Unload the modules specified in systemd_modules files.
|
|
|
|
for f in ${systemd_modules}; do
|
|
|
|
for j in $(cat usr/lib/modules-load.d/${f}); do
|
|
|
|
modprobe -rq ${j} || :
|
|
|
|
done
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# Create stuff specified in systemd_tmpfiles files.
|
|
|
|
for f in ${systemd_tmpfiles}; do
|
2012-10-06 11:51:32 +02:00
|
|
|
if [ "$PKGNAME" = "systemd" -a "$f" = "systemd.conf" ]; then
|
|
|
|
# This file is only meant to be run at boot-time.
|
|
|
|
continue
|
|
|
|
fi
|
2012-10-05 18:14:54 +02:00
|
|
|
systemd-tmpfiles --create ${f} || :
|
|
|
|
done
|
|
|
|
# Load modules specified in systemd_modules files.
|
|
|
|
for f in ${systemd_modules}; do
|
2013-09-13 08:31:01 +02:00
|
|
|
[ ! -f "usr/lib/modules-load.d/${f}" ] && continue
|
|
|
|
for j in "$(cat usr/lib/modules-load.d/${f})"; do
|
2012-10-05 18:14:54 +02:00
|
|
|
modprobe -q ${j} || :
|
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
2011-10-10 11:50:26 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|