forked from sdslabs/gasper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_launchers.go
137 lines (126 loc) · 4.06 KB
/
service_launchers.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"os"
"runtime"
"github.com/sdslabs/gasper/configs"
"github.com/sdslabs/gasper/lib/utils"
"github.com/sdslabs/gasper/services/appmaker"
"github.com/sdslabs/gasper/services/dbmaker"
"github.com/sdslabs/gasper/services/gendns"
"github.com/sdslabs/gasper/services/genproxy"
"github.com/sdslabs/gasper/services/genssh"
"github.com/sdslabs/gasper/services/jikan"
"github.com/sdslabs/gasper/services/master"
"github.com/sdslabs/gasper/types"
)
type serviceLauncher struct {
Deploy bool
Start func() error
}
// Bind the services to the launchers
var launcherBindings = map[string]*serviceLauncher{
master.ServiceName: {
Deploy: configs.ServiceConfig.Master.Deploy,
Start: startMasterService,
},
appmaker.ServiceName: {
Deploy: configs.ServiceConfig.AppMaker.Deploy,
Start: startAppMakerService,
},
genssh.ServiceName: {
Deploy: configs.ServiceConfig.GenSSH.Deploy,
Start: startGenSSHService,
},
gendns.ServiceName: {
Deploy: configs.ServiceConfig.GenDNS.Deploy,
Start: gendns.NewService().ListenAndServe,
},
genproxy.DefaultServiceName: {
Deploy: configs.ServiceConfig.GenProxy.Deploy,
Start: startGenProxyService,
},
genproxy.SSLServiceName: {
Deploy: configs.ServiceConfig.GenProxy.SSL.PlugIn,
Start: startGenProxyServiceWithSSL,
},
dbmaker.ServiceName: {
Deploy: configs.ServiceConfig.DbMaker.Deploy,
Start: startDbMakerService,
},
jikan.ServiceName: {
Deploy: configs.ServiceConfig.Jikan.Deploy,
Start: startJikanService,
},
}
func startDbMakerService() error {
if configs.ServiceConfig.DbMaker.MySQL.PlugIn {
checkAndPullImages(configs.ImageConfig.Mysql)
setupDatabaseContainer(types.MySQL)
}
if configs.ServiceConfig.DbMaker.MongoDB.PlugIn {
checkAndPullImages(configs.ImageConfig.Mongodb)
setupDatabaseContainer(types.MongoDB)
}
if configs.ServiceConfig.DbMaker.PostgreSQL.PlugIn {
checkAndPullImages(configs.ImageConfig.Postgresql)
setupDatabaseContainer(types.PostgreSQL)
}
if configs.ServiceConfig.DbMaker.Redis.PlugIn {
checkAndPullImages(configs.ImageConfig.Redis)
}
return startGrpcServer(dbmaker.NewService(), configs.ServiceConfig.DbMaker.Port)
}
func startAppMakerService() error {
images := []string{
configs.ImageConfig.Static,
configs.ImageConfig.Php,
configs.ImageConfig.Nodejs,
configs.ImageConfig.Python2,
configs.ImageConfig.Python3,
configs.ImageConfig.Golang,
configs.ImageConfig.Ruby,
configs.ImageConfig.Rust,
}
checkAndPullImages(images...)
return startGrpcServer(appmaker.NewService(), configs.ServiceConfig.AppMaker.Port)
}
func startMasterService() error {
if configs.ServiceConfig.Master.MongoDB.PlugIn {
checkAndPullImages(configs.ImageConfig.Mongodb)
setupDatabaseContainer(types.MongoDBGasper)
}
if configs.ServiceConfig.Master.Redis.PlugIn {
checkAndPullImages(configs.ImageConfig.Redis)
setupDatabaseContainer(types.RedisGasper)
}
return buildHTTPServer(master.NewService(), configs.ServiceConfig.Master.Port).ListenAndServe()
}
func startGenProxyService() error {
return buildHTTPServer(genproxy.NewService(), configs.ServiceConfig.GenProxy.Port).ListenAndServe()
}
func startGenSSHService() error {
if !configs.ServiceConfig.GenSSH.Deploy {
return nil
}
if runtime.GOOS == "windows" {
utils.LogInfo("Main-Launchers-1", "GenSSH doesn't work on Windows, skipping its deployment")
return nil
}
return genssh.NewService().ListenAndServe()
}
func startGenProxyServiceWithSSL() error {
port := configs.ServiceConfig.GenProxy.SSL.Port
certificate := configs.ServiceConfig.GenProxy.SSL.Certificate
privateKey := configs.ServiceConfig.GenProxy.SSL.PrivateKey
err := buildHTTPServer(genproxy.NewService(), port).ListenAndServeTLS(certificate, privateKey)
if err != nil {
utils.Log("Main-Launchers-2", "There was a problem deploying GenProxy Service with SSL", utils.ErrorTAG)
utils.Log("Main-Launchers-3", "Make sure the paths of certificate and private key are correct in `config.toml`", utils.ErrorTAG)
utils.LogError("Main-Launchers-4", err)
os.Exit(1)
}
return nil
}
func startJikanService() error {
return jikan.NewService().ListenAndServe()
}