summaryrefslogtreecommitdiffstats
path: root/src/rpm/systemd-update-helper.in
blob: ab8cdc0ff96db92e08ddc6bc3d9617e69d305405 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
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 "$@"

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

        users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p')
        for user in $users; do
            SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
                    systemctl --user -M "$user@" disable --now "$@" &
        done
        wait
        ;;

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

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

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

        users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p')
        for user in $users; do
            for unit in "$@"; do
                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
                        systemctl --user -M "$user@" set-property "$unit" Markers=+needs-restart &
            done
        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
        ;;

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

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

        users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p')

        if [[ "$command" =~ reexec ]]; then
            for user in $users; do
                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
                        systemctl --user -M "$user@" daemon-reexec &
            done
            wait
        fi

        if [[ "$command" =~ reload ]]; then
            for user in $users; do
                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
                        systemctl --user -M "$user@" daemon-reload &
            done
            wait
        fi

        if [[ "$command" =~ restart ]]; then
            for user in $users; do
                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
                        systemctl --user -M "$user@" reload-or-restart --marked &
            done
            wait
        fi
        ;;

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