From 127cca0c83d9afc95c6957c5745d36e770e0d19b Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 8 Oct 2019 12:29:11 +0300 Subject: [PATCH] * systemd service file: fix boot priority: start AGH after network is online --- home/service.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/home/service.go b/home/service.go index 2daf0618..638be158 100644 --- a/home/service.go +++ b/home/service.go @@ -139,6 +139,10 @@ func configureService(c *service.Config) { // POSIX // Redirect StdErr & StdOut to files. c.Option["LogOutput"] = true + + // Add "After=" setting for systemd service file, because we must be started only after network is online + // Set "RestartSec" to 10 + c.Option["SystemdScript"] = systemdScript } // cleanupService called on the service uninstall, cleans up additional files if needed @@ -185,3 +189,30 @@ var launchdConfig = ` ` + +// Note: we should keep it in sync with the template from service_systemd_linux.go file +const systemdScript = `[Unit] +Description={{.Description}} +ConditionFileIsExecutable={{.Path|cmdEscape}} +After=syslog.target network-online.target + +[Service] +StartLimitInterval=5 +StartLimitBurst=10 +ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}} +{{if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{end}} +{{if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{end}} +{{if .UserName}}User={{.UserName}}{{end}} +{{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}} +{{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}} +{{if and .LogOutput .HasOutputFileSupport -}} +StandardOutput=file:/var/log/{{.Name}}.out +StandardError=file:/var/log/{{.Name}}.err +{{- end}} +Restart=always +RestartSec=10 +EnvironmentFile=-/etc/sysconfig/{{.Name}} + +[Install] +WantedBy=multi-user.target +`