-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubservice.go
83 lines (70 loc) · 1.79 KB
/
subservice.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
package main
import (
"net/http"
"os"
"path/filepath"
fs "imuslab.com/arozos/mod/filesystem"
prout "imuslab.com/arozos/mod/prouter"
subservice "imuslab.com/arozos/mod/subservice"
"imuslab.com/arozos/mod/utils"
)
/*
ArOZ Online System - Dynamic Subsystem loading services
*/
var (
ssRouter *subservice.SubServiceRouter
reservePaths = []string{
"web",
"system",
"SystemAO",
"img",
"STDIN",
"STDOUT",
"STDERR",
"COM",
"ws",
}
)
func SubserviceInit() {
//If subservice is disabled, do not register endpoints
if *disable_subservices {
return
}
//Create a new subservice handler
ssRouter = subservice.NewSubServiceRouter(
reservePaths,
subserviceBasePort,
userHandler,
moduleHandler,
*listen_port,
)
//Create an admin router for subservice related functions
adminRouter := prout.NewModuleRouter(prout.RouterOption{
ModuleName: "System Setting",
AdminOnly: false,
UserHandler: userHandler,
DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
utils.SendErrorResponse(w, "Permission Denied")
},
})
//Register url endpoints
adminRouter.HandleFunc("/system/subservice/list", ssRouter.HandleListing)
adminRouter.HandleFunc("/system/subservice/kill", ssRouter.HandleKillSubService)
adminRouter.HandleFunc("/system/subservice/start", ssRouter.HandleStartSubService)
//Make subservice dir
os.MkdirAll("./subservice", 0644)
//Scan and load all subservice modules
subservices, _ := filepath.Glob("./subservice/*")
for _, servicePath := range subservices {
if fs.IsDir(servicePath) && !fs.FileExists(servicePath+"/.disabled") {
//Only enable module with no suspended config file
ssRouter.Launch(servicePath, true)
}
}
}
//Stop all the subprocess correctly
func SubserviceHandleShutdown() {
if ssRouter != nil {
ssRouter.Close()
}
}