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
diff --git a/bin/automatic-setup.sh b/bin/automatic-setup.sh
index 5c86bb2..871429b 100755
--- a/bin/automatic-setup.sh
+++ b/bin/automatic-setup.sh
@@ -16,6 +16,13 @@
1616
17set -x17set -x
1818
19# Wait for the snap to be successfully setup. This will only be true
20# when the snap is started the first time and the configure hook was
21# never called before.
22while [ ! -e $SNAP_COMMON/.setup_done ]; do
23 sleep 0.5
24done
25
19[ -f "$SNAP_COMMON/.block_auto_wizard" ] && exit 026[ -f "$SNAP_COMMON/.block_auto_wizard" ] && exit 0
2027
21[ -f "$SNAP_DATA/config" ] && exit 028[ -f "$SNAP_DATA/config" ] && exit 0
diff --git a/cmd/service/main.go b/cmd/service/main.go
index ae5e679..94084d8 100644
--- a/cmd/service/main.go
+++ b/cmd/service/main.go
@@ -19,11 +19,26 @@ import (
19 "os"19 "os"
20 "os/signal"20 "os/signal"
21 "syscall"21 "syscall"
22 "time"
22)23)
2324
25const snapSetupDoneFilePath = "/var/snap/wifi-ap/common/.setup_done"
26
24func main() {27func main() {
25 s := &service{}28 s := &service{}
2629
30 // Wait until the configure hook, which is called on snap
31 // installation, marked us as successfully setup. If we
32 // continue before that happen we will miss any initial
33 // configuration set via a gadget snap.
34 for {
35 _, err := os.Stat(snapSetupDoneFilePath)
36 if err == nil {
37 break
38 }
39 time.Sleep(time.Second/2)
40 }
41
27 c := make(chan os.Signal, 1)42 c := make(chan os.Signal, 1)
28 signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)43 signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
29 go func(s *service) {44 go func(s *service) {
diff --git a/hooks/configure b/hooks/configure
index dd0482a..6b984cd 100755
--- a/hooks/configure
+++ b/hooks/configure
@@ -38,3 +38,10 @@ else
38 # If no value provided set up our default38 # If no value provided set up our default
39 snapctl set automatic-setup.disable=false39 snapctl set automatic-setup.disable=false
40fi40fi
41
42# If we haven't marked ourself as setup yet after the snap was installed
43# we do this now so that the already started management service can
44# continue doing its job.
45if [ ! -e $SNAP_COMMON/.setup_done ]; then
46 touch $SNAP_COMMON/.setup_done
47fi
diff --git a/tests/main/conf-wizard-disabled-from-gadget/task.yaml b/tests/main/conf-wizard-disabled-from-gadget/task.yaml
index 8907db3..227ecfb 100644
--- a/tests/main/conf-wizard-disabled-from-gadget/task.yaml
+++ b/tests/main/conf-wizard-disabled-from-gadget/task.yaml
@@ -32,6 +32,7 @@ execute: |
32 /snap/bin/se-test-tools.unsquashfs -d gadget ${gadget_name}_*.snap32 /snap/bin/se-test-tools.unsquashfs -d gadget ${gadget_name}_*.snap
33 cat << EOF >> gadget/meta/gadget.yaml33 cat << EOF >> gadget/meta/gadget.yaml
34 defaults:34 defaults:
35 # Below snap ID matches the one assigned for wifi-ap in the Ubuntu Store
35 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS:36 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS:
36 automatic-setup.disable: true37 automatic-setup.disable: true
37 EOF38 EOF
@@ -43,4 +44,8 @@ execute: |
43 # unasserted snap to be configured with defaults from the gadget.44 # unasserted snap to be configured with defaults from the gadget.
44 snap install --edge wifi-ap45 snap install --edge wifi-ap
4546
46 test "$(snap get wifi-ap automatic-setup.disable)" = "true"47 test "$(snap get wifi-ap automatic-setup.disable)" = true
48 test "$(/snap/bin/wifi-ap.config get disabled)" = true
49 /snap/bin/wifi-ap.status | grep "ap.active: false"
50 ! pgrep dnsmasq
51 ! pgrep hostapd

Subscribers

People subscribed via source and target branches

to all changes: