Ejemplo n.º 1
0
// Signal sends the given signal to the given service.
func (instance *Execution) Signal(target *service.Service, what values.Signal) error {
	instance.doRLock()
	execution, ok := instance.executions[target]
	if !ok {
		instance.doRUnlock()
		return service.AlreadyStoppedError{Name: target.Name()}
	}
	instance.doRUnlock()
	return execution.Signal(what)
}
Ejemplo n.º 2
0
// Kill kills the given service.
func (instance *Execution) Kill(target *service.Service) error {
	instance.doRLock()
	execution, ok := instance.executions[target]
	if !ok {
		instance.doRUnlock()
		return service.AlreadyStoppedError{Name: target.Name()}
	}
	instance.doRUnlock()
	instance.registerStopRequestsFor(execution)
	return execution.Kill()
}
Ejemplo n.º 3
0
func (instance *Execution) createAndRegisterNotExistingExecutionFor(target *service.Service) (*service.Execution, error) {
	instance.doWLock()
	defer instance.doWUnlock()
	result, err := target.NewExecution(instance.executable.KeyStore())
	if err != nil {
		return nil, err
	}
	if _, ok := instance.executions[target]; ok {
		return nil, service.AlreadyRunningError{Name: target.Name()}
	}
	instance.executions[target] = result
	return result, nil
}
Ejemplo n.º 4
0
// Restart stops and restarts the given service.
func (instance *Execution) Restart(target *service.Service) error {
	instance.doRLock()
	if stopRequested, ok := instance.stopRequests[target]; ok && stopRequested {
		instance.doRUnlock()
		return service.AlreadyStoppedError{Name: target.Name()}
	}
	execution, ok := instance.executions[target]
	if !ok {
		instance.doRUnlock()
		return instance.Start(target)
	}
	instance.restartRequests[target] = true
	instance.doRUnlock()
	execution.Stop()
	return nil
}