Always initialize notifications first

This commit is contained in:
Frederik Ring 2024-04-26 14:35:59 +02:00
parent cf860e1dab
commit 178239f5b8
2 changed files with 6 additions and 12 deletions

View file

@ -30,12 +30,13 @@ func runScript(c *Config) (err error) {
s := newScript(c)
if initErr := s.initNotifications(); initErr != nil {
err = errwrap.Wrap(initErr, "error initializing notifications")
return
}
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
}

View file

@ -219,17 +219,10 @@ 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 {
func (s *script) initNotifications() error {
if s.c.EmailNotificationRecipient != "" {
emailURL := fmt.Sprintf(
"smtp://%s:%s@%s:%d/?from=%s&to=%s",