Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions locksmithctl/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"os"
"os/signal"
"strconv"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -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.")

Expand Down