2011-10-10 11:50:26 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2011-11-10 11:16:04 +01:00
|
|
|
# Enable and disable systemd services. The systemd_services environmental
|
|
|
|
# variable is expected to be set as follows:
|
|
|
|
#
|
|
|
|
# SERVICE_NAME RESTART
|
|
|
|
# foo.service off
|
|
|
|
# blah.service on
|
|
|
|
#
|
|
|
|
# i.e systemd_services='foo.service off blah.service on'
|
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
|
|
|
|
[ -z "${systemd_services}" ] && exit 1
|
|
|
|
|
|
|
|
if [ -e sys/fs/cgroups/systemd ]; then
|
|
|
|
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.
|
|
|
|
# disable and stop the unit.
|
|
|
|
systemctl --no-reload disable ${_srv} >/dev/null 2>&1 || :
|
|
|
|
systemctl stop ${_srv} >/dev/null 2>&1 || :
|
2011-10-10 11:50:26 +02:00
|
|
|
fi
|
2011-11-10 11:16:04 +01:00
|
|
|
elif [ "$TARGET" = "post-install" ]; then
|
|
|
|
if [ "$UPDATE" = "no" ]; then
|
|
|
|
# package is being installed.
|
|
|
|
# enable (but don't start) the unit by default.
|
|
|
|
systemctl enable ${_srv} >/dev/null 2>&1 || :
|
|
|
|
if [ "$systemd_booted" ]; then
|
|
|
|
# reload systemd if running.
|
|
|
|
systemctl daemon-reload >/dev/null 2>&1 || :
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# package is being updated.
|
|
|
|
if [ "$system_booted" ]; then
|
|
|
|
# reload systemd if running.
|
|
|
|
systemctl daemon-reload >/dev/null 2>&1 || :
|
|
|
|
fi
|
|
|
|
if [ -n "$restart" ]; then
|
|
|
|
# try restarting package service.
|
|
|
|
systemctl try-restart ${_srv} >/dev/null 2>&1 || :
|
|
|
|
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
|
2011-10-10 11:50:26 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|