Example #1
0
func (s *initSystemSuite) TestInstallCommandsShutdown(c *gc.C) {
	name := "juju-shutdown-job"
	conf, err := service.ShutdownAfterConf("cloud-final")
	c.Assert(err, jc.ErrorIsNil)
	svc, err := systemd.NewService(name, conf, s.dataDir)
	c.Assert(err, jc.ErrorIsNil)
	commands, err := svc.InstallCommands()
	c.Assert(err, jc.ErrorIsNil)

	test := systemdtesting.WriteConfTest{
		Service: name,
		DataDir: s.dataDir,
		Expected: `
[Unit]
Description=juju shutdown job
After=syslog.target
After=network.target
After=systemd-user-sessions.service
After=cloud-final

[Service]
ExecStart=/sbin/shutdown -h now
ExecStopPost=/bin/systemctl disable juju-shutdown-job.service

[Install]
WantedBy=multi-user.target
`[1:],
	}
	test.CheckCommands(c, commands)
}
Example #2
0
func newService(name string, conf common.Conf, initSystem, series string) (Service, error) {
	switch initSystem {
	case InitSystemWindows:
		svc, err := windows.NewService(name, conf)
		if err != nil {
			return nil, errors.Annotatef(err, "failed to wrap service %q", name)
		}
		return svc, nil
	case InitSystemUpstart:
		return upstart.NewService(name, conf), nil
	case InitSystemSystemd:
		dataDir, err := paths.DataDir(series)
		if err != nil {
			return nil, errors.Annotatef(err, "failed to find juju data dir for service %q", name)
		}

		svc, err := systemd.NewService(name, conf, dataDir)
		if err != nil {
			return nil, errors.Annotatef(err, "failed to wrap service %q", name)
		}
		return svc, nil
	default:
		return nil, errors.NotFoundf("init system %q", initSystem)
	}
}
Example #3
0
func (s *initSystemSuite) TestNewServiceEmptyConf(c *gc.C) {
	service, err := systemd.NewService(s.name, common.Conf{}, s.dataDir)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(service, jc.DeepEquals, &systemd.Service{
		Service: common.Service{
			Name: s.name,
		},
		ConfName: s.name + ".service",
		UnitName: s.name + ".service",
		Dirname:  fmt.Sprintf("%s/init/%s", s.dataDir, s.name),
	})
	s.stub.CheckCalls(c, nil)
}
Example #4
0
func (s *initSystemSuite) TestInstallZombie(c *gc.C) {
	s.addService("jujud-machine-0", "active")
	s.addListResponse()
	// We force the systemd API to return a slightly different conf.
	// In this case we simply set a different Env value between the
	// conf we are installing and the conf returned by the systemd API.
	// This causes Service.Exists to return false.
	conf := common.Conf{
		Desc:      s.conf.Desc,
		ExecStart: s.conf.ExecStart,
		Env:       map[string]string{"a": "b"},
	}
	s.setConf(c, conf)
	s.addListResponse()
	s.ch <- "done"

	conf.Env["a"] = "c"
	service, err := systemd.NewService(s.name, conf, s.dataDir)
	c.Assert(err, jc.ErrorIsNil)
	err = service.Install()
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c,
		"RunCommand",
		"RunCommand",
		"ListUnits",
		"Close",
		"StopUnit",
		"Close",
		"RunCommand",
		"DisableUnitFiles",
		"Reload",
		"RemoveAll",
		"Close",
		"MkdirAll",
		"CreateFile",
		"LinkUnitFiles",
		"Reload",
		"EnableUnitFiles",
		"Close",
	)
	filename := fmt.Sprintf("%s/init/%s/%s.service", s.dataDir, s.name, s.name)
	content := s.newConfStrEnv(s.name, `"a=c"`)
	s.checkCreateFileCall(c, 12, filename, content, 0644)
}
Example #5
0
func (s *initSystemSuite) newService(c *gc.C) *systemd.Service {
	service, err := systemd.NewService(s.name, s.conf, s.dataDir)
	c.Assert(err, jc.ErrorIsNil)
	return service
}