diff --git a/README.md b/README.md index 2dab8d6..a4ca37a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# service [![GoDoc](https://godoc.org/github.com/kardianos/service?status.svg)](https://godoc.org/github.com/kardianos/service) +# service + +[![GoDoc](https://godoc.org/github.com/kardianos/service?status.svg)](https://godoc.org/github.com/kardianos/service) service will install / un-install, start / stop, and run a program as a service (daemon). Currently supports Windows XP+, Linux/(systemd | Upstart | SysV), and OSX/Launchd. @@ -10,5 +12,6 @@ It also can be used to detect how a program is called, from an interactive terminal or from a service manager. ## BUGS - * Dependencies field is not implemented for Linux systems and Launchd. - * OS X when running as a UserService Interactive will not be accurate. + +- Dependencies field is not implemented for Linux systems and Launchd. +- OS X when running as a UserService Interactive will not be accurate. diff --git a/example/logging/main.go b/example/logging/main.go index 7a60326..01faba4 100644 --- a/example/logging/main.go +++ b/example/logging/main.go @@ -10,13 +10,14 @@ import ( "log" "time" - "github.com/kardianos/service" + "git.company.lan/gopkg/service" ) var logger service.Logger // Program structures. -// Define Start and Stop methods. +// +// Define Start and Stop methods. type program struct { exit chan struct{} } @@ -54,11 +55,12 @@ func (p *program) Stop(s service.Service) error { } // Service setup. -// Define service config. -// Create the service. -// Setup the logger. -// Handle service controls (optional). -// Run the service. +// +// Define service config. +// Create the service. +// Setup the logger. +// Handle service controls (optional). +// Run the service. func main() { svcFlag := flag.String("service", "", "Control the system service.") flag.Parse() diff --git a/example/runner/runner.go b/example/runner/runner.go index 8729cf4..703a94c 100644 --- a/example/runner/runner.go +++ b/example/runner/runner.go @@ -14,7 +14,7 @@ import ( "os/exec" "path/filepath" - "github.com/kardianos/service" + "git.company.lan/gopkg/service" ) // Config is the runner app config structure. diff --git a/example/simple/main.go b/example/simple/main.go index 2ec9f46..420e859 100644 --- a/example/simple/main.go +++ b/example/simple/main.go @@ -8,7 +8,7 @@ package main import ( "log" - "github.com/kardianos/service" + "git.company.lan/gopkg/service" ) var logger service.Logger diff --git a/example/stopPause/main.go b/example/stopPause/main.go index ec7d598..eaeeef4 100644 --- a/example/stopPause/main.go +++ b/example/stopPause/main.go @@ -10,7 +10,7 @@ import ( "os" "time" - "github.com/kardianos/service" + "git.company.lan/gopkg/service" ) var logger service.Logger diff --git a/go.mod b/go.mod index 55e67ea..b552fec 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/kardianos/service +module git.company.lan/gopkg/service go 1.12 diff --git a/service.go b/service.go index 904835e..fe90e67 100644 --- a/service.go +++ b/service.go @@ -18,7 +18,7 @@ // import ( // "log" // -// "github.com/kardianos/service" +// "git.company.lan/gopkg/service" // ) // // var logger service.Logger @@ -59,7 +59,7 @@ // logger.Error(err) // } // } -package service // import "github.com/kardianos/service" +package service // import "git.company.lan/gopkg/service" import ( "errors" @@ -167,42 +167,70 @@ func New(i Interface, c *Config) (Service, error) { } // KeyValue provides a list of system specific options. -// * OS X -// - LaunchdConfig string () - Use custom launchd config. -// - KeepAlive bool (true) - Prevent the system from stopping the service automatically. -// - RunAtLoad bool (false) - Run the service after its job has been loaded. -// - SessionCreate bool (false) - Create a full user session. // -// * Solaris -// - Prefix string ("application") - Service FMRI prefix. +// - OS X // -// * POSIX -// - UserService bool (false) - Install as a current user service. -// - SystemdScript string () - Use custom systemd script. -// - UpstartScript string () - Use custom upstart script. -// - SysvScript string () - Use custom sysv script. -// - OpenRCScript string () - Use custom OpenRC script. -// - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return. -// - ReloadSignal string () [USR1, ...] - Signal to send on reload. -// - PIDFile string () [/run/prog.pid] - Location of the PID file. -// - LogOutput bool (false) - Redirect StdErr & StandardOutPath to files. -// - Restart string (always) - How shall service be restarted. -// - SuccessExitStatus string () - The list of exit status that shall be considered as successful, -// in addition to the default ones. -// - LogDirectory string(/var/log) - The path to the log files directory +// - LaunchdConfig string () - Use custom launchd config. // -// * Linux (systemd) -// - LimitNOFILE int (-1) - Maximum open files (ulimit -n) -// (https://serverfault.com/questions/628610/increasing-nproc-for-processes-launched-by-systemd-on-centos-7) -// * Windows -// - DelayedAutoStart bool (false) - After booting, start this service after some delay. -// - Password string () - Password to use when interfacing with the system service manager. -// - Interactive bool (false) - The service can interact with the desktop. (more information https://docs.microsoft.com/en-us/windows/win32/services/interactive-services) -// - DelayedAutoStart bool (false) - after booting start this service after some delay. -// - StartType string ("automatic") - Start service type. (automatic | manual | disabled) -// - OnFailure string ("restart" ) - Action to perform on service failure. (restart | reboot | noaction) -// - OnFailureDelayDuration string ( "1s" ) - Delay before restarting the service, time.Duration string. -// - OnFailureResetPeriod int ( 10 ) - Reset period for errors, seconds. +// - KeepAlive bool (true) - Prevent the system from stopping the service automatically. +// +// - RunAtLoad bool (false) - Run the service after its job has been loaded. +// +// - SessionCreate bool (false) - Create a full user session. +// +// - Solaris +// +// - Prefix string ("application") - Service FMRI prefix. +// +// - POSIX +// +// - UserService bool (false) - Install as a current user service. +// +// - SystemdScript string () - Use custom systemd script. +// +// - UpstartScript string () - Use custom upstart script. +// +// - SysvScript string () - Use custom sysv script. +// +// - OpenRCScript string () - Use custom OpenRC script. +// +// - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return. +// +// - ReloadSignal string () [USR1, ...] - Signal to send on reload. +// +// - PIDFile string () [/run/prog.pid] - Location of the PID file. +// +// - LogOutput bool (false) - Redirect StdErr & StandardOutPath to files. +// +// - Restart string (always) - How shall service be restarted. +// +// - SuccessExitStatus string () - The list of exit status that shall be considered as successful, +// in addition to the default ones. +// +// - LogDirectory string(/var/log) - The path to the log files directory +// +// - Linux (systemd) +// +// - LimitNOFILE int (-1) - Maximum open files (ulimit -n) +// (https://serverfault.com/questions/628610/increasing-nproc-for-processes-launched-by-systemd-on-centos-7) +// +// - Windows +// +// - DelayedAutoStart bool (false) - After booting, start this service after some delay. +// +// - Password string () - Password to use when interfacing with the system service manager. +// +// - Interactive bool (false) - The service can interact with the desktop. (more information https://docs.microsoft.com/en-us/windows/win32/services/interactive-services) +// +// - DelayedAutoStart bool (false) - after booting start this service after some delay. +// +// - StartType string ("automatic") - Start service type. (automatic | manual | disabled) +// +// - OnFailure string ("restart" ) - Action to perform on service failure. (restart | reboot | noaction) +// +// - OnFailureDelayDuration string ( "1s" ) - Delay before restarting the service, time.Duration string. +// +// - OnFailureResetPeriod int ( 10 ) - Reset period for errors, seconds. type KeyValue map[string]interface{} // bool returns the value of the given name, assuming the value is a boolean. @@ -325,16 +353,16 @@ type System interface { // Interface represents the service interface for a program. Start runs before // the hosting process is granted control and Stop runs when control is returned. // -// 1. OS service manager executes user program. -// 2. User program sees it is executed from a service manager (IsInteractive is false). -// 3. User program calls Service.Run() which blocks. -// 4. Interface.Start() is called and quickly returns. -// 5. User program runs. -// 6. OS service manager signals the user program to stop. -// 7. Interface.Stop() is called and quickly returns. -// - For a successful exit, os.Exit should not be called in Interface.Stop(). -// 8. Service.Run returns. -// 9. User program should quickly exit. +// 1. OS service manager executes user program. +// 2. User program sees it is executed from a service manager (IsInteractive is false). +// 3. User program calls Service.Run() which blocks. +// 4. Interface.Start() is called and quickly returns. +// 5. User program runs. +// 6. OS service manager signals the user program to stop. +// 7. Interface.Stop() is called and quickly returns. +// - For a successful exit, os.Exit should not be called in Interface.Stop(). +// 8. Service.Run returns. +// 9. User program should quickly exit. type Interface interface { // Start provides a place to initiate the service. The service doesn't // signal a completed start until after this function returns, so the diff --git a/service_su_test.go b/service_su_test.go index 74eca3d..dbaa351 100644 --- a/service_su_test.go +++ b/service_su_test.go @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. // This needs to be run as root/admin hence the reason there is a build tag +//go:build su // +build su package service_test @@ -18,7 +19,7 @@ import ( "testing" "time" - "github.com/kardianos/service" + "git.company.lan/gopkg/service" ) const runAsServiceArg = "RunThisAsService" diff --git a/service_test.go b/service_test.go index 886b0cf..8613c85 100644 --- a/service_test.go +++ b/service_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/kardianos/service" + "git.company.lan/gopkg/service" ) func TestRunInterrupt(t *testing.T) {