summaryrefslogtreecommitdiff
path: root/src/rpm/systemd-update-helper.in
blob: f3c75b75fa7f9e7dfa82caea5f2bf687ad6feabe (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
#!/bin/bash
set -eu
set -o pipefail

command="${1:?}"
shift

command -v systemctl >/dev/null || exit 0

case "$command" in
    install-system-units)
        systemctl --no-reload preset "$@"
        ;;

    install-user-units)
        systemctl --no-reload preset --global "$@"
        ;;

    remove-system-units)
        if [ -d /run/systemd/system ]; then
            systemctl --no-reload disable --now "$@"
        else
            systemctl --no-reload disable "$@"
        fi
        ;;

    remove-user-units)
        systemctl --global disable "$@"
        ;;

    mark-restart-system-units)
        [ -d /run/systemd/system ] || exit 0

        for unit in "$@"; do
            systemctl set-property "$unit" Markers=+needs-restart &
        done
        wait
        ;;

    system-reload-restart|system-reload|system-restart)
        if [ -n "$*" ]; then
            echo "Unexpected arguments for '$command': $*"
            exit 2
        fi

        [ -d /run/systemd/system ] || exit 0

        if [[ "$command" =~ reload ]]; then
            systemctl daemon-reload
        fi

        if [[ "$command" =~ restart ]]; then
            systemctl reload-or-restart --marked
        fi
        ;;

    *)
        echo "Unknown verb '$command'"
        exit 3
        ;;
esac