eval "$(systemctl -p UnitFileState show "$systemd_unit")"
case "$UnitFileState" in
disabled)
- systemctl enable "$systemd_unit"
- # Failing to start the service is not a package error,
- # so don't let an error here propagate up.
+ # Failing to enable or start the service is not a
+ # package error, so don't let errors here
+ # propagate up.
+ systemctl enable "$systemd_unit" || true
systemctl start "$systemd_unit" || true
;;
enabled)
+ systemctl daemon-reload || true
systemctl reload-or-try-restart "$systemd_unit" || true
;;
esac
--- /dev/null
+#!/bin/sh
+
+set -e
+
+# NOTE: This package name detection will only work on Debian.
+# If this prerm script ever starts doing work on Red Hat,
+# we'll need to adapt this code accordingly.
+script="$(basename "$0")"
+pkg="${script%.prerm}"
+systemd_unit="${pkg}.service"
+
+case "${1}" in
+ remove)
+ if [ -e /run/systemd/system ]; then
+ systemctl stop "$systemd_unit" || true
+ systemctl disable "$systemd_unit" || true
+ fi
+ ;;
+esac
declare -a switches=()
systemd_unit="$WORKSPACE/${src_path}/${prog}.service"
if [[ -e "${systemd_unit}" ]]; then
- switches+=("${systemd_unit}=/lib/systemd/system/${prog}.service")
- switches+=(--after-install "$WORKSPACE/build/go-package-scripts/postinst")
+ switches+=(
+ --after-install "$WORKSPACE/build/go-package-scripts/postinst"
+ --before-remove "$WORKSPACE/build/go-package-scripts/prerm"
+ "${systemd_unit}=/lib/systemd/system/${prog}.service")
fi
switches+=("$WORKSPACE/$license_file=/usr/share/doc/$prog/$license_file")