[ARVADOS] created: 94f1d094bde1781481f13d6ad052f7748f880cb8
Git user
git at public.curoverse.com
Wed Aug 10 13:22:07 EDT 2016
at 94f1d094bde1781481f13d6ad052f7748f880cb8 (commit)
commit 94f1d094bde1781481f13d6ad052f7748f880cb8
Author: Brett Smith <brett at curoverse.com>
Date: Wed Aug 10 13:22:02 2016 -0400
9706: Go service postinst improvements.
* Use /bin/sh, per Debian policy.
* Prefer basename for readability.
* Check for systemd init with [ -e /run/systemd/system ].
* Make configuration changes based on checking the unit file state.
diff --git a/build/go-package-scripts/postinst b/build/go-package-scripts/postinst
index 137f898..3adb0fc 100755
--- a/build/go-package-scripts/postinst
+++ b/build/go-package-scripts/postinst
@@ -1,15 +1,29 @@
-#!/bin/bash
+#!/bin/sh
set -e
-script="${0##*/}"
+# NOTE: This package name detection will only work on Debian.
+# If this postinst script ever starts doing work on Red Hat,
+# we'll need to adapt this code accordingly.
+script="$(basename "$0")"
pkg="${script%.postinst}"
+systemd_unit="${pkg}.service"
case "${1}" in
configure)
- if which systemctl >/dev/null && [[ -e "/lib/systemd/system/${pkg}.service" ]]; then
- systemctl enable "${pkg}"
- systemctl start "${pkg}"
+ if [ -e /run/systemd/system ]; then
+ 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.
+ systemctl start "$systemd_unit" || true
+ ;;
+ enabled)
+ systemctl reload-or-try-restart "$systemd_unit" || true
+ ;;
+ esac
fi
;;
esac
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list