-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
85 lines (70 loc) · 1.53 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
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"github.com/srad/streamsink/controllers"
"github.com/srad/streamsink/database"
"github.com/srad/streamsink/services"
)
var (
Version string
Commit string
)
func main() {
log.Infof("Version: %s, Commit: %s", Version, Commit)
log.SetFormatter(&log.TextFormatter{})
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
cleanup()
os.Exit(1)
}()
database.Init()
// models.StartMetrics(conf.AppCfg.NetworkDev)
setupFolders()
services.StartUpJobs()
services.StartRecorder()
services.StartJobProcessing()
gin.SetMode("release")
endPoint := fmt.Sprintf("0.0.0.0:%d", 3000)
log.Infof("[main] start http server listening %s", endPoint)
server := &http.Server{
Addr: endPoint,
Handler: controllers.Setup(Version, Commit),
ReadTimeout: 12 * time.Hour,
WriteTimeout: 12 * time.Hour,
MaxHeaderBytes: 0,
}
go func() {
if err := server.ListenAndServe(); err != nil {
log.Fatalln(err)
}
log.Infof("[main] start http server listening %s", endPoint)
}()
<-c
}
func cleanup() {
log.Infoln("cleanup ...")
services.StopJobProcessing()
services.StopRecorder()
log.Infoln("cleanup complete")
}
func setupFolders() {
channels, err := database.ChannelList()
if err != nil {
log.Errorln(err)
return
}
for _, channel := range channels {
if err := channel.ChannelName.MkDir(); err != nil {
log.Errorln(err)
}
}
}