Fix local runtime updates (#1543)

This commit is contained in:
Janos Dobronszki 2020-04-16 17:50:24 +02:00 committed by GitHub
parent ae56becbbd
commit ac5822f1ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View File

@ -332,22 +332,17 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) {
// Update attemps to update the service // Update attemps to update the service
func (r *runtime) Update(s *Service) error { func (r *runtime) Update(s *Service) error {
var opts []CreateOption r.Lock()
service, ok := r.services[s.Name]
// check if the service already exists r.Unlock()
r.RLock() if !ok {
if service, ok := r.services[s.Name]; ok { return errors.New("Service not found")
opts = append(opts, WithOutput(service.output))
} }
r.RUnlock() err := service.Stop()
if err != nil {
// delete the service
if err := r.Delete(s); err != nil {
return err return err
} }
return service.Start()
// create new service
return r.Create(s, opts...)
} }
// Delete removes the service from the runtime and stops it // Delete removes the service from the runtime and stops it

View File

@ -100,6 +100,7 @@ func (s *service) Start() error {
// reset // reset
s.err = nil s.err = nil
s.closed = make(chan bool) s.closed = make(chan bool)
s.retries = 0
if s.Metadata == nil { if s.Metadata == nil {
s.Metadata = make(map[string]string) s.Metadata = make(map[string]string)
@ -113,6 +114,7 @@ func (s *service) Start() error {
if logger.V(logger.DebugLevel, logger.DefaultLogger) { if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("Runtime service %s forking new process", s.Service.Name) logger.Debugf("Runtime service %s forking new process", s.Service.Name)
} }
p, err := s.Process.Fork(s.Exec) p, err := s.Process.Fork(s.Exec)
if err != nil { if err != nil {
s.Metadata["status"] = "error" s.Metadata["status"] = "error"
@ -150,6 +152,7 @@ func (s *service) Stop() error {
default: default:
close(s.closed) close(s.closed)
s.running = false s.running = false
s.retries = 0
if s.PID == nil { if s.PID == nil {
return nil return nil
} }
@ -159,6 +162,9 @@ func (s *service) Stop() error {
// kill the process // kill the process
err := s.Process.Kill(s.PID) err := s.Process.Kill(s.PID)
if err != nil {
return err
}
// wait for it to exit // wait for it to exit
s.Process.Wait(s.PID) s.Process.Wait(s.PID)