MCPcopy
hub / github.com/docker/compose / restart

Method restart

pkg/compose/restart.go:37–115  ·  pkg/compose/restart.go::composeService.restart
(ctx context.Context, projectName string, options api.RestartOptions)

Source from the content-addressed store, hash-verified

35}
36
37func (s *composeService) restart(ctx context.Context, projectName string, options api.RestartOptions) error { //nolint:gocyclo
38 containers, err := s.getContainers(ctx, projectName, oneOffExclude, true)
39 if err != nil {
40 return err
41 }
42
43 project := options.Project
44 if project == nil {
45 project, err = s.getProjectWithResources(ctx, containers, projectName)
46 if err != nil {
47 return err
48 }
49 }
50
51 if options.NoDeps {
52 project, err = project.WithSelectedServices(options.Services, types.IgnoreDependencies)
53 if err != nil {
54 return err
55 }
56 }
57
58 // ignore depends_on relations which are not impacted by restarting service or not required
59 project, err = project.WithServicesTransform(func(_ string, s types.ServiceConfig) (types.ServiceConfig, error) {
60 for name, r := range s.DependsOn {
61 if !r.Restart {
62 delete(s.DependsOn, name)
63 }
64 }
65 return s, nil
66 })
67 if err != nil {
68 return err
69 }
70
71 if len(options.Services) != 0 {
72 project, err = project.WithSelectedServices(options.Services, types.IncludeDependents)
73 if err != nil {
74 return err
75 }
76 }
77
78 return InDependencyOrder(ctx, project, func(c context.Context, service string) error {
79 config := project.Services[service]
80 err = s.waitDependencies(ctx, project, service, config.DependsOn, containers, 0)
81 if err != nil {
82 return err
83 }
84
85 eg, ctx := errgroup.WithContext(ctx)
86 for _, ctr := range containers.filter(isService(service)) {
87 eg.Go(func() error {
88 def := project.Services[service]
89 for _, hook := range def.PreStop {
90 err = s.runHook(ctx, ctr, def, hook, nil)
91 if err != nil {
92 return err
93 }
94 }

Callers 2

RestartMethod · 0.95
handleWatchBatchMethod · 0.95

Calls 14

getContainersMethod · 0.95
waitDependenciesMethod · 0.95
runHookMethod · 0.95
apiClientMethod · 0.95
DurationSecondToIntFunction · 0.92
InDependencyOrderFunction · 0.85
isServiceFunction · 0.85
getContainerProgressNameFunction · 0.85
newEventFunction · 0.85
filterMethod · 0.80
OnMethod · 0.65

Tested by

no test coverage detected