File: snapd.prerm

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (44 lines) | stat: -rwxr-xr-x 1,213 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

set -e

systemctl_stop() {
    unit="$1"

    echo "Stopping unit $unit"
    systemctl stop -q "$unit" || true

    for i in $(seq 20); do
        echo "Waiting until unit $unit is stopped [attempt $i]"
        if ! systemctl is-active -q "$unit"; then
            echo "$unit is stopped."
            break
        fi
        sleep .1
    done

    if echo "$unit" | grep -q '.*\.service' ; then
        # snap services can request KillMode=process, which would result in only
        # the main process getting stopped, however during purge we are doing a
        # full cleanup
        systemctl kill -q "$unit" || true
    fi
}

if [ "$1" = "remove" ]; then
    units=$(systemctl list-unit-files --full | grep '^snap\.' | cut -f1 -d ' ' | grep -vF snap.mount.service || true)
    tostop=$(echo "$units" | grep -E '^snap\..*\.(service|timer|socket)$' || true)

    for unit in $tostop; do
        # ensure it's really a snap mount unit or systemd unit
        if  ! grep -q 'X-Snappy=yes' "/etc/systemd/system/$unit"; then
            echo "Skipping non-snapd systemd unit $unit"
            continue
        fi

        echo "Stopping $unit"
        systemctl_stop "$unit"
    done
fi

#DEBHELPER#