diff --git a/daemon.go b/daemon.go index 2e6331b..cc0db51 100644 --- a/daemon.go +++ b/daemon.go @@ -37,6 +37,9 @@ func (d *Daemon) Run(p Process) (*process, error) { // increment count by 1 atomic.AddUint32(&d.count, 1) + // to print remaininig seconds to start cmd == nil + d.process = p.GetProcess() + time.Sleep(time.Duration(d.cfg.Wait) * time.Second) if d.process, err = p.Start(); err != nil { diff --git a/process.go b/process.go index e74f92f..1eee98a 100644 --- a/process.go +++ b/process.go @@ -15,6 +15,7 @@ type Process interface { Pid() int Signal(sig syscall.Signal) error Start() (*process, error) + GetProcess() *process } type process struct { @@ -166,6 +167,11 @@ func (p *process) Signal(sig syscall.Signal) error { return syscall.Kill(p.cmd.Process.Pid, sig) } +// GetProccess +func (p *process) GetProcess() *process { + return p +} + // NewProcess return process instance func NewProcess(cfg *Config) *process { qch := make(chan struct{}) @@ -179,5 +185,6 @@ func NewProcess(cfg *Config) *process { }, errch: make(chan error, 1), quit: qch, + sTime: time.Now(), } } diff --git a/socket.go b/socket.go index c562e2d..fb3b05a 100644 --- a/socket.go +++ b/socket.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" "sync/atomic" + "time" "github.com/nbari/violetear" ) @@ -46,7 +47,7 @@ func (d *Daemon) HandleStatus(w http.ResponseWriter, r *http.Request) { } // only if process is running - if d.process != nil { + if d.process.cmd != nil { status.Fpid = d.fpid status.Pid = d.process.Pid() if d.process.eTime.IsZero() { @@ -55,7 +56,8 @@ func (d *Daemon) HandleStatus(w http.ResponseWriter, r *http.Request) { status.Down = AbsSince(d.process.eTime) } } else { - status.Status = fmt.Sprintf("Waiting %d seconds before starting", d.cfg.Wait) + startin := d.process.sTime.Add(time.Duration(d.cfg.Wait) * time.Second) + status.Status = fmt.Sprintf("Starting in %0.1f seconds", startin.Sub(time.Now()).Seconds()) } // return status in json