aboutsummaryrefslogtreecommitdiffsponsor
diff options
context:
space:
mode:
authorSlack Coder <slackcoder@server.ky>2024-10-21 12:00:24 -0500
committerSlack Coder <slackcoder@server.ky>2024-10-21 12:00:24 -0500
commitc8ba7263e7923fc76eee7dbe129a8bfbc9501bb7 (patch)
treefdbf5c0bbe4901d86e34cf3d1e75954a991e9c4d
parent937aa1ba188df0355ac9023c70b0fdac6eb618e9 (diff)
downloadmirror-c8ba7263e7923fc76eee7dbe129a8bfbc9501bb7.tar.xz
Add signal handling
-rw-r--r--cmd/mirror/main.go17
-rw-r--r--internal/service/service.go5
2 files changed, 22 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)
}
diff --git a/internal/service/service.go b/internal/service/service.go
index 21df14b..3038a03 100644
--- a/internal/service/service.go
+++ b/internal/service/service.go
@@ -146,6 +146,11 @@ func (s *Service) RemoveMirror(arg *Mirror) error {
return errors.New("not found")
}
+// Take arguments
+func (s *Service) Reload(cfg *Config) error {
+ return errors.New("not implemented")
+}
+
func (s *Service) Log(str string) {
escaped := []rune(strconv.Quote(strings.TrimSpace(str)))
escaped = escaped[1 : len(escaped)-1]