Skip to content

Commit

Permalink
Notifications do not get sent on locking failure
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Apr 25, 2024
1 parent 292d47e commit cf860e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/backup/run_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func runScript(c *Config) (err error) {

unlock, lockErr := s.lock("/var/lock/dockervolumebackup.lock")
if lockErr != nil {
if initErr := s.initNotificationsOnly(); initErr != nil {
err = errwrap.Wrap(initErr, "error initializing notifications")
return
}
err = errwrap.Wrap(lockErr, "error acquiring file lock")
return
}
Expand Down
13 changes: 12 additions & 1 deletion cmd/backup/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ func (s *script) init() error {
s.storages = append(s.storages, dropboxBackend)
}

if err := s.initNotificationsOnly(); err != nil {
return errwrap.Wrap(err, "error initializing configuration setup")
}

return nil
}

// initNotificationsOnly lives outside of the main init routine so that script
// runs that fail early can try to send notifications without having to
// invoke a full initialization
func (s *script) initNotificationsOnly() error {
if s.c.EmailNotificationRecipient != "" {
emailURL := fmt.Sprintf(
"smtp://%s:%s@%s:%d/?from=%s&to=%s",
Expand Down Expand Up @@ -253,6 +264,7 @@ func (s *script) init() error {

tmpl := template.New("")
tmpl.Funcs(templateHelpers)
var err error
tmpl, err = tmpl.Parse(defaultNotifications)
if err != nil {
return errwrap.Wrap(err, "unable to parse default notifications templates")
Expand Down Expand Up @@ -281,6 +293,5 @@ func (s *script) init() error {
return s.notifySuccess()
})
}

return nil
}

0 comments on commit cf860e1

Please sign in to comment.