-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
59 lines (50 loc) · 1.13 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
package main
import (
"email2misskey/global"
"email2misskey/inits"
"log"
"os"
"os/signal"
"syscall"
)
func main() {
// Start initializing
log.Println("Start initializing...")
if err := inits.Config(); err != nil {
log.Fatal(err)
}
if err := inits.Logger(); err != nil {
log.Fatal(err)
}
global.Logger.Infof("Logger initialized, switch to here")
if err := inits.Redis(); err != nil {
global.Logger.Fatal(err)
}
if err := inits.Misskey(); err != nil {
global.Logger.Fatal(err)
}
if err := inits.SMTP(); err != nil {
global.Logger.Fatal(err)
}
global.Logger.Infof("System initialized successfully.")
// Block process till finish
channelComplete := setupSignalHandling()
<-*channelComplete
}
func setupSignalHandling() *chan struct{} {
signalChannel := make(chan os.Signal, 2)
signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)
channelComplete := make(chan struct{})
go func() {
<-signalChannel
shutdown()
channelComplete <- struct{}{}
}()
return &channelComplete
}
func shutdown() {
global.Logger.Infof("System shutting down...")
if global.GDaemon != nil {
global.GDaemon.Shutdown()
}
}