From da2e57dd8ca268097bdaa3d6eaec5200ef619b99 Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 5 Apr 2017 18:10:35 -0400 Subject: [PATCH] Add flag to configure timeouts for start and restart Fix #46 --- main.go | 9 +++++++++ services/command.go | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index af7e2d5e..12ac6010 100644 --- a/main.go +++ b/main.go @@ -85,6 +85,13 @@ func main() { Value: &(flags.exclude), } + timeoutFlag := cli.IntFlag{ + Name: "timeout", + Usage: "The amount of time in seconds that Edward will wait for a service to launch before timing out. Defaults to 30", + Destination: &services.StartupTimeoutSeconds, + Value: 30, + } + app.Flags = []cli.Flag{ cli.StringFlag{ Name: "config, c", @@ -145,6 +152,7 @@ func main() { Usage: "After starting, tail logs for services.", Destination: &(flags.tail), }, + timeoutFlag, }, }, { @@ -178,6 +186,7 @@ func main() { Usage: "Disable autorestart", Destination: &(flags.noWatch), }, + timeoutFlag, }, }, { diff --git a/services/command.go b/services/command.go index 32745fe4..c474e0cf 100644 --- a/services/command.go +++ b/services/command.go @@ -20,6 +20,10 @@ import ( "github.com/yext/edward/warmup" ) +// StartupTimeoutSeconds is the amount of time in seconds that Edward will wait +// for a service to start before timing out +var StartupTimeoutSeconds = 30 + // ServiceCommand provides state and functions for managing a service type ServiceCommand struct { // Parent service config @@ -282,7 +286,7 @@ func (c *ServiceCommand) waitUntilLive(command *exec.Cmd) error { return errors.New("service terminated prematurely") } - timeout := time.NewTimer(30 * time.Second) + timeout := time.NewTimer(time.Duration(StartupTimeoutSeconds) * time.Second) defer timeout.Stop() done := make(chan struct{})