From 5a6db4d098ffba4538d10ba50dea465e26335ab6 Mon Sep 17 00:00:00 2001 From: Israel Derdik Date: Fri, 22 Apr 2016 12:44:49 -0400 Subject: [PATCH 1/5] daemon: add LOCKSMITHD_REBOOT_DELAY environment variable --- README.md | 12 ++++++++++++ locksmithctl/daemon.go | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index a51d1fa..7dc3b07 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 actinos 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 befor 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..0c2de79 100644 --- a/locksmithctl/daemon.go +++ b/locksmithctl/daemon.go @@ -107,7 +107,14 @@ 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") + if specifiedRebootDelaySecs, ok := rebootDelayEnv.(int); ok { + time.Sleep(specifiedRebootDelaySecs * time.Second) + } } + lgn.Reboot(false) dlog.Info("Reboot sent. Going to sleep.") From 58816f705a6d386c59bda41ba2be24f6ca7946bc Mon Sep 17 00:00:00 2001 From: Israel Derdik Date: Tue, 3 May 2016 10:33:19 -0400 Subject: [PATCH 2/5] removed type assertion --- locksmithctl/daemon.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/locksmithctl/daemon.go b/locksmithctl/daemon.go index 0c2de79..29b5dd1 100644 --- a/locksmithctl/daemon.go +++ b/locksmithctl/daemon.go @@ -25,6 +25,7 @@ import ( "os/signal" "sync" "syscall" + "strconv" "time" "github.com/coreos/locksmith/Godeps/_workspace/src/github.com/coreos/go-systemd/dbus" @@ -110,9 +111,15 @@ func rebootAndSleep(lgn *login1.Conn) { } else { //Don't override delay when logins are found rebootDelayEnv := os.Getenv("LOCKSMITHD_REBOOT_DELAY") - if specifiedRebootDelaySecs, ok := rebootDelayEnv.(int); ok { - time.Sleep(specifiedRebootDelaySecs * time.Second) - } + //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(specifiedRebootDelaySecs * time.Second) + } + } } lgn.Reboot(false) From 01df61e2a3f1faac383364e5d15d979b69751c22 Mon Sep 17 00:00:00 2001 From: Israel Derdik Date: Tue, 3 May 2016 10:41:54 -0400 Subject: [PATCH 3/5] fixed sleep duration --- locksmithctl/daemon.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locksmithctl/daemon.go b/locksmithctl/daemon.go index 29b5dd1..13d83f2 100644 --- a/locksmithctl/daemon.go +++ b/locksmithctl/daemon.go @@ -117,7 +117,7 @@ func rebootAndSleep(lgn *login1.Conn) { if err != nil { dlog.Warningf("Invalid value specified for LOCKSMITHD_REBOOT_DELAY: %v. Received %v expected int. Using 0.", err, rebootDelayEnv) } else { - time.Sleep(specifiedRebootDelaySecs * time.Second) + time.Sleep((time.Duration(int64(specifiedRebootDelaySecs))) * time.Second) } } } From b73d29ec7454646bd0f43f9aba7f377192069771 Mon Sep 17 00:00:00 2001 From: Israel Derdik Date: Tue, 3 May 2016 10:45:17 -0400 Subject: [PATCH 4/5] go fmt --- locksmithctl/daemon.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locksmithctl/daemon.go b/locksmithctl/daemon.go index 13d83f2..5a251e9 100644 --- a/locksmithctl/daemon.go +++ b/locksmithctl/daemon.go @@ -23,9 +23,9 @@ import ( "fmt" "os" "os/signal" + "strconv" "sync" "syscall" - "strconv" "time" "github.com/coreos/locksmith/Godeps/_workspace/src/github.com/coreos/go-systemd/dbus" @@ -113,13 +113,13 @@ func rebootAndSleep(lgn *login1.Conn) { rebootDelayEnv := os.Getenv("LOCKSMITHD_REBOOT_DELAY") //ignore if not set if rebootDelayEnv != "" { - specifiedRebootDelaySecs, err := strconv.Atoi(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) From 8a33e7f83e37631eb7be6bd416b00476b8924d90 Mon Sep 17 00:00:00 2001 From: Israel Derdik Date: Wed, 11 May 2016 15:18:30 -0400 Subject: [PATCH 5/5] fixed typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7dc3b07..a430343 100644 --- a/README.md +++ b/README.md @@ -140,14 +140,14 @@ function. ## Reboot delay -Some systems might want to perform actinos 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. +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 befor rebooting. +This would cause the machine to wait 300 seconds (5 minutes) after getting the lock before rebooting. ## Implementation details