From 96580943daba9cc55f29b9e569b60980d2dd1627 Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Thu, 14 Apr 2016 23:55:40 +0600 Subject: [PATCH] added args property which able to use command install with args --- daemon.go | 2 +- daemon_darwin.go | 7 +++++-- daemon_linux_systemd.go | 10 ++++++++-- daemon_linux_systemv.go | 9 +++++---- daemon_windows.go | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/daemon.go b/daemon.go index a32f16e..8908bdc 100644 --- a/daemon.go +++ b/daemon.go @@ -161,7 +161,7 @@ import "strings" type Daemon interface { // Install the service into the system - Install() (string, error) + Install(args ...string) (string, error) // Remove the service and all corresponded files from the system Remove() (string, error) diff --git a/daemon_darwin.go b/daemon_darwin.go index c4109b5..f5ea59c 100644 --- a/daemon_darwin.go +++ b/daemon_darwin.go @@ -63,7 +63,7 @@ func (darwin *darwinRecord) checkRunning() (string, bool) { } // Install the service -func (darwin *darwinRecord) Install() (string, error) { +func (darwin *darwinRecord) Install(args ...string) (string, error) { installAction := "Install " + darwin.description + ":" if ok, err := checkPrivileges(); !ok { @@ -96,7 +96,8 @@ func (darwin *darwinRecord) Install() (string, error) { file, &struct { Name, Path string - }{darwin.name, execPatch}, + Args []string + }{darwin.name, execPatch, args}, ); err != nil { return installAction + failed, err } @@ -196,6 +197,8 @@ var propertyList = ` ProgramArguments {{.Path}} + {{range .Args}}{{.}} + {{end}} RunAtLoad diff --git a/daemon_linux_systemd.go b/daemon_linux_systemd.go index 6c6c0a5..079a3c1 100644 --- a/daemon_linux_systemd.go +++ b/daemon_linux_systemd.go @@ -52,7 +52,7 @@ func (linux *systemDRecord) checkRunning() (string, bool) { } // Install the service -func (linux *systemDRecord) Install() (string, error) { +func (linux *systemDRecord) Install(args ...string) (string, error) { installAction := "Install " + linux.description + ":" if ok, err := checkPrivileges(); !ok { @@ -81,11 +81,17 @@ func (linux *systemDRecord) Install() (string, error) { return installAction + failed, err } + path := append([]string{execPatch}, args...) if err := templ.Execute( file, &struct { Name, Description, Dependencies, Path string - }{linux.name, linux.description, strings.Join(linux.dependencies, " "), execPatch}, + }{ + linux.name, + linux.description, + strings.Join(linux.dependencies, " "), + strings.Join(path, " "), + }, ); err != nil { return installAction + failed, err } diff --git a/daemon_linux_systemv.go b/daemon_linux_systemv.go index a7c0fd5..ea2dd1d 100644 --- a/daemon_linux_systemv.go +++ b/daemon_linux_systemv.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "regexp" + "strings" "text/template" ) @@ -51,7 +52,7 @@ func (linux *systemVRecord) checkRunning() (string, bool) { } // Install the service -func (linux *systemVRecord) Install() (string, error) { +func (linux *systemVRecord) Install(args ...string) (string, error) { installAction := "Install " + linux.description + ":" if ok, err := checkPrivileges(); !ok { @@ -83,8 +84,8 @@ func (linux *systemVRecord) Install() (string, error) { if err := templ.Execute( file, &struct { - Name, Description, Path string - }{linux.name, linux.description, execPatch}, + Name, Description, Path, Args string + }{linux.name, linux.description, execPatch, strings.Join(args, " ")}, ); err != nil { return installAction + failed, err } @@ -244,7 +245,7 @@ start() { if ! [ -f $pidfile ]; then printf "Starting $servname:\t" echo "$(date)" >> $stdoutlog - $exec >> $stdoutlog 2>> $stderrlog & + $exec {{.Args}} >> $stdoutlog 2>> $stderrlog & echo $! > $pidfile touch $lockfile success diff --git a/daemon_windows.go b/daemon_windows.go index 805ee18..c6515be 100644 --- a/daemon_windows.go +++ b/daemon_windows.go @@ -24,7 +24,7 @@ func newDaemon(name, description string, dependencies []string) (Daemon, error) } // Install the service -func (windows *windowsRecord) Install() (string, error) { +func (windows *windowsRecord) Install(args ...string) (string, error) { installAction := "Install " + windows.description + ":" return installAction + failed, ErrWindowsUnsupported