Skip to content

Commit

Permalink
added args property which able to use command install with args
Browse files Browse the repository at this point in the history
  • Loading branch information
takama committed Apr 14, 2016
1 parent 38d837d commit 9658094
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions daemon_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -196,6 +197,8 @@ var propertyList = `<?xml version="1.0" encoding="UTF-8"?>
<key>ProgramArguments</key>
<array>
<string>{{.Path}}</string>
{{range .Args}}<string>{{.}}</string>
{{end}}
</array>
<key>RunAtLoad</key>
<true/>
Expand Down
10 changes: 8 additions & 2 deletions daemon_linux_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions daemon_linux_systemv.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"regexp"
"strings"
"text/template"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion daemon_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9658094

Please sign in to comment.