-
Notifications
You must be signed in to change notification settings - Fork 75
/
main.go
82 lines (71 loc) · 1.79 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
package main
import (
"fmt"
"github.com/mynaparrot/plugnmeet-server/helpers"
"github.com/mynaparrot/plugnmeet-server/pkg/config"
"github.com/mynaparrot/plugnmeet-server/pkg/controllers"
"github.com/mynaparrot/plugnmeet-server/pkg/routers"
"github.com/mynaparrot/plugnmeet-server/version"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"os"
"os/signal"
"syscall"
)
func main() {
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("%s\n", c.App.Version)
}
app := &cli.App{
Name: "plugnmeet-server",
Usage: "Scalable, Open source web conference system",
Description: "without option will start server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "Configuration file",
DefaultText: "config.yaml",
Value: "config.yaml",
},
},
Action: startServer,
Version: version.Version,
}
err := app.Run(os.Args)
if err != nil {
log.Fatalln(err)
}
}
func startServer(c *cli.Context) error {
appCnf, err := helpers.ReadYamlConfigFile(c.String("config"))
if err != nil {
panic(err)
}
// set this config for global usage
config.New(appCnf)
// now prepare our server
err = helpers.PrepareServer(config.GetConfig())
if err != nil {
log.Fatalln(err)
}
// start nats services
nts := controllers.NewNatsController()
go nts.BootUp()
// start scheduler
go controllers.StartScheduler()
// defer close connections
defer helpers.HandleCloseConnections()
rt := routers.New()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
sig := <-sigChan
log.Infoln("exit requested, shutting down", "signal", sig)
_ = rt.Shutdown()
}()
err = rt.Listen(fmt.Sprintf(":%d", appCnf.Client.Port))
if err != nil {
log.Fatalln(err)
}
return nil
}