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
|
summary: "Check that stop-modes works"
details: |
Check that a snap service can configure which signal it receives when it's
stopped and that it's stopped when it's re-installed or removed.
# takes >1.5min to run
backends: [-autopkgtest]
# journald in ubuntu-14.04 not reliable
systems: [-ubuntu-14.04-*]
kill-timeout: 10m
restore: |
# remove to ensure all services are stopped
snap remove --purge test-snapd-service || true
debug: |
stop_modes="sighup sighup-all sigusr1 sigusr1-all sigusr2 sigusr2-all sigint sigint-all"
for s in $stop_modes; do
systemctl status "snap.test-snapd-service.test-snapd-${s}-service" || true
done
execute: |
echo "When the service snap is installed"
"$TESTSTOOLS"/snaps-state install-local test-snapd-service
# Because we cannot use daemon: notify easily yet just wait for a "ready"
# file to show up. The file is removed when the service is stopped. This
# pattern repeats around the test without additional comments.
retry -n 20 --wait 1 sh -c 'test -f /var/snap/test-snapd-service/common/ready'
echo "We can see it running"
systemctl status snap.test-snapd-service.test-snapd-service|MATCH "running"
systemctl show -p MainPID snap.test-snapd-service.test-snapd-service > old-main.pid
stop_modes="sighup sighup-all sigusr1 sigusr1-all sigusr2 sigusr2-all sigint sigint-all"
for s in $stop_modes; do
systemctl show -p ActiveState "snap.test-snapd-service.test-snapd-${s}-service" | MATCH "ActiveState=active"
done
echo "When it is re-installed"
"$TESTSTOOLS"/snaps-state install-local test-snapd-service
retry -n 20 --wait 1 sh -c 'test -f /var/snap/test-snapd-service/common/ready'
# note that sigterm{,-all} is tested separately
for s in $stop_modes; do
echo "We can see it is running"
systemctl show -p ActiveState "snap.test-snapd-service.test-snapd-${s}-service" | MATCH "ActiveState=active"
echo "and it got the right signal"
echo "checking that the right signal was sent"
test -f "/var/snap/test-snapd-service/common/${s}-${s%%-all}"
done
echo "Regular services are restarted normally"
"$TESTSTOOLS"/journal-state get-log -u snap.test-snapd-service.test-snapd-service | MATCH "stop service"
systemctl show -p MainPID snap.test-snapd-service.test-snapd-service > new-main.pid
test -e new-main.pid && test -e old-main.pid
test "$(cat new-main.pid)" != "$(cat old-main.pid)"
echo "Once the snap is removed, all services are stopped"
snap remove --purge test-snapd-service
for s in $stop_modes; do
"$TESTSTOOLS"/journal-state get-log | MATCH "stop ${s}"
done
rm -f /var/snap/test-snapd-service/common/*
|