summaryrefslogtreecommitdiff
path: root/src/hub
diff options
context:
space:
mode:
authorMarkus Grüneis <gimpf@gimpf.org>2014-10-19 18:15:20 +0200
committerMarkus Grüneis <gimpf@gimpf.org>2014-10-19 18:15:20 +0200
commit9a9547faf7121725a8f51ed3ddfc17f8c4a0bd06 (patch)
tree0938eabe1569f171dd4f97b5664170b84e21a84e /src/hub
parenthub: add some testing endpoints in s5srvWeb (diff)
hub: add SIGINT handling to sfive-hub
Diffstat (limited to 'src/hub')
-rw-r--r--src/hub/src/spreadspace.org/sfive-hub/s5hub.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/hub/src/spreadspace.org/sfive-hub/s5hub.go b/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
index bb5e80f..c00cb3c 100644
--- a/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
+++ b/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
@@ -3,15 +3,17 @@ package main
import (
"fmt"
"log"
+ "os"
+ "os/signal"
"spreadspace.org/sfive"
"sync"
)
func main() {
- fmt.Printf("s5: Hello, world.\n")
+ fmt.Printf("s5hub: Hello, world.\n")
server, err := sfive.NewServer("/tmp/sfive.sqlite")
if err != nil {
- log.Fatalf("failed to initialize S5: %v", err)
+ log.Fatalf("s5hub: failed to initialize: %v", err)
}
defer server.Close()
@@ -21,13 +23,30 @@ func main() {
go func() {
defer wg.Done()
server.ServePipe("/run/sfive/pipe")
+ log.Println("s5hub: pipe finished")
}()
wg.Add(1)
go func() {
defer wg.Done()
server.ServeWeb()
+ log.Println("s5hub: web finished")
}()
- wg.Wait()
+ alldone := make(chan bool)
+ go func() {
+ defer func() { alldone <- true }()
+ wg.Wait()
+ }()
+
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+
+ select {
+ case <-c:
+ log.Println("s5hub: received interrupt, shutdown")
+ return
+ case <-alldone:
+ return
+ }
}