Merge lp:~chipaca/snappy/delayed-service-start into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by John Lenton on 2015-07-29
Status: Merged
Approved by: Sergio Schvezov on 2015-07-29
Approved revision: 618
Merged at revision: 618
Proposed branch: lp:~chipaca/snappy/delayed-service-start
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~chipaca/snappy/firstboot-networking-restart
Diff against target: 199 lines (+91/-1)
7 files modified
debian/golang-snappy-dev.install (+1/-0)
debian/rules (+9/-0)
debian/snappy-wait4network.service (+10/-0)
snappy/click.go (+1/-0)
snappy/click_test.go (+21/-0)
systemd/systemd.go (+4/-1)
systemd/systemd_test.go (+45/-0)
To merge this branch: bzr merge lp:~chipaca/snappy/delayed-service-start
Reviewer Review Type Date Requested Status
Sergio Schvezov 2015-07-29 Approve on 2015-07-29
Oliver Grawert Approve on 2015-07-29
Ricardo Salveti (community) Needs Information on 2015-07-29
Review via email: mp+266166@code.launchpad.net

Commit Message

This creates wait4network, which waits for network, and makes services that define an external port depend on that.

Description of the Change

This creates wait4network, which waits for network, and makes services that define an external port depend on that. Wouldn't be necessary if network-online.target were more sensible for our use.

To post a comment you must log in.
Ricardo Salveti (rsalveti) wrote :

Inline.

review: Needs Information
John Lenton (chipaca) :
616. By John Lenton on 2015-07-29

Merged firstboot-networking-restart into delayed-service-start.

Sergio Schvezov (sergiusens) wrote :

This MP makes me feel weary. Is this just for webdm? I might just take a stance and try to fix it there.

review: Needs Information
Oliver Grawert (ogra) wrote :

how about instead of "phoning home" you just check if a default route is set, that should serve the same purpose but will get us less people complain about privacy :)

617. By John Lenton on 2015-07-29

brilliantly, check for a default route instead of "the internet", as that is good enough for us.

Oliver Grawert (ogra) wrote :

shiny !!

review: Approve
618. By John Lenton on 2015-07-29

