diff options
author | Slack Coder <slackcoder@server.ky> | 2024-10-21 12:00:24 -0500 |
---|---|---|
committer | Slack Coder <slackcoder@server.ky> | 2024-10-21 12:00:24 -0500 |
commit | c8ba7263e7923fc76eee7dbe129a8bfbc9501bb7 (patch) | |
tree | fdbf5c0bbe4901d86e34cf3d1e75954a991e9c4d /cmd | |
parent | 937aa1ba188df0355ac9023c70b0fdac6eb618e9 (diff) | |
download | mirror-c8ba7263e7923fc76eee7dbe129a8bfbc9501bb7.tar.xz |
Add signal handling
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/mirror/main.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cmd/mirror/main.go b/cmd/mirror/main.go index e8a00ac..1da9b15 100644 --- a/cmd/mirror/main.go +++ b/cmd/mirror/main.go @@ -5,6 +5,8 @@ import ( "fmt" "log" "os" + "os/signal" + "syscall" "git.server.ky/slackcoder/mirror/internal/service" ) @@ -36,6 +38,15 @@ func exitOnError(err error) { } } +func handleSignal(c <-chan os.Signal, srv *service.Service) { + for v := range c { + if v == syscall.SIGHUP { + var cfg service.Config + _ = srv.Reload(&cfg) + } + } +} + func main() { flags := ParseFlags() @@ -45,6 +56,9 @@ func main() { os.Exit(0) } + signalCh := make(chan os.Signal, 1) + signal.Notify(signalCh, syscall.SIGHUP) + var cfg service.Config c, err := service.ReadConfigDir(flags.ConfigDir) @@ -60,6 +74,9 @@ func main() { srv, err := service.NewService(&cfg) exitOnError(err) + signalCh = make(chan os.Signal, 1) + signal.Notify(signalCh, syscall.SIGHUP) + err = srv.Run() exitOnError(err) } |