fix: 60s lego timeout, stop on first failure, fall back to self-signed

This commit is contained in:
Claus Lohmar 2026-07-07 18:06:14 +01:00
parent 1298589afa
commit 1705d1e32d

View file

@ -1,6 +1,7 @@
package main
import (
"context"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
@ -176,12 +177,15 @@ func obtainCertsLego(domains []string, email, backupDir, legoDir, legoPath strin
"-d", domain,
}
cmd := exec.Command(legoPath, args...)
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, legoPath, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Printf(" [WARN] lego failed for %s: %v", domain, err)
continue
// Don't try remaining domains — caller will generate self-signed fallbacks
return fmt.Errorf("lego failed for %s: %w", domain, err)
}
// Small delay so port 80 is released between runs