mirror of
https://github.com/netbirdio/service.git
synced 2026-05-22 17:08:14 -07:00
service: add Config.Executable field to allow service to control other binaries.
This commit is contained in:
+334
-321
File diff suppressed because it is too large
Load Diff
+1
-3
@@ -12,8 +12,6 @@ import (
|
||||
"syscall"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/kardianos/osext"
|
||||
)
|
||||
|
||||
const maxPathSize = 32 * 1024
|
||||
@@ -98,7 +96,7 @@ func (s *darwinLaunchdService) Install() error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
path, err := osext.Executable()
|
||||
path, err := s.execPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
"syscall"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/kardianos/osext"
|
||||
)
|
||||
|
||||
func isSystemd() bool {
|
||||
@@ -75,7 +73,7 @@ func (s *systemd) Install() error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
path, err := osext.Executable()
|
||||
path, err := s.execPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
"syscall"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/kardianos/osext"
|
||||
)
|
||||
|
||||
type sysv struct {
|
||||
@@ -67,7 +65,7 @@ func (s *sysv) Install() error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
path, err := osext.Executable()
|
||||
path, err := s.execPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,12 +8,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/kardianos/osext"
|
||||
)
|
||||
|
||||
func isUpstart() bool {
|
||||
@@ -77,7 +75,7 @@ func (s *upstart) Install() error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
path, err := osext.Executable()
|
||||
path, err := s.execPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -122,7 +120,7 @@ func (s *upstart) Run() (err error) {
|
||||
|
||||
sigChan := make(chan os.Signal, 3)
|
||||
|
||||
signal.Notify(sigChan, syscall.SIGTERM, os.Interrupt)
|
||||
signal.Notify(sigChan, os.Interrupt, os.Kill)
|
||||
|
||||
<-sigChan
|
||||
|
||||
@@ -130,11 +128,11 @@ func (s *upstart) Run() (err error) {
|
||||
}
|
||||
|
||||
func (s *upstart) Start() error {
|
||||
return run("initctl", "start", s.Name)
|
||||
return exec.Command("initctl", "start", s.Name).Run()
|
||||
}
|
||||
|
||||
func (s *upstart) Stop() error {
|
||||
return run("initctl", "stop", s.Name)
|
||||
return exec.Command("initctl", "stop", s.Name).Run()
|
||||
}
|
||||
|
||||
func (s *upstart) Restart() error {
|
||||
|
||||
+2
-2
@@ -16,7 +16,6 @@ import (
|
||||
"code.google.com/p/winsvc/eventlog"
|
||||
"code.google.com/p/winsvc/mgr"
|
||||
"code.google.com/p/winsvc/svc"
|
||||
"github.com/kardianos/osext"
|
||||
)
|
||||
|
||||
const version = "Windows Service"
|
||||
@@ -165,10 +164,11 @@ loop:
|
||||
}
|
||||
|
||||
func (ws *windowsService) Install() error {
|
||||
exepath, err := osext.Executable()
|
||||
exepath, err := ws.execPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
binPath := &bytes.Buffer{}
|
||||
// Quote exe path in case it contains a string.
|
||||
binPath.WriteRune('"')
|
||||
|
||||
Reference in New Issue
Block a user