Exemplo n.º 1
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)
	}
}
Exemplo n.º 2
0
// NewService returns an interface to a service apropriate
// for the current system
func NewService(name string, conf common.Conf) Service {
	switch version.Current.OS {
	case version.Windows:
		svc := windows.NewService(name, conf)
		return svc
	default:
		return upstart.NewService(name, conf)
	}
}
Exemplo n.º 3
0
func (s *serviceSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetUpTest(c)
	var err error
	s.execPath = `C:\juju\bin\jujud.exe`
	s.stub = &testing.Stub{}
	s.stubMgr = windows.PatchServiceManager(s, s.stub)

	// Set up the service.
	s.name = "machine-1"
	s.conf = common.Conf{
		Desc:      "service for " + s.name,
		ExecStart: s.execPath + " " + s.name,
	}

	s.svcExistsErr = errors.New("Service machine-1 already installed")

	s.mgr, err = windows.NewService(s.name, s.conf)
	c.Assert(err, gc.IsNil)

	// Clear services
	s.stubMgr.Clear()
	s.stub.ResetCalls()
}