mirror of
https://github.com/docker/compose.git
synced 2025-11-03 21:25:21 +01:00
run hooks on restart
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
7f668bd7fe
commit
5924387e89
@ -34,7 +34,7 @@ func (s *composeService) Restart(ctx context.Context, projectName string, option
|
||||
}, 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)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -86,6 +86,13 @@ func (s *composeService) restart(ctx context.Context, projectName string, option
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
for _, ctr := range containers.filter(isService(service)) {
|
||||
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)
|
||||
w.Event(progress.RestartingEvent(eventName))
|
||||
timeout := utils.DurationSecondToInt(options.Timeout)
|
||||
@ -94,6 +101,12 @@ func (s *composeService) restart(ctx context.Context, projectName string, option
|
||||
return err
|
||||
}
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user