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
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

View File

@ -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)