1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
package main
import (
"flag"
"log"
"os"
"os/signal"
"spreadspace.org/sfive"
"sync"
)
var s5hl = log.New(os.Stderr, "[s5hub]\t", log.LstdFlags)
func main() {
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")
ppipe := flag.String("pipegram", "/var/run/sfive/pipegram", "path to the unix datagram pipe for the pipeserver")
startPipe := flag.Bool("start-pipe-server", true, "start a connection oriented pipe server; see option pipe")
startGramPipe := flag.Bool("start-pipegram-server", true, "start a datagram oriented pipe server; see option pipegram")
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")
vizAppDir := flag.String("viz-dir", "/usr/share/sfive", "base-path to the viz application")
help := flag.Bool("help", false, "show usage")
flag.Parse()
s5hl.Printf("Hello, world.\n")
if *help {
flag.Usage()
return
}
server, err := sfive.NewServer(*db)
if err != nil {
s5hl.Fatalf("failed to initialize: %v", err)
}
defer server.Close()
var wg sync.WaitGroup
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")
}()
}
if *startGramPipe {
wg.Add(1)
go func() {
defer wg.Done()
s5hl.Printf("start pipegram at %v\n", *ppipe)
server.ServeGramPipe(*ppipe)
s5hl.Println("pipegram finished")
}()
}
if *startWeb {
wg.Add(1)
go func() {
defer wg.Done()
s5hl.Println("start web-srv")
server.ServeWeb(*vizAppDir)
s5hl.Println("web finished")
}()
}
if *forward != "" {
wg.Add(1)
go func() {
defer wg.Done()
s5hl.Println("start forward")
server.RunForwarding(*forward)
s5hl.Println("forward finished")
}()
}
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:
s5hl.Println("received interrupt, shutdown")
return
case <-alldone:
return
}
}
|