add support for overriding service templates at runtime
This commit is contained in:
committed by
Daniel Theophanes
parent
994866c14a
commit
e5178e50d2
+16
-7
@@ -81,6 +81,11 @@ const (
|
|||||||
optionRunWait = "RunWait"
|
optionRunWait = "RunWait"
|
||||||
optionReloadSignal = "ReloadSignal"
|
optionReloadSignal = "ReloadSignal"
|
||||||
optionPIDFile = "PIDFile"
|
optionPIDFile = "PIDFile"
|
||||||
|
|
||||||
|
optionSystemdScript = "SystemdScript"
|
||||||
|
optionSysvScript = "SysvScript"
|
||||||
|
optionUpstartScript = "UpstartScript"
|
||||||
|
optionLaunchdConfig = "LaunchdConfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config provides the setup for a Service. The Name field is required.
|
// Config provides the setup for a Service. The Name field is required.
|
||||||
@@ -105,15 +110,19 @@ type Config struct {
|
|||||||
|
|
||||||
// System specific options.
|
// System specific options.
|
||||||
// * OS X
|
// * OS X
|
||||||
// - KeepAlive bool (true)
|
// - LaunchdConfig string () - Use custom launchd config
|
||||||
// - RunAtLoad bool (false)
|
// - KeepAlive bool (true)
|
||||||
// - UserService bool (false) - Install as a current user service.
|
// - RunAtLoad bool (false)
|
||||||
// - SessionCreate bool (false) - Create a full user session.
|
// - UserService bool (false) - Install as a current user service.
|
||||||
|
// - SessionCreate bool (false) - Create a full user session.
|
||||||
// * POSIX
|
// * POSIX
|
||||||
// - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return.
|
// - SystemdScript string () - Use custom systemd script
|
||||||
// - ReloadSignal string () [USR1, ...] - Signal to send on reaload.
|
// - UpstartScript string () - Use custom upstart script
|
||||||
|
// - SysvScript string () - Use custom sysv script
|
||||||
|
// - 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.
|
// - PIDFile string () [/run/prog.pid] - Location of the PID file.
|
||||||
// - LogOutput bool (false) - Redirect StdErr & StdOut to files.
|
// - LogOutput bool (false) - Redirect StdErr & StdOut to files.
|
||||||
Option KeyValue
|
Option KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-10
@@ -100,6 +100,25 @@ func (s *darwinLaunchdService) getServiceFilePath() (string, error) {
|
|||||||
return "/Library/LaunchDaemons/" + s.Name + ".plist", nil
|
return "/Library/LaunchDaemons/" + s.Name + ".plist", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *darwinLaunchdService) template() *template.Template {
|
||||||
|
functions := template.FuncMap{
|
||||||
|
"bool": func(v bool) string {
|
||||||
|
if v {
|
||||||
|
return "true"
|
||||||
|
}
|
||||||
|
return "false"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
customConfig := s.Option.string(optionLaunchdConfig, "")
|
||||||
|
|
||||||
|
if customConfig != "" {
|
||||||
|
return template.Must(template.New("").Funcs(functions).Parse(customConfig))
|
||||||
|
} else {
|
||||||
|
return template.Must(template.New("").Funcs(functions).Parse(launchdConfig))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *darwinLaunchdService) Install() error {
|
func (s *darwinLaunchdService) Install() error {
|
||||||
confPath, err := s.getServiceFilePath()
|
confPath, err := s.getServiceFilePath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -143,16 +162,7 @@ func (s *darwinLaunchdService) Install() error {
|
|||||||
SessionCreate: s.Option.bool(optionSessionCreate, optionSessionCreateDefault),
|
SessionCreate: s.Option.bool(optionSessionCreate, optionSessionCreateDefault),
|
||||||
}
|
}
|
||||||
|
|
||||||
functions := template.FuncMap{
|
return s.template().Execute(f, to)
|
||||||
"bool": func(v bool) string {
|
|
||||||
if v {
|
|
||||||
return "true"
|
|
||||||
}
|
|
||||||
return "false"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
t := template.Must(template.New("launchdConfig").Funcs(functions).Parse(launchdConfig))
|
|
||||||
return t.Execute(f, to)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *darwinLaunchdService) Uninstall() error {
|
func (s *darwinLaunchdService) Uninstall() error {
|
||||||
|
|||||||
@@ -52,8 +52,15 @@ func (s *systemd) configPath() (cp string, err error) {
|
|||||||
cp = "/etc/systemd/system/" + s.Config.Name + ".service"
|
cp = "/etc/systemd/system/" + s.Config.Name + ".service"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemd) template() *template.Template {
|
func (s *systemd) template() *template.Template {
|
||||||
return template.Must(template.New("").Funcs(tf).Parse(systemdScript))
|
customScript := s.Option.string(optionSystemdScript, "")
|
||||||
|
|
||||||
|
if customScript != "" {
|
||||||
|
return template.Must(template.New("").Funcs(tf).Parse(customScript))
|
||||||
|
} else {
|
||||||
|
return template.Must(template.New("").Funcs(tf).Parse(systemdScript))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemd) Install() error {
|
func (s *systemd) Install() error {
|
||||||
|
|||||||
@@ -45,8 +45,15 @@ func (s *sysv) configPath() (cp string, err error) {
|
|||||||
cp = "/etc/init.d/" + s.Config.Name
|
cp = "/etc/init.d/" + s.Config.Name
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sysv) template() *template.Template {
|
func (s *sysv) template() *template.Template {
|
||||||
return template.Must(template.New("").Funcs(tf).Parse(sysvScript))
|
customScript := s.Option.string(optionSysvScript, "")
|
||||||
|
|
||||||
|
if customScript != "" {
|
||||||
|
return template.Must(template.New("").Funcs(tf).Parse(customScript))
|
||||||
|
} else {
|
||||||
|
return template.Must(template.New("").Funcs(tf).Parse(sysvScript))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sysv) Install() error {
|
func (s *sysv) Install() error {
|
||||||
|
|||||||
@@ -111,7 +111,13 @@ func (s *upstart) getUpstartVersion() []int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *upstart) template() *template.Template {
|
func (s *upstart) template() *template.Template {
|
||||||
return template.Must(template.New("").Funcs(tf).Parse(upstartScript))
|
customScript := s.Option.string(optionUpstartScript, "")
|
||||||
|
|
||||||
|
if customScript != "" {
|
||||||
|
return template.Must(template.New("").Funcs(tf).Parse(customScript))
|
||||||
|
} else {
|
||||||
|
return template.Must(template.New("").Funcs(tf).Parse(upstartScript))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *upstart) Install() error {
|
func (s *upstart) Install() error {
|
||||||
|
|||||||
Reference in New Issue
Block a user