mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-11-22 21:30:28 +01:00
Scale services back up
This commit is contained in:
parent
8ef7fa0d5d
commit
511b79bd43
@ -394,15 +394,6 @@ func (s *script) stopContainersAndServices() (func() error, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var stopError error
|
|
||||||
if len(stopErrors) != 0 {
|
|
||||||
stopError = fmt.Errorf(
|
|
||||||
"stopContainers: %d error(s) stopping containers: %w",
|
|
||||||
len(stopErrors),
|
|
||||||
errors.Join(stopErrors...),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
var scaledDownServices []swarm.Service
|
var scaledDownServices []swarm.Service
|
||||||
var scaleDownErrors []error
|
var scaleDownErrors []error
|
||||||
if isDockerSwarm {
|
if isDockerSwarm {
|
||||||
@ -432,6 +423,16 @@ func (s *script) stopContainersAndServices() (func() error, error) {
|
|||||||
ScaleDownErrors: uint(len(scaleDownErrors)),
|
ScaleDownErrors: uint(len(scaleDownErrors)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var initialErr error
|
||||||
|
allErrors := append(stopErrors, scaleDownErrors...)
|
||||||
|
if len(allErrors) != 0 {
|
||||||
|
initialErr = fmt.Errorf(
|
||||||
|
"stopContainers: %d error(s) stopping containers: %w",
|
||||||
|
len(allErrors),
|
||||||
|
errors.Join(allErrors...),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return func() error {
|
return func() error {
|
||||||
servicesRequiringForceUpdate := map[string]struct{}{}
|
servicesRequiringForceUpdate := map[string]struct{}{}
|
||||||
|
|
||||||
@ -469,21 +470,34 @@ func (s *script) stopContainersAndServices() (func() error, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(restartErrors) != 0 {
|
var scaleUpErrors []error
|
||||||
|
if isDockerSwarm {
|
||||||
|
for _, service := range servicesToScaleDown {
|
||||||
|
service.Spec.Mode.Replicated.Replicas = service.PreviousSpec.Mode.Replicated.Replicas
|
||||||
|
service.Spec.TaskTemplate.ForceUpdate += 1
|
||||||
|
if _, err := s.cli.ServiceUpdate(context.Background(), service.ID, service.Version, service.Spec, types.ServiceUpdateOptions{}); err != nil {
|
||||||
|
scaleUpErrors = append(scaleUpErrors, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allErrors := append(restartErrors, scaleUpErrors...)
|
||||||
|
if len(allErrors) != 0 {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"stopContainers: %d error(s) restarting containers and services: %w",
|
"stopContainers: %d error(s) restarting containers and services: %w",
|
||||||
len(restartErrors),
|
len(allErrors),
|
||||||
errors.Join(restartErrors...),
|
errors.Join(allErrors...),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
s.logger.Info(
|
s.logger.Info(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"Restarted %d container(s) and the matching service(s).",
|
"Restarted %d container(s) and %d service(s).",
|
||||||
len(stoppedContainers),
|
len(stoppedContainers),
|
||||||
|
len(scaledDownServices),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return nil
|
return nil
|
||||||
}, stopError
|
}, initialErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// createArchive creates a tar archive of the configured backup location and
|
// createArchive creates a tar archive of the configured backup location and
|
||||||
|
Loading…
Reference in New Issue
Block a user