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
=== modified file 'snappy/click.go'
--- snappy/click.go 2015-04-08 18:53:49 +0000
+++ snappy/click.go 2015-04-13 14:30:45 +0000
@@ -70,6 +70,9 @@
70 pattern string70 pattern string
71}71}
7272
73// the default target for systemd units that we generate
74const servicesSystemdTarget = "multi-user.target"
75
73const (76const (
74 // from debsig-verify-0.9/debsigs.h77 // from debsig-verify-0.9/debsigs.h
75 dsSuccess = 078 dsSuccess = 0
@@ -421,13 +424,14 @@
421{{if .StopTimeout}}TimeoutStopSec={{.StopTimeout}}{{end}}424{{if .StopTimeout}}TimeoutStopSec={{.StopTimeout}}{{end}}
422425
423[Install]426[Install]
424WantedBy=multi-user.target427WantedBy={{.ServicesSystemdTarget}}
425`428`
426 var templateOut bytes.Buffer429 var templateOut bytes.Buffer
427 t := template.Must(template.New("wrapper").Parse(serviceTemplate))430 t := template.Must(template.New("wrapper").Parse(serviceTemplate))
428 wrapperData := struct {431 wrapperData := struct {
429 // embed service struct432 // embed service struct
430 Service433 Service
434<<<<<<< TREE
431 // but we need more435 // but we need more
432 Name string436 Name string
433 Version string437 Version string
@@ -437,12 +441,22 @@
437 FullPathStop string441 FullPathStop string
438 FullPathPostStop string442 FullPathPostStop string
439 AppTriple string443 AppTriple string
444=======
445 AppPath string
446 AaProfile string
447 FullPathStart string
448 FullPathStop string
449 FullPathPostStop string
450 AppTriple string
451 ServicesSystemdTarget string
452>>>>>>> MERGE-SOURCE
440 }{453 }{
441 service, m.Name, m.Version, baseDir, aaProfile,454 service, m.Name, m.Version, baseDir, aaProfile,
442 filepath.Join(baseDir, service.Start),455 filepath.Join(baseDir, service.Start),
443 filepath.Join(baseDir, service.Stop),456 filepath.Join(baseDir, service.Stop),
444 filepath.Join(baseDir, service.PostStop),457 filepath.Join(baseDir, service.PostStop),
445 fmt.Sprintf("%s_%s_%s", m.Name, service.Name, m.Version),458 fmt.Sprintf("%s_%s_%s", m.Name, service.Name, m.Version),
459 servicesSystemdTarget,
446 }460 }
447 if err := t.Execute(&templateOut, wrapperData); err != nil {461 if err := t.Execute(&templateOut, wrapperData); err != nil {
448 // this can never happen, except we forget a variable462 // this can never happen, except we forget a variable
@@ -467,6 +481,7 @@
467 return dir[len(globalRootDir):]481 return dir[len(globalRootDir):]
468}482}
469483
484<<<<<<< TREE
470func checkPackageForNameClashes(baseDir string) error {485func checkPackageForNameClashes(baseDir string) error {
471 m, err := parsePackageYamlFile(filepath.Join(baseDir, "meta", "package.yaml"))486 m, err := parsePackageYamlFile(filepath.Join(baseDir, "meta", "package.yaml"))
472 if err != nil {487 if err != nil {
@@ -477,6 +492,18 @@
477}492}
478493
479func addPackageServices(baseDir string, inhibitHooks bool, inter interacter) error {494func addPackageServices(baseDir string, inhibitHooks bool, inter interacter) error {
495=======
496// enable a service via manual symlink creation. Note that we can not
497// use "systemctl enable" as this code needs to run via ubuntu-device-flash
498// on a host that may not have systemd installed
499func systemdEnable(serviceFilename string) error {
500 enableTargetSymlink := filepath.Join(snapServicesDir, servicesSystemdTarget+".wants", filepath.Base(serviceFilename))
501
502 return os.Symlink(stripGlobalRootDir(serviceFilename), enableTargetSymlink)
503}
504
505func addPackageServices(baseDir string, inhibitHooks bool) error {
506>>>>>>> MERGE-SOURCE
480 m, err := parsePackageYamlFile(filepath.Join(baseDir, "meta", "package.yaml"))507 m, err := parsePackageYamlFile(filepath.Join(baseDir, "meta", "package.yaml"))
481 if err != nil {508 if err != nil {
482 return err509 return err
@@ -501,7 +528,13 @@
501 //528 //
502 // *but* always run enable (which just sets a symlink)529 // *but* always run enable (which just sets a symlink)
503 serviceName := filepath.Base(generateServiceFileName(m, service))530 serviceName := filepath.Base(generateServiceFileName(m, service))
531
532 if err := systemdEnable(serviceFilename); err != nil {
533 return err
534 }
535
504 if !inhibitHooks {536 if !inhibitHooks {
537<<<<<<< TREE
505 sysd := systemd.New(globalRootDir, inter)538 sysd := systemd.New(globalRootDir, inter)
506 if err := sysd.DaemonReload(); err != nil {539 if err := sysd.DaemonReload(); err != nil {
507 return err540 return err
@@ -512,6 +545,13 @@
512 }545 }
513546
514 if err := sysd.Start(serviceName); err != nil {547 if err := sysd.Start(serviceName); err != nil {
548=======
549 if err := runSystemctl("daemon-reload"); err != nil {
550 return err
551 }
552
553 if err := runSystemctl("start", serviceName); err != nil {
554>>>>>>> MERGE-SOURCE
515 return err555 return err
516 }556 }
517 }557 }
518558
=== modified file 'snappy/click_test.go'
--- snappy/click_test.go 2015-04-08 18:53:49 +0000
+++ snappy/click_test.go 2015-04-13 14:30:45 +0000
@@ -452,10 +452,8 @@
452 // it go de-activated and finally 2.0 got activated452 // it go de-activated and finally 2.0 got activated
453 content, err := ioutil.ReadFile(filepath.Join(s.tempdir, "hook.trace"))453 content, err := ioutil.ReadFile(filepath.Join(s.tempdir, "hook.trace"))
454 c.Assert(err, IsNil)454 c.Assert(err, IsNil)
455 c.Assert(string(content), Equals, `now: ./bar_app_1.0.tracehook455 expected := fmt.Sprintf("now: ./bar_app_1.0.tracehook\nnow: \nnow: ./bar_app_2.0.tracehook\n")
456now: 456 c.Assert(string(content), Equals, expected)
457now: ./bar_app_2.0.tracehook
458`)
459}457}
460458
461func (s *SnapTestSuite) TestClickCopyDataHookFails(c *C) {459func (s *SnapTestSuite) TestClickCopyDataHookFails(c *C) {
@@ -629,13 +627,21 @@
629 _, err := installClick(snapFile, AllowUnauthenticated, nil)627 _, err := installClick(snapFile, AllowUnauthenticated, nil)
630 c.Assert(err, IsNil)628 c.Assert(err, IsNil)
631629
632 servicesFile := filepath.Join(snapServicesDir, "foo.mvo_service_1.0.service")630 // ensure that we have the services file
631 serviceName := "foo.mvo_service_1.0.service"
632 servicesFile := filepath.Join(snapServicesDir, serviceName)
633 c.Assert(helpers.FileExists(servicesFile), Equals, true)633 c.Assert(helpers.FileExists(servicesFile), Equals, true)
634 st, err := os.Stat(servicesFile)634 st, err := os.Stat(servicesFile)
635 c.Assert(err, IsNil)635 c.Assert(err, IsNil)
636 // should _not_ be executable636 // should _not_ be executable
637 c.Assert(st.Mode().String(), Equals, "-rw-r--r--")637 c.Assert(st.Mode().String(), Equals, "-rw-r--r--")
638638
639 // ensure that we have the wants symlink
640 enabledSymlink := filepath.Join(snapServicesDir, servicesSystemdTarget+".wants", serviceName)
641 target, err := os.Readlink(enabledSymlink)
642 c.Assert(err, IsNil)
643 c.Assert(target, Equals, stripGlobalRootDir(servicesFile))
644
639 // and that it gets removed on remove645 // and that it gets removed on remove
640 snapDir := filepath.Join(snapAppsDir, "foo.mvo", "1.0")646 snapDir := filepath.Join(snapAppsDir, "foo.mvo", "1.0")
641 err = removeClick(snapDir, new(progress.NullProgress))647 err = removeClick(snapDir, new(progress.NullProgress))
@@ -662,8 +668,12 @@
662 _, err := installClick(snapFile, 0, nil)668 _, err := installClick(snapFile, 0, nil)
663 c.Assert(err, IsNil)669 c.Assert(err, IsNil)
664670
671<<<<<<< TREE
665 c.Assert(allSystemctl, HasLen, 3)672 c.Assert(allSystemctl, HasLen, 3)
666 c.Assert(allSystemctl[1], DeepEquals, []string{"--root", globalRootDir, "enable", "foo.mvo_service_1.0.service"})673 c.Assert(allSystemctl[1], DeepEquals, []string{"--root", globalRootDir, "enable", "foo.mvo_service_1.0.service"})
674=======
675 c.Assert(allSystemctl, HasLen, 0)
676>>>>>>> MERGE-SOURCE
667}677}
668678
669const expectedService = `[Unit]679const expectedService = `[Unit]
670680
=== modified file 'snappy/snapp_test.go'
--- snappy/snapp_test.go 2015-04-09 09:10:06 +0000
+++ snappy/snapp_test.go 2015-04-13 14:30:45 +0000
@@ -52,6 +52,9 @@
52 clickSystemHooksDir = filepath.Join(s.tempdir, "/usr/share/click/hooks")52 clickSystemHooksDir = filepath.Join(s.tempdir, "/usr/share/click/hooks")
53 os.MkdirAll(clickSystemHooksDir, 0755)53 os.MkdirAll(clickSystemHooksDir, 0755)
5454
55 // create a fake systemd environment
56 os.MkdirAll(filepath.Join(snapServicesDir, servicesSystemdTarget+".wants"), 0755)
57
55 // we may not have debsig-verify installed (and we don't need it58 // we may not have debsig-verify installed (and we don't need it
56 // for the unittests)59 // for the unittests)
57 runDebsigVerify = func(snapFile string, allowUnauth bool) (err error) {60 runDebsigVerify = func(snapFile string, allowUnauth bool) (err error) {

Subscribers

People subscribed via source and target branches