summaryrefslogtreecommitdiff
path: root/src/hub
diff options
context:
space:
mode:
authorMarkus Grüneis <gimpf@gimpf.org>2014-10-22 19:34:19 +0200
committerMarkus Grüneis <gimpf@gimpf.org>2014-10-22 19:34:19 +0200
commit76d3388c6cebb0eec96f4111fd8b420f709dbc8a (patch)
treea71f147ce13e0d949a316c1760956e9983ac0e4c /src/hub
parenthub: add basic POST support (diff)
hub: use command-line options for paths etc.
Diffstat (limited to 'src/hub')
-rw-r--r--src/hub/src/spreadspace.org/sfive-hub/s5hub.go60
-rwxr-xr-xsrc/hub/test-srv2
2 files changed, 44 insertions, 18 deletions
diff --git a/src/hub/src/spreadspace.org/sfive-hub/s5hub.go b/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
index c00cb3c..3368d37 100644
--- a/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
+++ b/src/hub/src/spreadspace.org/sfive-hub/s5hub.go
@@ -1,7 +1,7 @@
package main
import (
- "fmt"
+ "flag"
"log"
"os"
"os/signal"
@@ -9,29 +9,55 @@ import (
"sync"
)
+var s5hl = log.New(os.Stderr, "s5hub", log.LstdFlags)
+
func main() {
- fmt.Printf("s5hub: Hello, world.\n")
- server, err := sfive.NewServer("/tmp/sfive.sqlite")
+ db := flag.String("db", "/var/lib/sfive/db.sqlite", "path to the sqlite3 database file")
+ pipe := flag.String("pipe", "/var/run/sfive/pipe", "path to the unix pipe for the pipeserver")
+ startPipe := flag.Bool("start-pipe-server", true, "start a connection oriented pipe server; see option pipe")
+ startWeb := flag.Bool("start-web-server", true, "start a webserver")
+ forward := flag.String("forward-url", "", "forward to another sfive-server with http server at base-url")
+
+ flag.Parse()
+
+ s5hl.Printf("Hello, world.\n")
+ server, err := sfive.NewServer(*db)
if err != nil {
- log.Fatalf("s5hub: failed to initialize: %v", err)
+ s5hl.Fatalf("failed to initialize: %v", err)
}
defer server.Close()
var wg sync.WaitGroup
- wg.Add(1)
- go func() {
- defer wg.Done()
- server.ServePipe("/run/sfive/pipe")
- log.Println("s5hub: pipe finished")
- }()
+ if *startPipe {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ s5hl.Printf("start pipe at %v\n", *pipe)
+ server.ServePipe(*pipe)
+ s5hl.Println("pipe finished")
+ }()
+ }
- wg.Add(1)
- go func() {
- defer wg.Done()
- server.ServeWeb()
- log.Println("s5hub: web finished")
- }()
+ if *startWeb {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ s5hl.Println("start web-srv")
+ server.ServeWeb()
+ s5hl.Println("web finished")
+ }()
+ }
+
+ if *forward != "" {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ s5hl.Println("start forward")
+ // TODO
+ s5hl.Println("forward finished")
+ }()
+ }
alldone := make(chan bool)
go func() {
@@ -44,7 +70,7 @@ func main() {
select {
case <-c:
- log.Println("s5hub: received interrupt, shutdown")
+ s5hl.Println("received interrupt, shutdown")
return
case <-alldone:
return
diff --git a/src/hub/test-srv b/src/hub/test-srv
index eb2a0a9..ff1369d 100755
--- a/src/hub/test-srv
+++ b/src/hub/test-srv
@@ -1,4 +1,4 @@
#!/bin/sh
rm -f /run/sfive/pipe
-./bin/sfive-hub
+./bin/sfive-hub -db /var/lib/sfive/db.sqlite -start-pipe-server -pipe /var/run/sfive/pipe -start-web-server