aboutsummaryrefslogtreecommitdiff
path: root/cmd/alps
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2020-10-23 13:30:29 -0400
committerDrew DeVault <sir@cmpwn.com>2020-10-23 13:30:29 -0400
commitb93b2bafa56ee79fa5d70b4c15901981215fa935 (patch)
tree36e17ab04c4d34f4597c99a250be880f74fd8c2d /cmd/alps
parent8764397b7d641450009436196f300dadbe770f1d (diff)
downloadalps-b93b2bafa56ee79fa5d70b4c15901981215fa935.tar.gz
alps-b93b2bafa56ee79fa5d70b4c15901981215fa935.zip
Rig up dowork event queue and graceful termination
Diffstat (limited to 'cmd/alps')
-rw-r--r--cmd/alps/main.go26
1 files changed, 21 insertions, 5 deletions
diff --git a/cmd/alps/main.go b/cmd/alps/main.go
index 4c358d5..dedd6cb 100644
--- a/cmd/alps/main.go
+++ b/cmd/alps/main.go
@@ -1,11 +1,13 @@
package main
import (
+ "context"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
+ "time"
"git.sr.ht/~emersion/alps"
"github.com/fernet/fernet-go"
@@ -74,15 +76,29 @@ func main() {
e.Logger.SetLevel(log.DEBUG)
}
+ go e.Start(addr)
+
+ s.Queue.Start(context.Background())
+
sigs := make(chan os.Signal, 1)
- signal.Notify(sigs, syscall.SIGUSR1)
- go func() {
- for range sigs {
+ signal.Notify(sigs, syscall.SIGUSR1, syscall.SIGINT)
+
+ for sig := range sigs {
+ if sig == syscall.SIGUSR1 {
if err := s.Reload(); err != nil {
e.Logger.Errorf("Failed to reload server: %v", err)
}
+ } else if sig == syscall.SIGINT {
+ break
}
- }()
+ }
+
+ ctx, cancel := context.WithDeadline(context.Background(),
+ time.Now().Add(30*time.Second))
+ e.Shutdown(ctx)
+ cancel()
- e.Logger.Fatal(e.Start(addr))
+ e.Logger.Print("Waiting for work queues to finish...")
+ s.Queue.Shutdown()
+ e.Logger.Print("Shut down.")
}