2021-08-19 13:51:43 +00:00
|
|
|
//go:build !windows
|
2021-03-25 18:31:21 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2021-06-26 05:31:41 +00:00
|
|
|
"github.com/drakkan/sftpgo/v2/common"
|
|
|
|
"github.com/drakkan/sftpgo/v2/dataprovider"
|
|
|
|
"github.com/drakkan/sftpgo/v2/ftpd"
|
|
|
|
"github.com/drakkan/sftpgo/v2/httpd"
|
|
|
|
"github.com/drakkan/sftpgo/v2/logger"
|
2022-01-05 10:37:45 +00:00
|
|
|
"github.com/drakkan/sftpgo/v2/plugin"
|
2021-06-26 05:31:41 +00:00
|
|
|
"github.com/drakkan/sftpgo/v2/telemetry"
|
|
|
|
"github.com/drakkan/sftpgo/v2/webdavd"
|
2021-03-25 18:31:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func registerSignals() {
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGUSR1)
|
|
|
|
go func() {
|
|
|
|
for sig := range c {
|
|
|
|
switch sig {
|
|
|
|
case syscall.SIGHUP:
|
|
|
|
handleSIGHUP()
|
|
|
|
case syscall.SIGUSR1:
|
|
|
|
handleSIGUSR1()
|
|
|
|
case syscall.SIGINT, syscall.SIGTERM:
|
|
|
|
handleInterrupt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleSIGHUP() {
|
|
|
|
logger.Debug(logSender, "", "Received reload request")
|
|
|
|
err := dataprovider.ReloadConfig()
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, "", "error reloading dataprovider configuration: %v", err)
|
|
|
|
}
|
|
|
|
err = httpd.ReloadCertificateMgr()
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, "", "error reloading cert manager: %v", err)
|
|
|
|
}
|
|
|
|
err = ftpd.ReloadCertificateMgr()
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, "", "error reloading FTPD cert manager: %v", err)
|
|
|
|
}
|
|
|
|
err = webdavd.ReloadCertificateMgr()
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, "", "error reloading WebDAV cert manager: %v", err)
|
|
|
|
}
|
|
|
|
err = telemetry.ReloadCertificateMgr()
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, "", "error reloading telemetry cert manager: %v", err)
|
|
|
|
}
|
|
|
|
err = common.ReloadDefender()
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, "", "error reloading defender's lists: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleSIGUSR1() {
|
|
|
|
logger.Debug(logSender, "", "Received log file rotation request")
|
|
|
|
err := logger.RotateLogFile()
|
|
|
|
if err != nil {
|
|
|
|
logger.Warn(logSender, "", "error rotating log file: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleInterrupt() {
|
|
|
|
logger.Debug(logSender, "", "Received interrupt request")
|
2021-07-11 13:26:51 +00:00
|
|
|
plugin.Handler.Cleanup()
|
2021-03-25 18:31:21 +00:00
|
|
|
os.Exit(0)
|
|
|
|
}
|