Пример #1
0
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")
}
Пример #2
0
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")
}
Пример #3
0
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")
}
Пример #4
0
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")
}
Пример #5
0
// Restart restarts the agent's service.
func (a *MachineAgent) Restart() error {
	name := a.CurrentConfig().Value(agent.AgentServiceName)
	return service.Restart(name)
}
Пример #6
0
func (s *restartSuite) TestRestartStopAndStart(c *gc.C) {
	err := service.Restart(s.Name)
	c.Assert(err, jc.ErrorIsNil)

	s.Stub.CheckCallNames(c, "DiscoverService", "Stop", "Start")
}
Пример #7
0
	"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")
}