diff --git a/README.md b/README.md index a51d1fa..a430343 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,18 @@ function. [time.ParseDuration]: http://godoc.org/time#ParseDuration + +## Reboot delay +Some systems might want to perform actions before a reboot occurs. These systems can watch the [semaphore](#semaphore) in `etcd` for changes to the `holders` and then do any tasks (e.g. pulling machines out of worker pools, load-balancers) necessary. Using `LOCKSMITHD_REBOOT_DELAY` environment variable grants the system time to perform these actions before the machine reboots. + +Usage: +``` +LOCKSMITHD_REBOOT_DELAY=300 +``` + +This would cause the machine to wait 300 seconds (5 minutes) after getting the lock before rebooting. + + ## Implementation details The following section describes how locksmith works under the hood. diff --git a/locksmithctl/daemon.go b/locksmithctl/daemon.go index 59ebb05..5a251e9 100644 --- a/locksmithctl/daemon.go +++ b/locksmithctl/daemon.go @@ -23,6 +23,7 @@ import ( "fmt" "os" "os/signal" + "strconv" "sync" "syscall" "time" @@ -107,7 +108,20 @@ func rebootAndSleep(lgn *login1.Conn) { if 0 != lines { dlog.Noticef("Logins detected, delaying reboot for %d minutes.", delaymins) time.Sleep(loginsRebootDelay) + } else { + //Don't override delay when logins are found + rebootDelayEnv := os.Getenv("LOCKSMITHD_REBOOT_DELAY") + //ignore if not set + if rebootDelayEnv != "" { + specifiedRebootDelaySecs, err := strconv.Atoi(rebootDelayEnv) + if err != nil { + dlog.Warningf("Invalid value specified for LOCKSMITHD_REBOOT_DELAY: %v. Received %v expected int. Using 0.", err, rebootDelayEnv) + } else { + time.Sleep((time.Duration(int64(specifiedRebootDelaySecs))) * time.Second) + } + } } + lgn.Reboot(false) dlog.Info("Reboot sent. Going to sleep.")