run hooks on restart

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
(cherry picked from commit 5924387e89eb42cc8d836c500b45cb30ab3ebd09)
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Nicolas De Loof 2025-10-27 08:08:15 +01:00 committed by Guillaume Lours
parent d0f2c3504a
commit ee86f5527c

View File

@ -34,7 +34,7 @@ func (s *composeService) Restart(ctx context.Context, projectName string, option
}, s.stdinfo(), "Restarting") }, s.stdinfo(), "Restarting")
} }
func (s *composeService) restart(ctx context.Context, projectName string, options api.RestartOptions) error { func (s *composeService) restart(ctx context.Context, projectName string, options api.RestartOptions) error { //nolint:gocyclo
containers, err := s.getContainers(ctx, projectName, oneOffExclude, true) containers, err := s.getContainers(ctx, projectName, oneOffExclude, true)
if err != nil { if err != nil {
return err return err
@ -86,6 +86,13 @@ func (s *composeService) restart(ctx context.Context, projectName string, option
eg, ctx := errgroup.WithContext(ctx) eg, ctx := errgroup.WithContext(ctx)
for _, ctr := range containers.filter(isService(service)) { for _, ctr := range containers.filter(isService(service)) {
eg.Go(func() error { eg.Go(func() error {
def := project.Services[service]
for _, hook := range def.PreStop {
err = s.runHook(ctx, ctr, def, hook, nil)
if err != nil {
return err
}
}
eventName := getContainerProgressName(ctr) eventName := getContainerProgressName(ctr)
w.Event(progress.RestartingEvent(eventName)) w.Event(progress.RestartingEvent(eventName))
timeout := utils.DurationSecondToInt(options.Timeout) timeout := utils.DurationSecondToInt(options.Timeout)
@ -94,6 +101,12 @@ func (s *composeService) restart(ctx context.Context, projectName string, option
return err return err
} }
w.Event(progress.StartedEvent(eventName)) w.Event(progress.StartedEvent(eventName))
for _, hook := range def.PostStart {
err = s.runHook(ctx, ctr, def, hook, nil)
if err != nil {
return err
}
}
return nil return nil
}) })
} }