forked from omnibuildplatform/omni-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (63 loc) · 1.65 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"os"
"os/signal"
"syscall"
"github.com/gookit/color"
"github.com/omnibuildplatform/omni-repository/app"
"github.com/omnibuildplatform/omni-repository/application"
)
var (
manager *application.RepositoryManager
)
func init() {
app.Bootstrap("./config")
application.InitServer()
}
func main() {
var err error
manager, err = application.NewRepositoryManager(application.Server().Group("/data/"))
if err != nil {
color.Error.Printf("failed to initialize repository manager %v\n", err)
os.Exit(1)
}
err = app.InitDB()
if err != nil {
color.Error.Printf("failed to connect database ,error: %v\n ", err)
os.Exit(1)
}
err = manager.Initialize()
if err != nil {
color.Error.Printf("failed to start repository manager %v\n ", err)
os.Exit(1)
}
color.Info.Printf("============ Begin Running(PID: %d) ============\n", os.Getpid())
application.Run()
}
// listenSignals Graceful start/stop server
func listenSignals() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go handleSignals(sigChan)
}
// handleSignals handle process signal
func handleSignals(c chan os.Signal) {
color.Info.Printf("Notice: System signal monitoring is enabled(watch: SIGINT,SIGTERM,SIGQUIT)\n")
switch <-c {
case syscall.SIGINT:
color.Info.Printf("\nShutdown by Ctrl+C")
case syscall.SIGTERM: // by kill
color.Info.Printf("\nShutdown quickly")
case syscall.SIGQUIT:
color.Info.Printf("\nShutdown gracefully")
// do graceful shutdown
}
// sync logs
_ = app.Logger.Sync()
if manager != nil {
manager.Close()
}
//sleep and exit
color.Info.Println("\nGoodBye...")
os.Exit(0)
}