-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbnet.go
59 lines (50 loc) · 1018 Bytes
/
dbnet.go
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
package main
import (
"context"
"os"
"os/signal"
"syscall"
"time"
"github.com/dbnet-io/dbnet/store"
"github.com/dbrest-io/dbrest/state"
"github.com/flarco/g"
"github.com/spf13/cast"
)
var ctx = g.NewContext(context.Background())
var interrupted = false
var isApp = cast.ToBool(os.Getenv("DBNET_APP"))
func init() {
store.InitDB()
}
func main() {
state.DefaultProject().NoRestriction = true // allow all on dbREST
exitCode := 11
done := make(chan struct{})
interrupt := make(chan os.Signal, 1)
kill := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
signal.Notify(kill, syscall.SIGTERM)
go func() {
defer close(done)
exitCode = cliInit()
}()
select {
case <-done:
os.Exit(exitCode)
case <-kill:
println("\nkilling process...")
os.Exit(111)
case <-interrupt:
if cliServe.Sc.Used {
println("\ninterrupting...")
interrupted = true
ctx.Cancel()
select {
case <-done:
case <-time.After(5 * time.Second):
}
}
os.Exit(exitCode)
return
}
}