summarylogtreecommitdiffstats
path: root/systemd-hook
diff options
context:
space:
mode:
Diffstat (limited to 'systemd-hook')
-rw-r--r--systemd-hook46
1 files changed, 46 insertions, 0 deletions
diff --git a/systemd-hook b/systemd-hook
new file mode 100644
index 000000000000..0a4754b21647
--- /dev/null
+++ b/systemd-hook
@@ -0,0 +1,46 @@
+#!/bin/sh -e
+
+is_chrooted() {
+ if systemd-detect-virt --chroot; then
+ echo >&2 " Skipped: Running in chroot."
+ exit 0
+ fi
+}
+
+systemd_live() {
+ is_chrooted
+ if [ ! -d /run/systemd/system ]; then
+ echo >&2 " Skipped: Current root is not booted."
+ exit 0
+ fi
+}
+
+udevd_live() {
+ is_chrooted
+ if [ ! -d /run/udev ]; then
+ echo >&2 " Skipped: Device manager is not running."
+ exit 0
+ fi
+}
+
+op="$1"; shift
+
+case "$op" in
+ catalog) /usr/bin/journalctl --update-catalog ;;
+ hwdb) /usr/bin/systemd-hwdb --usr update ;;
+ update) touch -c /usr ;;
+ sysusers) /usr/bin/systemd-sysusers ;;
+ tmpfiles) /usr/bin/systemd-tmpfiles --create ;;
+
+ daemon-reload) systemd_live; /usr/bin/systemctl daemon-reload ;;
+ udev-reload) udevd_live; /usr/bin/udevadm control --reload ;;
+ binfmt) systemd_live; /usr/lib/systemd/systemd-binfmt ;;
+ sysctl) systemd_live; /usr/lib/systemd/systemd-sysctl ;;
+
+ # For use by other packages
+ reload) systemd_live; /usr/bin/systemctl try-reload-or-restart "$@" ;;
+
+ *) echo >&2 " Invalid operation '$op'"; exit 1 ;;
+esac
+
+exit 0