nuked the go wait4network altogether

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/golang-snappy-dev.install'
2--- debian/golang-snappy-dev.install 2015-03-18 19:26:18 +0000
3+++ debian/golang-snappy-dev.install 2015-07-29 18:50:43 +0000
4@@ -1,1 +1,2 @@
5+/usr/bin/xgettext-go
6 /usr/share/gocode
7
8=== modified file 'debian/rules'
9--- debian/rules 2015-07-01 07:48:19 +0000
10+++ debian/rules 2015-07-29 18:50:43 +0000
11@@ -4,6 +4,7 @@
12 #export DH_VERBOSE=1
13 export DH_OPTIONS
14 export DH_GOPKG := launchpad.net/snappy
15+#export DEB_BUILD_OPTIONS=nocheck
16
17 %:
18 dh $@ --buildsystem=golang --with=golang --fail-missing --with systemd
19@@ -30,6 +31,10 @@
20 --no-enable \
21 -pubuntu-snappy \
22 snappy-autopilot.service
23+ # enable wait4network
24+ dh_systemd_enable \
25+ -pubuntu-snappy \
26+ snappy-wait4network.service
27
28 override_dh_systemd_start:
29 # start boot-ok
30@@ -49,6 +54,10 @@
31 --no-start \
32 -pubuntu-snappy \
33 snappy-autopilot.service
34+ # start wait4network
35+ dh_systemd_start \
36+ -pubuntu-snappy \
37+ snappy-wait4network.service
38
39 override_dh_auto_build:
40 # this will update the i18n stuff
41
42=== added file 'debian/snappy-wait4network.service'
43--- debian/snappy-wait4network.service 1970-01-01 00:00:00 +0000
44+++ debian/snappy-wait4network.service 2015-07-29 18:50:43 +0000
45@@ -0,0 +1,10 @@
46+[Unit]
47+Description=Wait for network
48+After=network-online.target
49+
50+[Service]
51+Type=oneshot
52+RemainAfterExit=yes
53+TimeoutStartSec=0
54+ExecStart=/bin/sh -ec 'while [ -z "$( /sbin/ip route show 0/0 )" ]; do sleep 5; done'
55+
56
57=== modified file 'snappy/click.go'
58--- snappy/click.go 2015-07-23 11:05:37 +0000
59+++ snappy/click.go 2015-07-29 18:50:43 +0000
60@@ -444,6 +444,7 @@
61 StopTimeout: time.Duration(service.StopTimeout),
62 AaProfile: aaProfile,
63 IsFramework: m.Type == pkg.TypeFramework,
64+ IsNetworked: service.Ports != nil && len(service.Ports.External) > 0,
65 BusName: service.BusName,
66 UdevAppName: udevPartName,
67 }), nil
68
69=== modified file 'snappy/click_test.go'
70--- snappy/click_test.go 2015-07-23 11:05:37 +0000
71+++ snappy/click_test.go 2015-07-29 18:50:43 +0000
72@@ -1231,6 +1231,7 @@
73 WantedBy=multi-user.target
74 `
75 expectedServiceAppWrapper = fmt.Sprintf(expectedServiceWrapperFmt, "After=ubuntu-snappy.frameworks.target\nRequires=ubuntu-snappy.frameworks.target", ".canonical", "canonical", "\n", helpers.UbuntuArchitecture())
76+ expectedNetAppWrapper = fmt.Sprintf(expectedServiceWrapperFmt, "After=ubuntu-snappy.frameworks.target\nRequires=ubuntu-snappy.frameworks.target\nAfter=snappy-wait4network.service\nRequires=snappy-wait4network.service", ".canonical", "canonical", "\n", helpers.UbuntuArchitecture())
77 expectedServiceFmkWrapper = fmt.Sprintf(expectedServiceWrapperFmt, "Before=ubuntu-snappy.frameworks.target\nAfter=ubuntu-snappy.frameworks-pre.target\nRequires=ubuntu-snappy.frameworks-pre.target", "", "", "BusName=foo.bar.baz\nType=dbus", helpers.UbuntuArchitecture())
78 )
79
80@@ -1253,6 +1254,26 @@
81 c.Assert(generatedWrapper, Equals, expectedServiceAppWrapper)
82 }
83
84+func (s *SnapTestSuite) TestSnappyGenerateSnapServiceAppWrapperWithExternalPort(c *C) {
85+ service := ServiceYaml{
86+ Name: "xkcd-webserver",
87+ Start: "bin/foo start",
88+ Stop: "bin/foo stop",
89+ PostStop: "bin/foo post-stop",
90+ StopTimeout: DefaultTimeout,
91+ Description: "A fun webserver",
92+ Ports: &Ports{External: map[string]Port{"foo": Port{}}},
93+ }
94+ pkgPath := "/apps/xkcd-webserver.canonical/0.3.4/"
95+ aaProfile := "xkcd-webserver.canonical_xkcd-webserver_0.3.4"
96+ m := packageYaml{Name: "xkcd-webserver",
97+ Version: "0.3.4"}
98+
99+ generatedWrapper, err := generateSnapServicesFile(service, pkgPath, aaProfile, &m)
100+ c.Assert(err, IsNil)
101+ c.Assert(generatedWrapper, Equals, expectedNetAppWrapper)
102+}
103+
104 func (s *SnapTestSuite) TestSnappyGenerateSnapServiceFmkWrapper(c *C) {
105 service := ServiceYaml{
106 Name: "xkcd-webserver",
107
108=== modified file 'systemd/systemd.go'
109--- systemd/systemd.go 2015-07-23 13:15:56 +0000
110+++ systemd/systemd.go 2015-07-29 18:50:43 +0000
111@@ -84,6 +84,7 @@
112 StopTimeout time.Duration
113 AaProfile string
114 IsFramework bool
115+ IsNetworked bool
116 BusName string
117 UdevAppName string
118 }
119@@ -205,7 +206,9 @@
120 {{if .IsFramework}}Before=ubuntu-snappy.frameworks.target
121 After=ubuntu-snappy.frameworks-pre.target
122 Requires=ubuntu-snappy.frameworks-pre.target{{else}}After=ubuntu-snappy.frameworks.target
123-Requires=ubuntu-snappy.frameworks.target{{end}}
124+Requires=ubuntu-snappy.frameworks.target{{end}}{{if .IsNetworked}}
125+After=snappy-wait4network.service
126+Requires=snappy-wait4network.service{{end}}
127 X-Snappy=yes
128
129 [Service]
130
131=== modified file 'systemd/systemd_test.go'
132--- systemd/systemd_test.go 2015-07-23 13:15:56 +0000
133+++ systemd/systemd_test.go 2015-07-29 18:50:43 +0000
134@@ -181,6 +181,10 @@
135 expectedAppService = fmt.Sprintf(expectedServiceFmt, "After=ubuntu-snappy.frameworks.target\nRequires=ubuntu-snappy.frameworks.target", ".mvo", "mvo", "\n", helpers.UbuntuArchitecture())
136 expectedFmkService = fmt.Sprintf(expectedServiceFmt, "Before=ubuntu-snappy.frameworks.target\nAfter=ubuntu-snappy.frameworks-pre.target\nRequires=ubuntu-snappy.frameworks-pre.target", "", "", "\n", helpers.UbuntuArchitecture())
137 expectedDbusService = fmt.Sprintf(expectedServiceFmt, "After=ubuntu-snappy.frameworks.target\nRequires=ubuntu-snappy.frameworks.target", ".mvo", "mvo", "BusName=foo.bar.baz\nType=dbus", helpers.UbuntuArchitecture())
138+
139+ // things that need network
140+ expectedNetAppService = fmt.Sprintf(expectedServiceFmt, "After=ubuntu-snappy.frameworks.target\nRequires=ubuntu-snappy.frameworks.target\nAfter=snappy-wait4network.service\nRequires=snappy-wait4network.service", ".mvo", "mvo", "\n", helpers.UbuntuArchitecture())
141+ expectedNetFmkService = fmt.Sprintf(expectedServiceFmt, "Before=ubuntu-snappy.frameworks.target\nAfter=ubuntu-snappy.frameworks-pre.target\nRequires=ubuntu-snappy.frameworks-pre.target\nAfter=snappy-wait4network.service\nRequires=snappy-wait4network.service", "", "", "\n", helpers.UbuntuArchitecture())
142 )
143
144 func (s *SystemdTestSuite) TestGenAppServiceFile(c *C) {
145@@ -202,6 +206,26 @@
146 c.Check(New("", nil).GenServiceFile(desc), Equals, expectedAppService)
147 }
148
149+func (s *SystemdTestSuite) TestGenNetAppServiceFile(c *C) {
150+
151+ desc := &ServiceDescription{
152+ AppName: "app",
153+ ServiceName: "service",
154+ Version: "1.0",
155+ Description: "descr",
156+ AppPath: "/apps/app.mvo/1.0/",
157+ Start: "bin/start",
158+ Stop: "bin/stop",
159+ PostStop: "bin/stop --post",
160+ StopTimeout: time.Duration(10 * time.Second),
161+ AaProfile: "aa-profile",
162+ IsNetworked: true,
163+ UdevAppName: "app.mvo",
164+ }
165+
166+ c.Check(New("", nil).GenServiceFile(desc), Equals, expectedNetAppService)
167+}
168+
169 func (s *SystemdTestSuite) TestGenFmkServiceFile(c *C) {
170
171 desc := &ServiceDescription{
172@@ -222,6 +246,27 @@
173 c.Check(New("", nil).GenServiceFile(desc), Equals, expectedFmkService)
174 }
175
176+func (s *SystemdTestSuite) TestGenNetFmkServiceFile(c *C) {
177+
178+ desc := &ServiceDescription{
179+ AppName: "app",
180+ ServiceName: "service",
181+ Version: "1.0",
182+ Description: "descr",
183+ AppPath: "/apps/app/1.0/",
184+ Start: "bin/start",
185+ Stop: "bin/stop",
186+ PostStop: "bin/stop --post",
187+ StopTimeout: time.Duration(10 * time.Second),
188+ AaProfile: "aa-profile",
189+ IsNetworked: true,
190+ IsFramework: true,
191+ UdevAppName: "app",
192+ }
193+
194+ c.Check(New("", nil).GenServiceFile(desc), Equals, expectedNetFmkService)
195+}
196+
197 func (s *SystemdTestSuite) TestGenServiceFileWithBusName(c *C) {
198
199 desc := &ServiceDescription{

Subscribers

People subscribed via source and target branches