Merge ~morphis/snappy-hwe-snaps/+git/wifi-ap:feature/wait-for-snap-setup into ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master

Proposed by Simon Fels
Status: Merged
Approved by: Matteo Croce
Approved revision: e577ecf5589141ae3fdcfec9ce9515d96955876c
Merged at revision: 3334d49fa005b243e544b8448585746462b57e94
Proposed branch: ~morphis/snappy-hwe-snaps/+git/wifi-ap:feature/wait-for-snap-setup
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master
Diff against target: 86 lines (+35/-1)
4 files modified
bin/automatic-setup.sh (+7/-0)
cmd/service/main.go (+15/-0)
hooks/configure (+7/-0)
tests/main/conf-wizard-disabled-from-gadget/task.yaml (+6/-1)
Reviewer Review Type Date Requested Status
Matteo Croce (community) Approve
System Enablement Bot continuous-integration Approve
Review via email: mp+316544@code.launchpad.net

Description of the change

Wait for initial snap setup to be done before starting service

In the case that the gadget snap provides configuration items for us those are set after our services are already started which leads to the problem that we don't respect any preset configuration options on first startup.

This fixes the problem by telling our services to wait for a file $SNAP_COMMON/.setup_done to be present.

To post a comment you must log in.
Revision history for this message
Matteo Croce (teknoraver) :
review: Needs Fixing
Revision history for this message
Matteo Croce (teknoraver) :
review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Matteo Croce (teknoraver) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/automatic-setup.sh b/bin/automatic-setup.sh
2index 5c86bb2..871429b 100755
3--- a/bin/automatic-setup.sh
4+++ b/bin/automatic-setup.sh
5@@ -16,6 +16,13 @@
6
7 set -x
8
9+# Wait for the snap to be successfully setup. This will only be true
10+# when the snap is started the first time and the configure hook was
11+# never called before.
12+while [ ! -e $SNAP_COMMON/.setup_done ]; do
13+ sleep 0.5
14+done
15+
16 [ -f "$SNAP_COMMON/.block_auto_wizard" ] && exit 0
17
18 [ -f "$SNAP_DATA/config" ] && exit 0
19diff --git a/cmd/service/main.go b/cmd/service/main.go
20index ae5e679..94084d8 100644
21--- a/cmd/service/main.go
22+++ b/cmd/service/main.go
23@@ -19,11 +19,26 @@ import (
24 "os"
25 "os/signal"
26 "syscall"
27+ "time"
28 )
29
30+const snapSetupDoneFilePath = "/var/snap/wifi-ap/common/.setup_done"
31+
32 func main() {
33 s := &service{}
34
35+ // Wait until the configure hook, which is called on snap
36+ // installation, marked us as successfully setup. If we
37+ // continue before that happen we will miss any initial
38+ // configuration set via a gadget snap.
39+ for {
40+ _, err := os.Stat(snapSetupDoneFilePath)
41+ if err == nil {
42+ break
43+ }
44+ time.Sleep(time.Second/2)
45+ }
46+
47 c := make(chan os.Signal, 1)
48 signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
49 go func(s *service) {
50diff --git a/hooks/configure b/hooks/configure
51index dd0482a..6b984cd 100755
52--- a/hooks/configure
53+++ b/hooks/configure
54@@ -38,3 +38,10 @@ else
55 # If no value provided set up our default
56 snapctl set automatic-setup.disable=false
57 fi
58+
59+# If we haven't marked ourself as setup yet after the snap was installed
60+# we do this now so that the already started management service can
61+# continue doing its job.
62+if [ ! -e $SNAP_COMMON/.setup_done ]; then
63+ touch $SNAP_COMMON/.setup_done
64+fi
65diff --git a/tests/main/conf-wizard-disabled-from-gadget/task.yaml b/tests/main/conf-wizard-disabled-from-gadget/task.yaml
66index 8907db3..227ecfb 100644
67--- a/tests/main/conf-wizard-disabled-from-gadget/task.yaml
68+++ b/tests/main/conf-wizard-disabled-from-gadget/task.yaml
69@@ -32,6 +32,7 @@ execute: |
70 /snap/bin/se-test-tools.unsquashfs -d gadget ${gadget_name}_*.snap
71 cat << EOF >> gadget/meta/gadget.yaml
72 defaults:
73+ # Below snap ID matches the one assigned for wifi-ap in the Ubuntu Store
74 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS:
75 automatic-setup.disable: true
76 EOF
77@@ -43,4 +44,8 @@ execute: |
78 # unasserted snap to be configured with defaults from the gadget.
79 snap install --edge wifi-ap
80
81- test "$(snap get wifi-ap automatic-setup.disable)" = "true"
82+ test "$(snap get wifi-ap automatic-setup.disable)" = true
83+ test "$(/snap/bin/wifi-ap.config get disabled)" = true
84+ /snap/bin/wifi-ap.status | grep "ap.active: false"
85+ ! pgrep dnsmasq
86+ ! pgrep hostapd

Subscribers

People subscribed via source and target branches

to all changes: