Skip to content

Commit

Permalink
Notification hooks do not run on locking failure
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Mar 9, 2024
1 parent baf34ec commit 03250e9
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions cmd/backup/run_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,35 @@ func runScript(c *Config) (err error) {

s := newScript(c)

unlock, lockErr := s.lock("/var/lock/dockervolumebackup.lock")
if lockErr != nil {
err = errwrap.Wrap(lockErr, "error acquiring file lock")
return
}
defer func() {
if derr := unlock(); derr != nil {
err = errors.Join(err, errwrap.Wrap(derr, "error releasing file lock"))
}
}()
return func() (err error) {
scriptErr := func() (err error) {
unlock, lockErr := s.lock("/var/lock/dockervolumebackup.lock")
if lockErr != nil {
err = errwrap.Wrap(lockErr, "error acquiring file lock")
return
}

unset, err := s.c.applyEnv()
if err != nil {
return errwrap.Wrap(err, "error applying env")
}
defer func() {
if derr := unset(); derr != nil {
err = errors.Join(err, errwrap.Wrap(derr, "error unsetting environment variables"))
}
}()
defer func() {
if derr := unlock(); derr != nil {
err = errors.Join(err, errwrap.Wrap(derr, "error releasing file lock"))
}
}()

if initErr := s.init(); initErr != nil {
err = errwrap.Wrap(initErr, "error instantiating script")
return
}
unset, err := s.c.applyEnv()
if err != nil {
err = errwrap.Wrap(err, "error applying env")
return
}
defer func() {
if derr := unset(); derr != nil {
err = errors.Join(err, errwrap.Wrap(derr, "error unsetting environment variables"))
}
}()

return func() (err error) {
scriptErr := func() error {
if initErr := s.init(); initErr != nil {
err = errwrap.Wrap(initErr, "error instantiating script")
return
}
if err := s.withLabeledCommands(lifecyclePhaseArchive, func() (err error) {
restartContainersAndServices, err := s.stopContainersAndServices()
// The mechanism for restarting containers is not using hooks as it
Expand Down

0 comments on commit 03250e9

Please sign in to comment.