diff --git a/cmd/backup/run_script.go b/cmd/backup/run_script.go index 020cb2f1..51c6a04e 100644 --- a/cmd/backup/run_script.go +++ b/cmd/backup/run_script.go @@ -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 } diff --git a/cmd/backup/script.go b/cmd/backup/script.go index e1f29da9..a7ffc0f9 100644 --- a/cmd/backup/script.go +++ b/cmd/backup/script.go @@ -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", @@ -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") @@ -281,6 +293,5 @@ func (s *script) init() error { return s.notifySuccess() }) } - return nil }