Add support for graceful shutdown

Fixes #1014

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-10-22 11:56:41 +02:00
parent 87045284cc
commit db0e58ae7e
32 changed files with 371 additions and 124 deletions

View File

@@ -26,6 +26,7 @@ import (
"path"
"path/filepath"
"strings"
"sync/atomic"
"time"
"github.com/sftpgo/sdk"
@@ -44,13 +45,16 @@ var (
errNoHook = errors.New("unable to execute action, no hook defined")
errUnexpectedHTTResponse = errors.New("unexpected HTTP hook response code")
hooksConcurrencyGuard = make(chan struct{}, 150)
activeHooks atomic.Int32
)
func startNewHook() {
activeHooks.Add(1)
hooksConcurrencyGuard <- struct{}{}
}
func hookEnded() {
activeHooks.Add(-1)
<-hooksConcurrencyGuard
}