From 2dbca8fa3bfee503e509a417470547a98b5a7dd1 Mon Sep 17 00:00:00 2001 From: Daniel Theophanes Date: Mon, 8 Feb 2016 13:59:12 -0800 Subject: [PATCH] service: add pidfile option --- service.go | 2 ++ service_systemd_linux.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/service.go b/service.go index fcef8020..c01530fe 100644 --- a/service.go +++ b/service.go @@ -81,6 +81,7 @@ const ( optionRunWait = "RunWait" optionReloadSignal = "ReloadSignal" + optionPIDFile = "PIDFile" ) // Config provides the setup for a Service. The Name field is required. @@ -112,6 +113,7 @@ type Config struct { // * POSIX // - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return. // - ReloadSignal string () [USR1, ...] - Signal to send on reaload. + // - PIDFile string () [/run/prog.pid] - Location of the PID file. Option KeyValue } diff --git a/service_systemd_linux.go b/service_systemd_linux.go index 6d7f5907..64a6f73f 100644 --- a/service_systemd_linux.go +++ b/service_systemd_linux.go @@ -81,10 +81,12 @@ func (s *systemd) Install() error { *Config Path string ReloadSignal string + PIDFile string }{ s.Config, path, s.Option.string(optionReloadSignal, ""), + s.Option.string(optionPIDFile, ""), } err = s.template().Execute(f, to) @@ -163,6 +165,7 @@ ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}} {{if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmd}}{{end}} {{if .UserName}}User={{.UserName}}{{end}} {{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}} +{{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}} Restart=always RestartSec=120