github.com/anonymouse64/snapd@v0.0.0-20210824153203-04c4c42d842d/packaging/ubuntu-14.04/snapd.prerm (about) 1 #! /bin/sh 2 3 set -e 4 5 systemctl_stop() { 6 unit="$1" 7 8 echo "Stopping unit $unit" 9 systemctl stop -q "$unit" || true 10 11 for i in $(seq 20); do 12 echo "Waiting until unit $unit is stopped [attempt $i]" 13 if ! systemctl is-active -q "$unit"; then 14 echo "$unit is stopped." 15 return 16 fi 17 sleep .1 18 done 19 } 20 21 if [ -d /run/systemd/system ]; then 22 23 if [ "$1" = "remove" ]; then 24 units=$(systemctl list-unit-files --full | grep '^snap\.' | cut -f1 -d ' ' | grep -vF snap.mount.service || true) 25 tostop=$(echo "$units" | grep -E '^snap\..*\.(service|timer|socket)$' || true) 26 27 for unit in $tostop; do 28 # ensure it's really a snap mount unit or systemd unit 29 if ! grep -q 'X-Snappy=yes' "/etc/systemd/system/$unit"; then 30 echo "Skipping non-snapd systemd unit $unit" 31 continue 32 fi 33 34 echo "Stopping $unit" 35 systemctl_stop "$unit" 36 done 37 fi 38 39 systemctl stop snapd.autoimport.service snapd.socket snapd.service 40 systemctl disable snapd.autoimport.service snapd.socket snapd.service 41 fi