From 2eba2e6b2eef0172bb65c0360f3214dcd599914e Mon Sep 17 00:00:00 2001 From: King'ori Maina Date: Thu, 16 Apr 2020 10:31:17 +0300 Subject: [PATCH 01/11] Add kind field to records to set the kind of daemon Allow one to choose they kind of daemon that they want to create. --- daemon.go | 9 +++++++-- daemon_darwin.go | 5 +++-- daemon_freebsd.go | 5 +++-- daemon_linux.go | 8 ++++---- daemon_linux_systemd.go | 1 + daemon_linux_systemv.go | 1 + daemon_linux_upstart.go | 1 + daemon_windows.go | 5 +++-- 8 files changed, 23 insertions(+), 12 deletions(-) diff --git a/daemon.go b/daemon.go index 229d947..1dd122b 100644 --- a/daemon.go +++ b/daemon.go @@ -199,11 +199,16 @@ type Executable interface { Run() } +// Kind is type of the daemon +type Kind string + // New - Create a new daemon // // name: name of the service // // description: any explanation, what is the service, its purpose -func New(name, description string, dependencies ...string) (Daemon, error) { - return newDaemon(strings.Join(strings.Fields(name), "_"), description, dependencies) +// +// kind: what kind of daemon to create +func New(name, description string, kind Kind, dependencies ...string) (Daemon, error) { + return newDaemon(strings.Join(strings.Fields(name), "_"), description, kind, dependencies) } diff --git a/daemon_darwin.go b/daemon_darwin.go index 7fa2b4e..bc15c64 100644 --- a/daemon_darwin.go +++ b/daemon_darwin.go @@ -17,12 +17,13 @@ import ( type darwinRecord struct { name string description string + kind Kind dependencies []string } -func newDaemon(name, description string, dependencies []string) (Daemon, error) { +func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { - return &darwinRecord{name, description, dependencies}, nil + return &darwinRecord{name, description, kind, dependencies}, nil } // Standard service path for system daemons diff --git a/daemon_freebsd.go b/daemon_freebsd.go index c39e046..e3995fe 100644 --- a/daemon_freebsd.go +++ b/daemon_freebsd.go @@ -15,6 +15,7 @@ import ( type bsdRecord struct { name string description string + kind Kind dependencies []string } @@ -66,8 +67,8 @@ func (bsd *bsdRecord) getCmd(cmd string) string { } // Get the daemon properly -func newDaemon(name, description string, dependencies []string) (Daemon, error) { - return &bsdRecord{name, description, dependencies}, nil +func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { + return &bsdRecord{name, description, kind, dependencies}, nil } func execPath() (name string, err error) { diff --git a/daemon_linux.go b/daemon_linux.go index 633f20c..6dbcd87 100644 --- a/daemon_linux.go +++ b/daemon_linux.go @@ -10,15 +10,15 @@ import ( ) // Get the daemon properly -func newDaemon(name, description string, dependencies []string) (Daemon, error) { +func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { // newer subsystem must be checked first if _, err := os.Stat("/run/systemd/system"); err == nil { - return &systemDRecord{name, description, dependencies}, nil + return &systemDRecord{name, description, kind, dependencies}, nil } if _, err := os.Stat("/sbin/initctl"); err == nil { - return &upstartRecord{name, description, dependencies}, nil + return &upstartRecord{name, description, kind, dependencies}, nil } - return &systemVRecord{name, description, dependencies}, nil + return &systemVRecord{name, description, kind, dependencies}, nil } // Get executable path diff --git a/daemon_linux_systemd.go b/daemon_linux_systemd.go index f7a8ebc..21c4384 100644 --- a/daemon_linux_systemd.go +++ b/daemon_linux_systemd.go @@ -16,6 +16,7 @@ import ( type systemDRecord struct { name string description string + kind Kind dependencies []string } diff --git a/daemon_linux_systemv.go b/daemon_linux_systemv.go index 0c1cb17..34cc6ab 100644 --- a/daemon_linux_systemv.go +++ b/daemon_linux_systemv.go @@ -16,6 +16,7 @@ import ( type systemVRecord struct { name string description string + kind Kind dependencies []string } diff --git a/daemon_linux_upstart.go b/daemon_linux_upstart.go index ab870b7..fdaab4d 100644 --- a/daemon_linux_upstart.go +++ b/daemon_linux_upstart.go @@ -16,6 +16,7 @@ import ( type upstartRecord struct { name string description string + kind Kind dependencies []string } diff --git a/daemon_windows.go b/daemon_windows.go index bb37ba0..b7ddace 100644 --- a/daemon_windows.go +++ b/daemon_windows.go @@ -24,12 +24,13 @@ import ( type windowsRecord struct { name string description string + kind Kind dependencies []string } -func newDaemon(name, description string, dependencies []string) (Daemon, error) { +func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { - return &windowsRecord{name, description, dependencies}, nil + return &windowsRecord{name, description, kind, dependencies}, nil } // Install the service From f5e82a501ed6057a222170544c070979268e25cf Mon Sep 17 00:00:00 2001 From: King'ori Maina Date: Thu, 16 Apr 2020 10:36:40 +0300 Subject: [PATCH 02/11] Add applicable kind of daemons per operating system Current support is only for the GlobalDaemon kind across all operating systems. --- daemon_darwin.go | 6 ++++++ daemon_freebsd.go | 6 ++++++ daemon_linux.go | 6 ++++++ daemon_windows.go | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/daemon_darwin.go b/daemon_darwin.go index bc15c64..7014618 100644 --- a/daemon_darwin.go +++ b/daemon_darwin.go @@ -21,6 +21,12 @@ type darwinRecord struct { dependencies []string } +const ( + // GlobalDaemon is a user daemon that runs as the root user. In other words, + // system-wide daemons provided by the administrator. + GlobalDaemon Kind = "GlobalDaemon" +) + func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { return &darwinRecord{name, description, kind, dependencies}, nil diff --git a/daemon_freebsd.go b/daemon_freebsd.go index e3995fe..521a41e 100644 --- a/daemon_freebsd.go +++ b/daemon_freebsd.go @@ -19,6 +19,12 @@ type bsdRecord struct { dependencies []string } +const ( + // GlobalDaemon is a user daemon that runs as the root user. In other words, + // system-wide daemons provided by the administrator. + GlobalDaemon Kind = "GlobalDaemon" +) + // Standard service path for systemV daemons func (bsd *bsdRecord) servicePath() string { return "/usr/local/etc/rc.d/" + bsd.name diff --git a/daemon_linux.go b/daemon_linux.go index 6dbcd87..1221cae 100644 --- a/daemon_linux.go +++ b/daemon_linux.go @@ -9,6 +9,12 @@ import ( "os" ) +const ( + // GlobalDaemon is a user daemon that runs as the root user. In other words, + // system-wide daemons provided by the administrator. + GlobalDaemon Kind = "GlobalDaemon" +) + // Get the daemon properly func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { // newer subsystem must be checked first diff --git a/daemon_windows.go b/daemon_windows.go index b7ddace..ebd3c54 100644 --- a/daemon_windows.go +++ b/daemon_windows.go @@ -28,6 +28,12 @@ type windowsRecord struct { dependencies []string } +const ( + // GlobalDaemon is a user daemon that runs as the root user. In other words, + // system-wide daemons provided by the administrator. + GlobalDaemon Kind = "GlobalDaemon" +) + func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { return &windowsRecord{name, description, kind, dependencies}, nil From 80558eaae7525ad15932dc52d253a9c95023b8d3 Mon Sep 17 00:00:00 2001 From: King'ori Maina Date: Thu, 16 Apr 2020 12:00:38 +0300 Subject: [PATCH 03/11] Add support for per-user agents provided by the user and administrator * UserAgent - added by the user to run as the user. * GlobalAgent - added by an administrator to run for all users but as the logged in user. --- README.md | 4 ++-- daemon.go | 12 +++++++----- daemon_darwin.go | 41 ++++++++++++++++++++++++++++++++------- examples/cron/cron_job.go | 2 +- examples/myservice.go | 2 +- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index abb8dda..fc2313f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ import ( ) func main() { - service, err := daemon.New("name", "description") + service, err := daemon.New("name", "description", daemon.GlobalDaemon) if err != nil { log.Fatal("Error: ", err) } @@ -159,7 +159,7 @@ func init() { } func main() { - srv, err := daemon.New(name, description, dependencies...) + srv, err := daemon.New(name, description, daemon.GlobalDaemon, dependencies...) if err != nil { errlog.Println("Error: ", err) os.Exit(1) diff --git a/daemon.go b/daemon.go index 1dd122b..d654c32 100644 --- a/daemon.go +++ b/daemon.go @@ -5,10 +5,12 @@ /* Package daemon v0.12.0 for use with Go (golang) services. -Package daemon provides primitives for daemonization of golang services. -This package is not provide implementation of user daemon, -accordingly must have root rights to install/remove service. -In the current implementation is only supported Linux and Mac Os X daemon. +Package daemon provides primitives for daemonization of golang services. In the +current implementation the only supported operating systems are macOS, FreeBSD, +Linux and Windows. Also to note, for global daemons one must have root rights to +install or remove the service. The only exception is macOS where there is an +implementation of a user daemon that can installed or removed by the current +user. Example: @@ -137,7 +139,7 @@ Example: } func main() { - srv, err := daemon.New(name, description, dependencies...) + srv, err := daemon.New(name, description, daemon.GlobalDaemon, dependencies...) if err != nil { errlog.Println("Error: ", err) os.Exit(1) diff --git a/daemon_darwin.go b/daemon_darwin.go index 7014618..1091f4d 100644 --- a/daemon_darwin.go +++ b/daemon_darwin.go @@ -22,7 +22,18 @@ type darwinRecord struct { } const ( - // GlobalDaemon is a user daemon that runs as the root user. In other words, + // UserAgent is a user daemon that runs as the currently logged in user and + // stores its property list in the user’s individual LaunchAgents directory. + // In other words, per-user agents provided by the user. + UserAgent Kind = "UserAgent" + + // GlobalAgent is a user daemon that runs as the currently logged in user and + // stores its property list in the users' global LaunchAgents directory. In + // other words, per-user agents provided by the administrator. + GlobalAgent Kind = "GlobalAgent" + + // GlobalDaemon is a system daemon that runs as the root user and stores its + // property list in the global LaunchDaemons directory. In other words, // system-wide daemons provided by the administrator. GlobalDaemon Kind = "GlobalDaemon" ) @@ -34,7 +45,18 @@ func newDaemon(name, description string, kind Kind, dependencies []string) (Daem // Standard service path for system daemons func (darwin *darwinRecord) servicePath() string { - return "/Library/LaunchDaemons/" + darwin.name + ".plist" + var path string + + switch darwin.kind { + case UserAgent: + path = "~/Library/LaunchAgents" + darwin.name + ".plist" + case GlobalAgent: + path = "/Library/LaunchAgents/" + darwin.name + ".plist" + case GlobalDaemon: + path = "/Library/LaunchDaemons/" + darwin.name + ".plist" + } + + return path } // Is a service installed @@ -73,7 +95,8 @@ func (darwin *darwinRecord) checkRunning() (string, bool) { func (darwin *darwinRecord) Install(args ...string) (string, error) { installAction := "Install " + darwin.description + ":" - if ok, err := checkPrivileges(); !ok { + ok, err := checkPrivileges() + if !ok && darwin.kind != UserAgent { return installAction + failed, err } @@ -116,7 +139,8 @@ func (darwin *darwinRecord) Install(args ...string) (string, error) { func (darwin *darwinRecord) Remove() (string, error) { removeAction := "Removing " + darwin.description + ":" - if ok, err := checkPrivileges(); !ok { + ok, err := checkPrivileges() + if !ok && darwin.kind != UserAgent { return removeAction + failed, err } @@ -135,7 +159,8 @@ func (darwin *darwinRecord) Remove() (string, error) { func (darwin *darwinRecord) Start() (string, error) { startAction := "Starting " + darwin.description + ":" - if ok, err := checkPrivileges(); !ok { + ok, err := checkPrivileges() + if !ok && darwin.kind != UserAgent { return startAction + failed, err } @@ -158,7 +183,8 @@ func (darwin *darwinRecord) Start() (string, error) { func (darwin *darwinRecord) Stop() (string, error) { stopAction := "Stopping " + darwin.description + ":" - if ok, err := checkPrivileges(); !ok { + ok, err := checkPrivileges() + if !ok && darwin.kind != UserAgent { return stopAction + failed, err } @@ -180,7 +206,8 @@ func (darwin *darwinRecord) Stop() (string, error) { // Status - Get service status func (darwin *darwinRecord) Status() (string, error) { - if ok, err := checkPrivileges(); !ok { + ok, err := checkPrivileges() + if !ok && darwin.kind != UserAgent { return "", err } diff --git a/examples/cron/cron_job.go b/examples/cron/cron_job.go index 7102297..826ca1f 100644 --- a/examples/cron/cron_job.go +++ b/examples/cron/cron_job.go @@ -80,7 +80,7 @@ func init() { } func main() { - srv, err := daemon.New(name, description) + srv, err := daemon.New(name, description, daemon.GlobalDaemon) if err != nil { errlog.Println("Error: ", err) os.Exit(1) diff --git a/examples/myservice.go b/examples/myservice.go index bf0f5da..7f4dee6 100644 --- a/examples/myservice.go +++ b/examples/myservice.go @@ -120,7 +120,7 @@ func init() { } func main() { - srv, err := daemon.New(name, description, dependencies...) + srv, err := daemon.New(name, description, daemon.GlobalDaemon, dependencies...) if err != nil { errlog.Println("Error: ", err) os.Exit(1) From 83604cfc812fff3c5352395742615d569e4853be Mon Sep 17 00:00:00 2001 From: King'ori Maina Date: Thu, 16 Apr 2020 12:41:58 +0300 Subject: [PATCH 04/11] Expand ~ to user's home directory https://stackoverflow.com/questions/17609732/expand-tilde-to-home-directory --- daemon_darwin.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/daemon_darwin.go b/daemon_darwin.go index 1091f4d..d0ce369 100644 --- a/daemon_darwin.go +++ b/daemon_darwin.go @@ -8,6 +8,7 @@ package daemon import ( "os" "os/exec" + "os/user" "path/filepath" "regexp" "text/template" @@ -49,7 +50,8 @@ func (darwin *darwinRecord) servicePath() string { switch darwin.kind { case UserAgent: - path = "~/Library/LaunchAgents" + darwin.name + ".plist" + usr, _ := user.Current() + path = usr.HomeDir + "/Library/LaunchAgents/" + darwin.name + ".plist" case GlobalAgent: path = "/Library/LaunchAgents/" + darwin.name + ".plist" case GlobalDaemon: From 6a7fc0e0f3d36d9305ce307aaa4017c3747b0706 Mon Sep 17 00:00:00 2001 From: King'ori Maina Date: Fri, 17 Apr 2020 15:02:48 +0300 Subject: [PATCH 05/11] Fix cross-platfrom building issues Seems like I have to specify the `kinds` globally because of cross platform building and then handle invalidity at runtime. For example, you would not be able to build binary on a Linux machine if you referenced `daemon.UserAgent` since that constant would not be made available by the compiler on a Linux build. --- README.md | 4 ++-- daemon.go | 50 +++++++++++++++++++++++++++++++++++++-- daemon_darwin.go | 17 ------------- daemon_freebsd.go | 6 ----- daemon_linux.go | 6 ----- daemon_windows.go | 6 ----- examples/cron/cron_job.go | 2 +- examples/myservice.go | 2 +- 8 files changed, 52 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index fc2313f..e6744ef 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ import ( ) func main() { - service, err := daemon.New("name", "description", daemon.GlobalDaemon) + service, err := daemon.New("name", "description", daemon.SystemDaemon) if err != nil { log.Fatal("Error: ", err) } @@ -159,7 +159,7 @@ func init() { } func main() { - srv, err := daemon.New(name, description, daemon.GlobalDaemon, dependencies...) + srv, err := daemon.New(name, description, daemon.SystemDaemon, dependencies...) if err != nil { errlog.Println("Error: ", err) os.Exit(1) diff --git a/daemon.go b/daemon.go index d654c32..d13f42d 100644 --- a/daemon.go +++ b/daemon.go @@ -139,7 +139,7 @@ Example: } func main() { - srv, err := daemon.New(name, description, daemon.GlobalDaemon, dependencies...) + srv, err := daemon.New(name, description, daemon.SystemDaemon, dependencies...) if err != nil { errlog.Println("Error: ", err) os.Exit(1) @@ -157,7 +157,11 @@ Go daemon */ package daemon -import "strings" +import ( + "errors" + "runtime" + "strings" +) // Status constants. const ( @@ -204,6 +208,29 @@ type Executable interface { // Kind is type of the daemon type Kind string +const ( + // UserAgent is a user daemon that runs as the currently logged in user and + // stores its property list in the user’s individual LaunchAgents directory. + // In other words, per-user agents provided by the user. Valid for macOS only. + UserAgent Kind = "UserAgent" + + // GlobalAgent is a user daemon that runs as the currently logged in user and + // stores its property list in the users' global LaunchAgents directory. In + // other words, per-user agents provided by the administrator. Valid for macOS + // only. + GlobalAgent Kind = "GlobalAgent" + + // GlobalDaemon is a system daemon that runs as the root user and stores its + // property list in the global LaunchDaemons directory. In other words, + // system-wide daemons provided by the administrator. Valid for macOS only. + GlobalDaemon Kind = "GlobalDaemon" + + // SystemDaemon is a system daemon that runs as the root user. In other words, + // system-wide daemons provided by the administrator. Valid for FreeBSD, Linux + // and Windows only. + SystemDaemon Kind = "SystemDaemon" +) + // New - Create a new daemon // // name: name of the service @@ -212,5 +239,24 @@ type Kind string // // kind: what kind of daemon to create func New(name, description string, kind Kind, dependencies ...string) (Daemon, error) { + switch runtime.GOOS { + case "darwin": + if kind == SystemDaemon { + return nil, errors.New("Invalid daemon kind specified") + } + case "freebsd": + if kind != SystemDaemon { + return nil, errors.New("Invalid daemon kind specified") + } + case "linux": + if kind != SystemDaemon { + return nil, errors.New("Invalid daemon kind specified") + } + case "windows": + if kind != SystemDaemon { + return nil, errors.New("Invalid daemon kind specified") + } + } + return newDaemon(strings.Join(strings.Fields(name), "_"), description, kind, dependencies) } diff --git a/daemon_darwin.go b/daemon_darwin.go index d0ce369..ae1538c 100644 --- a/daemon_darwin.go +++ b/daemon_darwin.go @@ -22,23 +22,6 @@ type darwinRecord struct { dependencies []string } -const ( - // UserAgent is a user daemon that runs as the currently logged in user and - // stores its property list in the user’s individual LaunchAgents directory. - // In other words, per-user agents provided by the user. - UserAgent Kind = "UserAgent" - - // GlobalAgent is a user daemon that runs as the currently logged in user and - // stores its property list in the users' global LaunchAgents directory. In - // other words, per-user agents provided by the administrator. - GlobalAgent Kind = "GlobalAgent" - - // GlobalDaemon is a system daemon that runs as the root user and stores its - // property list in the global LaunchDaemons directory. In other words, - // system-wide daemons provided by the administrator. - GlobalDaemon Kind = "GlobalDaemon" -) - func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { return &darwinRecord{name, description, kind, dependencies}, nil diff --git a/daemon_freebsd.go b/daemon_freebsd.go index 521a41e..e3995fe 100644 --- a/daemon_freebsd.go +++ b/daemon_freebsd.go @@ -19,12 +19,6 @@ type bsdRecord struct { dependencies []string } -const ( - // GlobalDaemon is a user daemon that runs as the root user. In other words, - // system-wide daemons provided by the administrator. - GlobalDaemon Kind = "GlobalDaemon" -) - // Standard service path for systemV daemons func (bsd *bsdRecord) servicePath() string { return "/usr/local/etc/rc.d/" + bsd.name diff --git a/daemon_linux.go b/daemon_linux.go index 1221cae..6dbcd87 100644 --- a/daemon_linux.go +++ b/daemon_linux.go @@ -9,12 +9,6 @@ import ( "os" ) -const ( - // GlobalDaemon is a user daemon that runs as the root user. In other words, - // system-wide daemons provided by the administrator. - GlobalDaemon Kind = "GlobalDaemon" -) - // Get the daemon properly func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { // newer subsystem must be checked first diff --git a/daemon_windows.go b/daemon_windows.go index ebd3c54..b7ddace 100644 --- a/daemon_windows.go +++ b/daemon_windows.go @@ -28,12 +28,6 @@ type windowsRecord struct { dependencies []string } -const ( - // GlobalDaemon is a user daemon that runs as the root user. In other words, - // system-wide daemons provided by the administrator. - GlobalDaemon Kind = "GlobalDaemon" -) - func newDaemon(name, description string, kind Kind, dependencies []string) (Daemon, error) { return &windowsRecord{name, description, kind, dependencies}, nil diff --git a/examples/cron/cron_job.go b/examples/cron/cron_job.go index 826ca1f..fdbc241 100644 --- a/examples/cron/cron_job.go +++ b/examples/cron/cron_job.go @@ -80,7 +80,7 @@ func init() { } func main() { - srv, err := daemon.New(name, description, daemon.GlobalDaemon) + srv, err := daemon.New(name, description, daemon.SystemDaemon) if err != nil { errlog.Println("Error: ", err) os.Exit(1) diff --git a/examples/myservice.go b/examples/myservice.go index 7f4dee6..a9cce43 100644 --- a/examples/myservice.go +++ b/examples/myservice.go @@ -120,7 +120,7 @@ func init() { } func main() { - srv, err := daemon.New(name, description, daemon.GlobalDaemon, dependencies...) + srv, err := daemon.New(name, description, daemon.SystemDaemon, dependencies...) if err != nil { errlog.Println("Error: ", err) os.Exit(1) From 086d83d5187d09606c512155cdc3854d02bdc60a Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Fri, 24 Jul 2020 00:05:58 +0200 Subject: [PATCH 06/11] Updated vendors --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7115eba..30e34f0 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.14 require ( github.com/robfig/cron v1.2.0 - golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 + golang.org/x/sys v0.0.0-20200722175500-76b94024e4b6 ) diff --git a/go.sum b/go.sum index 282b469..c6f16c2 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= -golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HXxFpW2sdCiP8MJSKLQY= -golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200722175500-76b94024e4b6 h1:X9xIZ1YU8bLZA3l6gqDUHSFiD0GFI9S548h6C8nDtOY= +golang.org/x/sys v0.0.0-20200722175500-76b94024e4b6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= From 0b10f33f7cd937b4ee3a3b8abc663cbcef6ae117 Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Fri, 24 Jul 2020 00:06:47 +0200 Subject: [PATCH 07/11] Added contributor --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e6744ef..b2366de 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Go Daemon -A daemon package for use with Go (golang) services with no dependencies +A daemon package for use with Go (golang) services [![GoDoc](https://godoc.org/github.com/takama/daemon?status.svg)](https://godoc.org/github.com/takama/daemon) @@ -183,13 +183,13 @@ Windows). Template will be a default Go Template(`"text/template"`). If `SetTemplate` is not called, default template content will be used while creating service. -|Variable | Description| -|---------|------------| -|Description| Description for service | -|Dependencies|Service dependencies| -|Name|Service name| -|Path|Path of service executable| -|Args|Arguments for service executable| +| Variable | Description | +| ------------ | -------------------------------- | +| Description | Description for service | +| Dependencies | Service dependencies | +| Name | Service name | +| Path | Path of service executable | +| Args | Arguments for service executable | #### Example template(for linux systemv) @@ -215,7 +215,6 @@ See `examples/cron/cron_job.go` ## Contributors (unsorted) -- [Igor Dolzhikov](https://github.com/takama) - [Sheile](https://github.com/Sheile) - [Nguyen Trung Loi](https://github.com/loint) - [Donny Prasetyobudi](https://github.com/donnpebe) @@ -235,10 +234,11 @@ See `examples/cron/cron_job.go` - [AlgorathDev](https://github.com/AlgorathDev) - [Alexis Camilleri](https://github.com/krysennn) - [neverland4u](https://github.com/neverland4u) +- [King'ori Maina](https://github.com/itskingori) All the contributors are welcome. If you would like to be the contributor please accept some rules. -- The pull requests will be accepted only in "develop" branch +- The pull requests will be accepted only in `develop` branch - All modifications or additions should be tested - Sorry, We will not accept code with any dependency, only standard library From fed48ef7f87c2928376ada2baedde5040afc6ff6 Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Fri, 24 Jul 2020 00:08:04 +0200 Subject: [PATCH 08/11] Updated license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index ffcad4a..3c1a169 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 The Go Authors +Copyright (c) 2020 The Go Authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 440dd2136a123b1f10ac2506e83f196463d443d4 Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Fri, 24 Jul 2020 00:11:47 +0200 Subject: [PATCH 09/11] Updated copyright --- daemon.go | 2 +- daemon_darwin.go | 2 +- daemon_freebsd.go | 4 ++++ daemon_linux.go | 2 +- daemon_linux_systemd.go | 2 +- daemon_linux_systemv.go | 2 +- daemon_linux_upstart.go | 2 +- daemon_windows.go | 8 ++++---- helper.go | 2 +- helper_legacy.go | 2 +- helper_windows.go | 2 +- 11 files changed, 17 insertions(+), 13 deletions(-) diff --git a/daemon.go b/daemon.go index d13f42d..5fa9d26 100644 --- a/daemon.go +++ b/daemon.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. diff --git a/daemon_darwin.go b/daemon_darwin.go index ae1538c..0c99343 100644 --- a/daemon_darwin.go +++ b/daemon_darwin.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. diff --git a/daemon_freebsd.go b/daemon_freebsd.go index e3995fe..2d84d5f 100644 --- a/daemon_freebsd.go +++ b/daemon_freebsd.go @@ -1,3 +1,7 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by +// license that can be found in the LICENSE file. + package daemon import ( diff --git a/daemon_linux.go b/daemon_linux.go index 6dbcd87..524c7d8 100644 --- a/daemon_linux.go +++ b/daemon_linux.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. diff --git a/daemon_linux_systemd.go b/daemon_linux_systemd.go index 21c4384..d6e6cca 100644 --- a/daemon_linux_systemd.go +++ b/daemon_linux_systemd.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. diff --git a/daemon_linux_systemv.go b/daemon_linux_systemv.go index 34cc6ab..588f6db 100644 --- a/daemon_linux_systemv.go +++ b/daemon_linux_systemv.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. diff --git a/daemon_linux_upstart.go b/daemon_linux_upstart.go index fdaab4d..16216c7 100644 --- a/daemon_linux_upstart.go +++ b/daemon_linux_upstart.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. diff --git a/daemon_windows.go b/daemon_windows.go index b7ddace..047b635 100644 --- a/daemon_windows.go +++ b/daemon_windows.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. @@ -279,7 +279,7 @@ type serviceHandler struct { executable Executable } -func (sh *serviceHandler) Execute(args []string, r <-chan svc.ChangeRequest, changes chan <- svc.Status) (ssec bool, errno uint32) { +func (sh *serviceHandler) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) { const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue changes <- svc.Status{State: svc.StartPending} @@ -290,7 +290,7 @@ func (sh *serviceHandler) Execute(args []string, r <-chan svc.ChangeRequest, cha sh.executable.Start() changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} - loop: +loop: for { select { case <-tick: @@ -352,4 +352,4 @@ func (linux *windowsRecord) GetTemplate() string { // SetTemplate - sets service config template func (linux *windowsRecord) SetTemplate(tplStr string) error { return errors.New(fmt.Sprintf("templating is not supported for windows")) -} \ No newline at end of file +} diff --git a/helper.go b/helper.go index 35981fb..e4bd4c1 100644 --- a/helper.go +++ b/helper.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. diff --git a/helper_legacy.go b/helper_legacy.go index bf5d9f1..f52cc98 100644 --- a/helper_legacy.go +++ b/helper_legacy.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. diff --git a/helper_windows.go b/helper_windows.go index 12816bc..2c176a3 100644 --- a/helper_windows.go +++ b/helper_windows.go @@ -1,4 +1,4 @@ -// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by // license that can be found in the LICENSE file. From fda1afddc671a36706b74c32aa3e571fab7d2ef9 Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Fri, 24 Jul 2020 00:16:21 +0200 Subject: [PATCH 10/11] Added contributor --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b2366de..27dd650 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,7 @@ See `examples/cron/cron_job.go` - [AlgorathDev](https://github.com/AlgorathDev) - [Alexis Camilleri](https://github.com/krysennn) - [neverland4u](https://github.com/neverland4u) +- [Rustam](https://github.com/rusq) - [King'ori Maina](https://github.com/itskingori) All the contributors are welcome. If you would like to be the contributor please accept some rules. From af3497b7e92728c4af9cffc4e2f16c6ff7f6f50a Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Fri, 24 Jul 2020 00:16:53 +0200 Subject: [PATCH 11/11] Bumped version number to v1.0.0 --- daemon.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon.go b/daemon.go index 5fa9d26..e5b0fa2 100644 --- a/daemon.go +++ b/daemon.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. /* -Package daemon v0.12.0 for use with Go (golang) services. +Package daemon v1.0.0 for use with Go (golang) services. Package daemon provides primitives for daemonization of golang services. In the current implementation the only supported operating systems are macOS, FreeBSD,