From 0e5bec1b9eec14f9070a6f49ad7e0242f1545d66 Mon Sep 17 00:00:00 2001 From: RozenLin Date: Tue, 26 Mar 2019 09:10:25 -0700 Subject: [PATCH] Systemd/dep (#165) * support the dependency config for linux systemd * remote the binary file incorrectly added --- example/logging/main.go | 3 +++ service.go | 8 +++++++- service_systemd_linux.go | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/example/logging/main.go b/example/logging/main.go index b017abd..07e9f06 100644 --- a/example/logging/main.go +++ b/example/logging/main.go @@ -67,6 +67,9 @@ func main() { Name: "GoServiceExampleLogging", DisplayName: "Go Service Example for Logging", Description: "This is an example Go service that outputs log messages.", + Dependencies: []string{ + "Requires=network.target", + "After=network-online.target syslog.target"}, } prg := &program{} diff --git a/service.go b/service.go index 77fa5ae..bcbb38b 100644 --- a/service.go +++ b/service.go @@ -111,7 +111,13 @@ type Config struct { Executable string // Array of service dependencies. - // Not yet implemented on Linux or OS X. + // Not yet fully implemented on Linux or OS X: + // 1. Support linux-systemd dependencies, just put each full line as the + // element of the string array, such as + // "After=network.target syslog.target" + // "Requires=syslog.target" + // Note, such lines will be directly appended into the [Unit] of + // the generated service config file, will not check their correctness. Dependencies []string // The following fields are not supported on Windows. diff --git a/service_systemd_linux.go b/service_systemd_linux.go index 4b57dca..da3ecce 100644 --- a/service_systemd_linux.go +++ b/service_systemd_linux.go @@ -228,6 +228,9 @@ func (s *systemd) Restart() error { const systemdScript = `[Unit] Description={{.Description}} ConditionFileIsExecutable={{.Path|cmdEscape}} +{{range .Dependencies}} +{{.}} +{{end}} [Service] StartLimitInterval=5