summarylogtreecommitdiffstats
path: root/systemd-hook
blob: d64341fd3ca65cbad1cbd38ca31119f653dbc190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/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 [ ! -S /run/udev/control ]; then
    echo >&2 "  Skipped: Device manager is not running."
    exit 0
  fi
}

op="$1"; shift

case "$op" in
  binfmt)
    systemd_live
    /usr/lib/systemd/systemd-binfmt
    ;;
  catalog)
    /usr/bin/journalctl --update-catalog
    ;;
  daemon-reload-system)
    systemd_live
    /usr/bin/systemctl --system daemon-reload
    ;;
  daemon-reload-user)
    systemd_live
    /usr/bin/systemctl kill --kill-whom='main' --signal='SIGHUP' 'user@*.service'
    ;;
  hwdb)
    /usr/bin/systemd-hwdb --usr update
    ;;
  sysctl)
    systemd_live
    /usr/lib/systemd/systemd-sysctl
    ;;
  sysusers)
    /usr/bin/systemd-sysusers
    ;;
  tmpfiles)
    /usr/bin/systemd-tmpfiles --create
    ;;
  update)
    touch -c /usr
    ;;
  udev-reload)
    udevd_live
    /usr/bin/udevadm control --reload
    if [ ! -e /etc/systemd/do-not-udevadm-trigger-on-update ]; then
      /usr/bin/udevadm trigger -c change
      /usr/bin/udevadm settle
    fi
    ;;

  # 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