Skip to content

Commit b456601

Browse files
committed
run hooks on restart
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 7f668bd commit b456601

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/compose/restart.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (s *composeService) Restart(ctx context.Context, projectName string, option
3434
}, s.stdinfo(), "Restarting")
3535
}
3636

37-
func (s *composeService) restart(ctx context.Context, projectName string, options api.RestartOptions) error {
37+
func (s *composeService) restart(ctx context.Context, projectName string, options api.RestartOptions) error { //nolint:gocyclo
3838
containers, err := s.getContainers(ctx, projectName, oneOffExclude, true)
3939
if err != nil {
4040
return err
@@ -86,6 +86,13 @@ func (s *composeService) restart(ctx context.Context, projectName string, option
8686
eg, ctx := errgroup.WithContext(ctx)
8787
for _, ctr := range containers.filter(isService(service)) {
8888
eg.Go(func() error {
89+
def := project.Services[service]
90+
for _, hook := range def.PreStop {
91+
err = s.runHook(ctx, ctr, def, hook, nil)
92+
if err != nil {
93+
return err
94+
}
95+
}
8996
eventName := getContainerProgressName(ctr)
9097
w.Event(progress.RestartingEvent(eventName))
9198
timeout := utils.DurationSecondToInt(options.Timeout)
@@ -94,6 +101,12 @@ func (s *composeService) restart(ctx context.Context, projectName string, option
94101
return err
95102
}
96103
w.Event(progress.StartedEvent(eventName))
104+
for _, hook := range def.PostStart {
105+
err = s.runHook(ctx, ctr, def, hook, nil)
106+
if err != nil {
107+
return err
108+
}
109+
}
97110
return nil
98111
})
99112
}

0 commit comments

Comments
 (0)