Fix local runtime updates (#1543)
This commit is contained in:
parent
ae56becbbd
commit
ac5822f1ee
@ -332,22 +332,17 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) {
|
||||
|
||||
// Update attemps to update the service
|
||||
func (r *runtime) Update(s *Service) error {
|
||||
var opts []CreateOption
|
||||
|
||||
// check if the service already exists
|
||||
r.RLock()
|
||||
if service, ok := r.services[s.Name]; ok {
|
||||
opts = append(opts, WithOutput(service.output))
|
||||
r.Lock()
|
||||
service, ok := r.services[s.Name]
|
||||
r.Unlock()
|
||||
if !ok {
|
||||
return errors.New("Service not found")
|
||||
}
|
||||
r.RUnlock()
|
||||
|
||||
// delete the service
|
||||
if err := r.Delete(s); err != nil {
|
||||
err := service.Stop()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// create new service
|
||||
return r.Create(s, opts...)
|
||||
return service.Start()
|
||||
}
|
||||
|
||||
// Delete removes the service from the runtime and stops it
|
||||
|
@ -100,6 +100,7 @@ func (s *service) Start() error {
|
||||
// reset
|
||||
s.err = nil
|
||||
s.closed = make(chan bool)
|
||||
s.retries = 0
|
||||
|
||||
if s.Metadata == nil {
|
||||
s.Metadata = make(map[string]string)
|
||||
@ -113,6 +114,7 @@ func (s *service) Start() error {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("Runtime service %s forking new process", s.Service.Name)
|
||||
}
|
||||
|
||||
p, err := s.Process.Fork(s.Exec)
|
||||
if err != nil {
|
||||
s.Metadata["status"] = "error"
|
||||
@ -150,6 +152,7 @@ func (s *service) Stop() error {
|
||||
default:
|
||||
close(s.closed)
|
||||
s.running = false
|
||||
s.retries = 0
|
||||
if s.PID == nil {
|
||||
return nil
|
||||
}
|
||||
@ -159,6 +162,9 @@ func (s *service) Stop() error {
|
||||
|
||||
// kill the process
|
||||
err := s.Process.Kill(s.PID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// wait for it to exit
|
||||
s.Process.Wait(s.PID)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user