diff options
author | zeripath <art27@cantab.net> | 2019-11-21 18:32:02 +0000 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-11-21 13:32:02 -0500 |
commit | cbaa1de9ec8ab1baa49357b660fab16a68097c84 (patch) | |
tree | 5f481d73c95ae24b91e7bb03abaa5cf921f806b5 /modules/minwinsvc | |
parent | d7ac9727bb5046118915cbb26b2dac1b7b27c9d4 (diff) | |
download | gitea-cbaa1de9ec8ab1baa49357b660fab16a68097c84.tar.gz gitea-cbaa1de9ec8ab1baa49357b660fab16a68097c84.zip |
Add Graceful shutdown for Windows and hooks for shutdown of goroutines (#8964)
* Graceful Shutdown for windows and others
Restructures modules/graceful, adding shutdown for windows, removing and
replacing the old minwinsvc code.
Creates a new waitGroup - terminate which allows for goroutines to
finish up after the shutdown of the servers.
Shutdown and terminate hooks are added for goroutines.
* Remove unused functions - these can be added in a different PR
* Add startup timeout functionality
* Document STARTUP_TIMEOUT
Diffstat (limited to 'modules/minwinsvc')
-rw-r--r-- | modules/minwinsvc/LICENSE | 20 | ||||
-rw-r--r-- | modules/minwinsvc/README.md | 18 | ||||
-rw-r--r-- | modules/minwinsvc/minwinsvc.go | 18 | ||||
-rw-r--r-- | modules/minwinsvc/svc_other.go | 11 | ||||
-rw-r--r-- | modules/minwinsvc/svc_windows.go | 76 |
5 files changed, 0 insertions, 143 deletions
diff --git a/modules/minwinsvc/LICENSE b/modules/minwinsvc/LICENSE deleted file mode 100644 index fce91b4e1a..0000000000 --- a/modules/minwinsvc/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2015 Daniel Theophanes - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. diff --git a/modules/minwinsvc/README.md b/modules/minwinsvc/README.md deleted file mode 100644 index 260dceeac3..0000000000 --- a/modules/minwinsvc/README.md +++ /dev/null @@ -1,18 +0,0 @@ -### Minimal windows service stub - -Programs designed to run from most *nix style operating systems -can import this package to enable running programs as services without modifying -them. - -``` -import _ "github.com/kardianos/minwinsvc" -``` - -If you need more control over the exit behavior, set -``` -minwinsvc.SetOnExit(func() { - // Do something. - // Within 10 seconds call: - os.Exit(0) -}) -``` diff --git a/modules/minwinsvc/minwinsvc.go b/modules/minwinsvc/minwinsvc.go deleted file mode 100644 index 4cd89ffdb4..0000000000 --- a/modules/minwinsvc/minwinsvc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 Daniel Theophanes. -// Use of this source code is governed by a zlib-style -// license that can be found in the LICENSE file.package service - -// Package minwinsvc is a minimal non-invasive windows only service stub. -// -// Import to allow running as a windows service. -// import _ "github.com/kardianos/minwinsvc" -// This will detect if running as a windows service -// and install required callbacks for windows. -package minwinsvc - -// SetOnExit sets the function to be called when the windows service -// requests an exit. If this is not called, or if it is called where -// f == nil, then it defaults to calling "os.Exit(0)". -func SetOnExit(f func()) { - setOnExit(f) -} diff --git a/modules/minwinsvc/svc_other.go b/modules/minwinsvc/svc_other.go deleted file mode 100644 index 197d30021f..0000000000 --- a/modules/minwinsvc/svc_other.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2015 Daniel Theophanes. -// Use of this source code is governed by a zlib-style -// license that can be found in the LICENSE file.package service - -//+build !windows - -package minwinsvc - -func setOnExit(f func()) { - // Nothing. -} diff --git a/modules/minwinsvc/svc_windows.go b/modules/minwinsvc/svc_windows.go deleted file mode 100644 index 609bf06d3a..0000000000 --- a/modules/minwinsvc/svc_windows.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2015 Daniel Theophanes. -// Use of this source code is governed by a zlib-style -// license that can be found in the LICENSE file.package service - -//+build windows - -package minwinsvc - -import ( - "os" - "strconv" - "sync" - - "golang.org/x/sys/windows/svc" -) - -var ( - onExit func() - guard sync.Mutex - skip, _ = strconv.ParseBool(os.Getenv("SKIP_MINWINSVC")) - isSSH = os.Getenv("SSH_ORIGINAL_COMMAND") != "" -) - -func init() { - if skip || isSSH { - return - } - interactive, err := svc.IsAnInteractiveSession() - if err != nil { - panic(err) - } - if interactive { - return - } - go func() { - _ = svc.Run("", runner{}) - - guard.Lock() - f := onExit - guard.Unlock() - - // Don't hold this lock in user code. - if f != nil { - f() - } - // Make sure we exit. - os.Exit(0) - }() -} - -func setOnExit(f func()) { - guard.Lock() - onExit = f - guard.Unlock() -} - -type runner struct{} - -func (runner) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (bool, uint32) { - const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown - changes <- svc.Status{State: svc.StartPending} - - changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} - for { - c := <-r - switch c.Cmd { - case svc.Interrogate: - changes <- c.CurrentStatus - case svc.Stop, svc.Shutdown: - changes <- svc.Status{State: svc.StopPending} - return false, 0 - } - } - - return false, 0 -} |