Merge lp:~mvo/snappy/snappy-systemctl-enable into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Michael Vogt
Status: Work in progress
Proposed branch: lp:~mvo/snappy/snappy-systemctl-enable
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 174 lines (+59/-6) (has conflicts)
3 files modified
snappy/click.go (+41/-1)
snappy/click_test.go (+15/-5)
snappy/snapp_test.go (+3/-0)
Text conflict in snappy/click.go
Text conflict in snappy/click_test.go
To merge this branch: bzr merge lp:~mvo/snappy/snappy-systemctl-enable
Reviewer Review Type Date Requested Status
Sergio Schvezov Needs Fixing
Review via email: mp+255967@code.launchpad.net

Description of the change

This branch sets a manual symlink to enable a systemd unit instead of using systemctl enable that may not be available on the system.

To post a comment you must log in.
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Please remerge trunk

review: Needs Fixing

Unmerged revisions

308. By Michael Vogt

manually set the symlink that systemctl enable sets to ensure that ubuntu-device-flash works on systems with no systemd

307. By Sergio Schvezov

Fixing tests:
- Check for len 0 for system hooks when inhibiting.
- Make it easier on editors that trim empty spaces.

306. By Sergio Schvezov

systemctl not to be called with inhibithooks

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy/click.go'
2--- snappy/click.go 2015-04-08 18:53:49 +0000
3+++ snappy/click.go 2015-04-13 14:30:45 +0000
4@@ -70,6 +70,9 @@
5 pattern string
6 }
7
8+// the default target for systemd units that we generate
9+const servicesSystemdTarget = "multi-user.target"
10+
11 const (
12 // from debsig-verify-0.9/debsigs.h
13 dsSuccess = 0
14@@ -421,13 +424,14 @@
15 {{if .StopTimeout}}TimeoutStopSec={{.StopTimeout}}{{end}}
16
17 [Install]
18-WantedBy=multi-user.target
19+WantedBy={{.ServicesSystemdTarget}}
20 `
21 var templateOut bytes.Buffer
22 t := template.Must(template.New("wrapper").Parse(serviceTemplate))
23 wrapperData := struct {
24 // embed service struct
25 Service
26+<<<<<<< TREE
27 // but we need more
28 Name string
29 Version string
30@@ -437,12 +441,22 @@
31 FullPathStop string
32 FullPathPostStop string
33 AppTriple string
34+=======
35+ AppPath string
36+ AaProfile string
37+ FullPathStart string
38+ FullPathStop string
39+ FullPathPostStop string
40+ AppTriple string
41+ ServicesSystemdTarget string
42+>>>>>>> MERGE-SOURCE
43 }{
44 service, m.Name, m.Version, baseDir, aaProfile,
45 filepath.Join(baseDir, service.Start),
46 filepath.Join(baseDir, service.Stop),
47 filepath.Join(baseDir, service.PostStop),
48 fmt.Sprintf("%s_%s_%s", m.Name, service.Name, m.Version),
49+ servicesSystemdTarget,
50 }
51 if err := t.Execute(&templateOut, wrapperData); err != nil {
52 // this can never happen, except we forget a variable
53@@ -467,6 +481,7 @@
54 return dir[len(globalRootDir):]
55 }
56
57+<<<<<<< TREE
58 func checkPackageForNameClashes(baseDir string) error {
59 m, err := parsePackageYamlFile(filepath.Join(baseDir, "meta", "package.yaml"))
60 if err != nil {
61@@ -477,6 +492,18 @@
62 }
63
64 func addPackageServices(baseDir string, inhibitHooks bool, inter interacter) error {
65+=======
66+// enable a service via manual symlink creation. Note that we can not
67+// use "systemctl enable" as this code needs to run via ubuntu-device-flash
68+// on a host that may not have systemd installed
69+func systemdEnable(serviceFilename string) error {
70+ enableTargetSymlink := filepath.Join(snapServicesDir, servicesSystemdTarget+".wants", filepath.Base(serviceFilename))
71+
72+ return os.Symlink(stripGlobalRootDir(serviceFilename), enableTargetSymlink)
73+}
74+
75+func addPackageServices(baseDir string, inhibitHooks bool) error {
76+>>>>>>> MERGE-SOURCE
77 m, err := parsePackageYamlFile(filepath.Join(baseDir, "meta", "package.yaml"))
78 if err != nil {
79 return err
80@@ -501,7 +528,13 @@
81 //
82 // *but* always run enable (which just sets a symlink)
83 serviceName := filepath.Base(generateServiceFileName(m, service))
84+
85+ if err := systemdEnable(serviceFilename); err != nil {
86+ return err
87+ }
88+
89 if !inhibitHooks {
90+<<<<<<< TREE
91 sysd := systemd.New(globalRootDir, inter)
92 if err := sysd.DaemonReload(); err != nil {
93 return err
94@@ -512,6 +545,13 @@
95 }
96
97 if err := sysd.Start(serviceName); err != nil {
98+=======
99+ if err := runSystemctl("daemon-reload"); err != nil {
100+ return err
101+ }
102+
103+ if err := runSystemctl("start", serviceName); err != nil {
104+>>>>>>> MERGE-SOURCE
105 return err
106 }
107 }
108
109=== modified file 'snappy/click_test.go'
110--- snappy/click_test.go 2015-04-08 18:53:49 +0000
111+++ snappy/click_test.go 2015-04-13 14:30:45 +0000
112@@ -452,10 +452,8 @@
113 // it go de-activated and finally 2.0 got activated
114 content, err := ioutil.ReadFile(filepath.Join(s.tempdir, "hook.trace"))
115 c.Assert(err, IsNil)
116- c.Assert(string(content), Equals, `now: ./bar_app_1.0.tracehook
117-now:
118-now: ./bar_app_2.0.tracehook
119-`)
120+ expected := fmt.Sprintf("now: ./bar_app_1.0.tracehook\nnow: \nnow: ./bar_app_2.0.tracehook\n")
121+ c.Assert(string(content), Equals, expected)
122 }
123
124 func (s *SnapTestSuite) TestClickCopyDataHookFails(c *C) {
125@@ -629,13 +627,21 @@
126 _, err := installClick(snapFile, AllowUnauthenticated, nil)
127 c.Assert(err, IsNil)
128
129- servicesFile := filepath.Join(snapServicesDir, "foo.mvo_service_1.0.service")
130+ // ensure that we have the services file
131+ serviceName := "foo.mvo_service_1.0.service"
132+ servicesFile := filepath.Join(snapServicesDir, serviceName)
133 c.Assert(helpers.FileExists(servicesFile), Equals, true)
134 st, err := os.Stat(servicesFile)
135 c.Assert(err, IsNil)
136 // should _not_ be executable
137 c.Assert(st.Mode().String(), Equals, "-rw-r--r--")
138
139+ // ensure that we have the wants symlink
140+ enabledSymlink := filepath.Join(snapServicesDir, servicesSystemdTarget+".wants", serviceName)
141+ target, err := os.Readlink(enabledSymlink)
142+ c.Assert(err, IsNil)
143+ c.Assert(target, Equals, stripGlobalRootDir(servicesFile))
144+
145 // and that it gets removed on remove
146 snapDir := filepath.Join(snapAppsDir, "foo.mvo", "1.0")
147 err = removeClick(snapDir, new(progress.NullProgress))
148@@ -662,8 +668,12 @@
149 _, err := installClick(snapFile, 0, nil)
150 c.Assert(err, IsNil)
151
152+<<<<<<< TREE
153 c.Assert(allSystemctl, HasLen, 3)
154 c.Assert(allSystemctl[1], DeepEquals, []string{"--root", globalRootDir, "enable", "foo.mvo_service_1.0.service"})
155+=======
156+ c.Assert(allSystemctl, HasLen, 0)
157+>>>>>>> MERGE-SOURCE
158 }
159
160 const expectedService = `[Unit]
161
162=== modified file 'snappy/snapp_test.go'
163--- snappy/snapp_test.go 2015-04-09 09:10:06 +0000
164+++ snappy/snapp_test.go 2015-04-13 14:30:45 +0000
165@@ -52,6 +52,9 @@
166 clickSystemHooksDir = filepath.Join(s.tempdir, "/usr/share/click/hooks")
167 os.MkdirAll(clickSystemHooksDir, 0755)
168
169+ // create a fake systemd environment
170+ os.MkdirAll(filepath.Join(snapServicesDir, servicesSystemdTarget+".wants"), 0755)
171+
172 // we may not have debsig-verify installed (and we don't need it
173 // for the unittests)
174 runDebsigVerify = func(snapFile string, allowUnauth bool) (err error) {

Subscribers

People subscribed via source and target branches