stdout/stderr isn't supported by all versions of systemd
This commit is contained in:
committed by
Daniel Theophanes
parent
e5178e50d2
commit
4f2cc00692
@@ -8,7 +8,10 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
@@ -53,6 +56,40 @@ func (s *systemd) configPath() (cp string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *systemd) getSystemdVersion() int64 {
|
||||||
|
out, err := exec.Command("/usr/bin/systemctl", "--version").Output()
|
||||||
|
if err != nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
re := regexp.MustCompile(`systemd ([0-9]+)`)
|
||||||
|
matches := re.FindStringSubmatch(string(out))
|
||||||
|
if len(matches) != 2 {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
v, err := strconv.ParseInt(matches[1], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *systemd) hasOutputFileSupport() bool {
|
||||||
|
defaultValue := true
|
||||||
|
version := s.getSystemdVersion()
|
||||||
|
if version == -1 {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
|
if version < 236 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
func (s *systemd) template() *template.Template {
|
func (s *systemd) template() *template.Template {
|
||||||
customScript := s.Option.string(optionSystemdScript, "")
|
customScript := s.Option.string(optionSystemdScript, "")
|
||||||
|
|
||||||
@@ -86,13 +123,15 @@ func (s *systemd) Install() error {
|
|||||||
|
|
||||||
var to = &struct {
|
var to = &struct {
|
||||||
*Config
|
*Config
|
||||||
Path string
|
Path string
|
||||||
ReloadSignal string
|
HasOutputFileSupport bool
|
||||||
PIDFile string
|
ReloadSignal string
|
||||||
LogOutput bool
|
PIDFile string
|
||||||
|
LogOutput bool
|
||||||
}{
|
}{
|
||||||
s.Config,
|
s.Config,
|
||||||
path,
|
path,
|
||||||
|
s.hasOutputFileSupport(),
|
||||||
s.Option.string(optionReloadSignal, ""),
|
s.Option.string(optionReloadSignal, ""),
|
||||||
s.Option.string(optionPIDFile, ""),
|
s.Option.string(optionPIDFile, ""),
|
||||||
s.Option.bool(optionLogOutput, optionLogOutputDefault),
|
s.Option.bool(optionLogOutput, optionLogOutputDefault),
|
||||||
@@ -175,8 +214,10 @@ ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}}
|
|||||||
{{if .UserName}}User={{.UserName}}{{end}}
|
{{if .UserName}}User={{.UserName}}{{end}}
|
||||||
{{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}}
|
{{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}}
|
||||||
{{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}}
|
{{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}}
|
||||||
{{if .LogOutput}}StandardOutput=file:/var/log/{{.Name}}.out"
|
{{if and .LogOutput .HasOutputFileSupport -}}
|
||||||
StandardError=file:/var/log/{{.Name}}.err{{end}}
|
StandardOutput=file:/var/log/{{.Name}}.out
|
||||||
|
StandardError=file:/var/log/{{.Name}}.err
|
||||||
|
{{- end}}
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=120
|
RestartSec=120
|
||||||
EnvironmentFile=-/etc/sysconfig/{{.Name}}
|
EnvironmentFile=-/etc/sysconfig/{{.Name}}
|
||||||
|
|||||||
Reference in New Issue
Block a user