func (s *restartSuite) TestRestartFailStart(c *gc.C) { s.Stub.SetErrors(nil, nil, s.Failure) // DiscoverService, Stop, Start err := service.Restart(s.Name) s.CheckFailure(c, err) s.Stub.CheckCallNames(c, "DiscoverService", "Stop", "Start") }
func (s *restartSuite) TestRestartFailDiscovery(c *gc.C) { s.Stub.SetErrors(s.Failure) err := service.Restart(s.Name) s.CheckFailure(c, err) s.Stub.CheckCallNames(c, "DiscoverService") }
func (s *restartSuite) TestRestartRestartable(c *gc.C) { s.Patched.Service = &restartable{s.Service} err := service.Restart(s.Name) c.Assert(err, jc.ErrorIsNil) s.Stub.CheckCallNames(c, "DiscoverService", "Restart") }
func (s *restartSuite) TestRestartFailRestart(c *gc.C) { s.Patched.Service = &restartable{s.Service} s.Stub.SetErrors(nil, s.Failure) // DiscoverService, Restart err := service.Restart(s.Name) s.CheckFailure(c, err) s.Stub.CheckCallNames(c, "DiscoverService", "Restart") }
// Restart restarts the agent's service. func (a *MachineAgent) Restart() error { name := a.CurrentConfig().Value(agent.AgentServiceName) return service.Restart(name) }
func (s *restartSuite) TestRestartStopAndStart(c *gc.C) { err := service.Restart(s.Name) c.Assert(err, jc.ErrorIsNil) s.Stub.CheckCallNames(c, "DiscoverService", "Stop", "Start") }
"os" "github.com/juju/errors" "github.com/juju/juju/service" ) const svcName = "rsyslog" // These are patched out during tests. var ( getEuid = func() int { return os.Geteuid() } restart = func(name string) error { return service.Restart(name) } ) // Restart restarts the "rsyslog" service using the local host's // currently running init system (e.g. upstart, systemd). If the caller // is not a superuser then Restart returns an error. func Restart() error { if getEuid() == 0 { if err := restart(svcName); err != nil { return errors.Annotatef(err, "failed to restart service %q", svcName) } return nil } return errors.Errorf("must be root") }