aboutsummaryrefslogtreecommitdiffstats
path: root/packaging/deb/meshbay-node/DEBIAN/postinst
blob: f78cf6c0f0609b58b80974c5de5ded5c24d5817b (plain) (blame)
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
#!/bin/sh
set -e

# The node runs as a user service, in every signed-in user's own systemd
# manager: the system-wide reload does not reach those, and each would keep
# the old unit and the old code until restarted by hand. Every running user
# manager reloads, and restarts the node where it was running.
reload_user_managers() {
    for bus in /run/user/*/systemd/private; do
        [ -S "$bus" ] || continue
        uid=$(basename "$(dirname "$(dirname "$bus")")")
        user=$(id -nu "$uid" 2>/dev/null) || continue
        systemctl --user -M "$user@" daemon-reload 2>/dev/null || true
        [ -n "$1" ] && systemctl --user -M "$user@" try-restart meshbay-node.service 2>/dev/null || true
    done
}

case "$1" in
    configure)
        if [ -d /run/systemd/system ]; then
            systemctl daemon-reload || true
            # $2 is the version replaced: on an upgrade, a running node
            # restarts onto the new code.
            if [ -n "$2" ]; then
                systemctl try-restart 'meshbay-node@*.service' 2>/dev/null || true
            fi
            reload_user_managers "$2"
        fi
        ;;
esac

#DEBHELPER#