This commit is contained in:
2024-04-03 20:39:20 +03:00
parent 9832e01049
commit 0811cea833
9 changed files with 95 additions and 61 deletions
+6 -3
View File
@@ -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). 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. 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. terminal or from a service manager.
## BUGS ## 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.
+3 -1
View File
@@ -10,12 +10,13 @@ import (
"log" "log"
"time" "time"
"github.com/kardianos/service" "git.company.lan/gopkg/service"
) )
var logger service.Logger var logger service.Logger
// Program structures. // Program structures.
//
// Define Start and Stop methods. // Define Start and Stop methods.
type program struct { type program struct {
exit chan struct{} exit chan struct{}
@@ -54,6 +55,7 @@ func (p *program) Stop(s service.Service) error {
} }
// Service setup. // Service setup.
//
// Define service config. // Define service config.
// Create the service. // Create the service.
// Setup the logger. // Setup the logger.
+1 -1
View File
@@ -14,7 +14,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"github.com/kardianos/service" "git.company.lan/gopkg/service"
) )
// Config is the runner app config structure. // Config is the runner app config structure.
+1 -1
View File
@@ -8,7 +8,7 @@ package main
import ( import (
"log" "log"
"github.com/kardianos/service" "git.company.lan/gopkg/service"
) )
var logger service.Logger var logger service.Logger
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"os" "os"
"time" "time"
"github.com/kardianos/service" "git.company.lan/gopkg/service"
) )
var logger service.Logger var logger service.Logger
+1 -1
View File
@@ -1,4 +1,4 @@
module github.com/kardianos/service module git.company.lan/gopkg/service
go 1.12 go 1.12
+35 -7
View File
@@ -18,7 +18,7 @@
// import ( // import (
// "log" // "log"
// //
// "github.com/kardianos/service" // "git.company.lan/gopkg/service"
// ) // )
// //
// var logger service.Logger // var logger service.Logger
@@ -59,7 +59,7 @@
// logger.Error(err) // logger.Error(err)
// } // }
// } // }
package service // import "github.com/kardianos/service" package service // import "git.company.lan/gopkg/service"
import ( import (
"errors" "errors"
@@ -167,41 +167,69 @@ func New(i Interface, c *Config) (Service, error) {
} }
// KeyValue provides a list of system specific options. // KeyValue provides a list of system specific options.
// * OS X //
// - OS X
//
// - LaunchdConfig string () - Use custom launchd config. // - LaunchdConfig string () - Use custom launchd config.
//
// - KeepAlive bool (true) - Prevent the system from stopping the service automatically. // - KeepAlive bool (true) - Prevent the system from stopping the service automatically.
//
// - RunAtLoad bool (false) - Run the service after its job has been loaded. // - RunAtLoad bool (false) - Run the service after its job has been loaded.
//
// - SessionCreate bool (false) - Create a full user session. // - SessionCreate bool (false) - Create a full user session.
// //
// * Solaris // - Solaris
//
// - Prefix string ("application") - Service FMRI prefix. // - Prefix string ("application") - Service FMRI prefix.
// //
// * POSIX // - POSIX
//
// - UserService bool (false) - Install as a current user service. // - UserService bool (false) - Install as a current user service.
//
// - SystemdScript string () - Use custom systemd script. // - SystemdScript string () - Use custom systemd script.
//
// - UpstartScript string () - Use custom upstart script. // - UpstartScript string () - Use custom upstart script.
//
// - SysvScript string () - Use custom sysv script. // - SysvScript string () - Use custom sysv script.
//
// - OpenRCScript string () - Use custom OpenRC script. // - OpenRCScript string () - Use custom OpenRC script.
//
// - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return. // - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return.
//
// - ReloadSignal string () [USR1, ...] - Signal to send on reload. // - ReloadSignal string () [USR1, ...] - Signal to send on reload.
//
// - PIDFile string () [/run/prog.pid] - Location of the PID file. // - PIDFile string () [/run/prog.pid] - Location of the PID file.
//
// - LogOutput bool (false) - Redirect StdErr & StandardOutPath to files. // - LogOutput bool (false) - Redirect StdErr & StandardOutPath to files.
//
// - Restart string (always) - How shall service be restarted. // - Restart string (always) - How shall service be restarted.
//
// - SuccessExitStatus string () - The list of exit status that shall be considered as successful, // - SuccessExitStatus string () - The list of exit status that shall be considered as successful,
// in addition to the default ones. // in addition to the default ones.
//
// - LogDirectory string(/var/log) - The path to the log files directory // - LogDirectory string(/var/log) - The path to the log files directory
// //
// * Linux (systemd) // - Linux (systemd)
//
// - LimitNOFILE int (-1) - Maximum open files (ulimit -n) // - LimitNOFILE int (-1) - Maximum open files (ulimit -n)
// (https://serverfault.com/questions/628610/increasing-nproc-for-processes-launched-by-systemd-on-centos-7) // (https://serverfault.com/questions/628610/increasing-nproc-for-processes-launched-by-systemd-on-centos-7)
// * Windows //
// - Windows
//
// - DelayedAutoStart bool (false) - After booting, start this service after some delay. // - DelayedAutoStart bool (false) - After booting, start this service after some delay.
//
// - Password string () - Password to use when interfacing with the system service manager. // - 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) // - 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. // - DelayedAutoStart bool (false) - after booting start this service after some delay.
//
// - StartType string ("automatic") - Start service type. (automatic | manual | disabled) // - StartType string ("automatic") - Start service type. (automatic | manual | disabled)
//
// - OnFailure string ("restart" ) - Action to perform on service failure. (restart | reboot | noaction) // - OnFailure string ("restart" ) - Action to perform on service failure. (restart | reboot | noaction)
//
// - OnFailureDelayDuration string ( "1s" ) - Delay before restarting the service, time.Duration string. // - OnFailureDelayDuration string ( "1s" ) - Delay before restarting the service, time.Duration string.
//
// - OnFailureResetPeriod int ( 10 ) - Reset period for errors, seconds. // - OnFailureResetPeriod int ( 10 ) - Reset period for errors, seconds.
type KeyValue map[string]interface{} type KeyValue map[string]interface{}
+2 -1
View File
@@ -3,6 +3,7 @@
// license that can be found in the LICENSE file. // 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 // This needs to be run as root/admin hence the reason there is a build tag
//go:build su
// +build su // +build su
package service_test package service_test
@@ -18,7 +19,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/kardianos/service" "git.company.lan/gopkg/service"
) )
const runAsServiceArg = "RunThisAsService" const runAsServiceArg = "RunThisAsService"
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/kardianos/service" "git.company.lan/gopkg/service"
) )
func TestRunInterrupt(t *testing.T) { func TestRunInterrupt(t *testing.T) {