|
@@ -68,7 +68,7 @@ func NewSubServiceRouter(ReservePaths []string, basePort int, userHandler *user.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//Load and start all the subservices inside this rootpath
|
|
|
|
|
|
+// Load and start all the subservices inside this rootpath
|
|
func (sr *SubServiceRouter) LoadSubservicesFromRootPath(rootpath string) {
|
|
func (sr *SubServiceRouter) LoadSubservicesFromRootPath(rootpath string) {
|
|
scanningPath := filepath.ToSlash(filepath.Clean(rootpath)) + "/*"
|
|
scanningPath := filepath.ToSlash(filepath.Clean(rootpath)) + "/*"
|
|
|
|
|
|
@@ -167,7 +167,7 @@ func (sr *SubServiceRouter) Launch(servicePath string, startupMode bool) error {
|
|
infocmd := exec.Command(servicePath+"/"+binaryExecPath, "-info")
|
|
infocmd := exec.Command(servicePath+"/"+binaryExecPath, "-info")
|
|
launchConfig, err := infocmd.CombinedOutput()
|
|
launchConfig, err := infocmd.CombinedOutput()
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Println("*Subservice* startup flag -info return no JSON string and moduleInfo.json does not exists.")
|
|
|
|
|
|
+ sr.logger.PrintAndLog("Subservice", "Missing module startup info for "+servicePath, errors.New("Startup flag -info return no JSON string and moduleInfo.json does not exists for "+servicePath))
|
|
if startupMode {
|
|
if startupMode {
|
|
log.Fatal("Unable to start service: "+binaryname, err)
|
|
log.Fatal("Unable to start service: "+binaryname, err)
|
|
} else {
|
|
} else {
|
|
@@ -232,7 +232,7 @@ func (sr *SubServiceRouter) Launch(servicePath string, startupMode bool) error {
|
|
ServiceDir: serviceRoot,
|
|
ServiceDir: serviceRoot,
|
|
Process: cmd,
|
|
Process: cmd,
|
|
}
|
|
}
|
|
- log.Println("[Subservice] Starting service " + serviceRoot + " in compatibility mode.")
|
|
|
|
|
|
+ sr.logger.PrintAndLog("Subservice", "Starting service "+serviceRoot+" in compatibility mode", nil)
|
|
} else {
|
|
} else {
|
|
//Create a proxy for this service
|
|
//Create a proxy for this service
|
|
//Get proxy endpoint from startDir dir
|
|
//Get proxy endpoint from startDir dir
|
|
@@ -297,6 +297,8 @@ func (sr *SubServiceRouter) Launch(servicePath string, startupMode bool) error {
|
|
Process: cmd,
|
|
Process: cmd,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ sr.logger.PrintAndLog("Subservice", "Subservice Registered: "+thisModuleInfo.Name, nil)
|
|
|
|
+
|
|
//Create a new proxy object
|
|
//Create a new proxy object
|
|
path, _ := url.Parse("http://localhost:" + intToString(thisServicePort))
|
|
path, _ := url.Parse("http://localhost:" + intToString(thisServicePort))
|
|
proxy := reverseproxy.NewReverseProxy(path)
|
|
proxy := reverseproxy.NewReverseProxy(path)
|
|
@@ -361,12 +363,12 @@ func (sr *SubServiceRouter) HandleListing(w http.ResponseWriter, r *http.Request
|
|
Disabled: disabled,
|
|
Disabled: disabled,
|
|
})
|
|
})
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Println(err)
|
|
|
|
|
|
+ sr.logger.PrintAndLog("Subservice", "Unable to list subservice folder", err)
|
|
}
|
|
}
|
|
sendJSONResponse(w, string(jsonString))
|
|
sendJSONResponse(w, string(jsonString))
|
|
}
|
|
}
|
|
|
|
|
|
-//Kill the subservice that is currently running
|
|
|
|
|
|
+// Kill the subservice that is currently running
|
|
func (sr *SubServiceRouter) HandleKillSubService(w http.ResponseWriter, r *http.Request) {
|
|
func (sr *SubServiceRouter) HandleKillSubService(w http.ResponseWriter, r *http.Request) {
|
|
userinfo, _ := sr.userHandler.GetUserInfoFromRequest(w, r)
|
|
userinfo, _ := sr.userHandler.GetUserInfoFromRequest(w, r)
|
|
//Require admin permission
|
|
//Require admin permission
|
|
@@ -408,13 +410,13 @@ func (sr *SubServiceRouter) HandleStartSubService(w http.ResponseWriter, r *http
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-//Check if the user has permission to access such proxy module
|
|
|
|
|
|
+// Check if the user has permission to access such proxy module
|
|
func (sr *SubServiceRouter) CheckUserPermissionOnSubservice(ss *SubService, u *user.User) bool {
|
|
func (sr *SubServiceRouter) CheckUserPermissionOnSubservice(ss *SubService, u *user.User) bool {
|
|
moduleName := ss.Info.Name
|
|
moduleName := ss.Info.Name
|
|
return u.GetModuleAccessPermission(moduleName)
|
|
return u.GetModuleAccessPermission(moduleName)
|
|
}
|
|
}
|
|
|
|
|
|
-//Check if the target is reverse proxy. If yes, return the proxy handler and the rewritten url in string
|
|
|
|
|
|
+// Check if the target is reverse proxy. If yes, return the proxy handler and the rewritten url in string
|
|
func (sr *SubServiceRouter) CheckIfReverseProxyPath(r *http.Request) (bool, *reverseproxy.ReverseProxy, string, *SubService) {
|
|
func (sr *SubServiceRouter) CheckIfReverseProxyPath(r *http.Request) (bool, *reverseproxy.ReverseProxy, string, *SubService) {
|
|
requestURL := r.URL.Path
|
|
requestURL := r.URL.Path
|
|
|
|
|
|
@@ -534,7 +536,7 @@ func (sr *SubServiceRouter) StartSubService(serviceDir string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-//Get a list of subservice roots in realpath
|
|
|
|
|
|
+// Get a list of subservice roots in realpath
|
|
func (sr *SubServiceRouter) GetSubserviceRoot() []string {
|
|
func (sr *SubServiceRouter) GetSubserviceRoot() []string {
|
|
subserviceRoots := []string{}
|
|
subserviceRoots := []string{}
|
|
for _, subService := range sr.RunningSubService {
|
|
for _, subService := range sr.RunningSubService {
|
|
@@ -544,7 +546,7 @@ func (sr *SubServiceRouter) GetSubserviceRoot() []string {
|
|
return subserviceRoots
|
|
return subserviceRoots
|
|
}
|
|
}
|
|
|
|
|
|
-//Scan and get the next avaible port for subservice from its basePort
|
|
|
|
|
|
+// Scan and get the next avaible port for subservice from its basePort
|
|
func (sr *SubServiceRouter) GetNextUsablePort() int {
|
|
func (sr *SubServiceRouter) GetNextUsablePort() int {
|
|
basePort := sr.BasePort
|
|
basePort := sr.BasePort
|
|
for sr.CheckIfPortInUse(basePort) {
|
|
for sr.CheckIfPortInUse(basePort) {
|
|
@@ -589,21 +591,21 @@ func (sr *SubServiceRouter) HandleRoutingRequest(w http.ResponseWriter, r *http.
|
|
if err != nil {
|
|
if err != nil {
|
|
//Check if it is cancelling events.
|
|
//Check if it is cancelling events.
|
|
if !strings.Contains(err.Error(), "cancel") {
|
|
if !strings.Contains(err.Error(), "cancel") {
|
|
- log.Println(subserviceObject.Info.Name + " IS NOT RESPONDING!")
|
|
|
|
|
|
+ sr.logger.PrintAndLog("Subservice", subserviceObject.Info.Name+" IS NOT RESPONDING!", err)
|
|
sr.RestartSubService(subserviceObject)
|
|
sr.RestartSubService(subserviceObject)
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-//Handle fail start over when the remote target is not responding
|
|
|
|
|
|
+// Handle fail start over when the remote target is not responding
|
|
func (sr *SubServiceRouter) RestartSubService(ss *SubService) {
|
|
func (sr *SubServiceRouter) RestartSubService(ss *SubService) {
|
|
go func(ss *SubService) {
|
|
go func(ss *SubService) {
|
|
//Kill the original subservice
|
|
//Kill the original subservice
|
|
sr.KillSubService(ss.ServiceDir)
|
|
sr.KillSubService(ss.ServiceDir)
|
|
- log.Println("RESTARTING SUBSERVICE " + ss.Info.Name + " IN 10 SECOUNDS")
|
|
|
|
|
|
+ sr.logger.PrintAndLog("Subservice", "RESTARTING SUBSERVICE "+ss.Info.Name+" IN 10 SECOUNDS", nil)
|
|
time.Sleep(10000 * time.Millisecond)
|
|
time.Sleep(10000 * time.Millisecond)
|
|
sr.StartSubService(ss.ServiceDir)
|
|
sr.StartSubService(ss.ServiceDir)
|
|
- log.Println("SUBSERVICE " + ss.Info.Name + " RESTARTED")
|
|
|
|
|
|
+ sr.logger.PrintAndLog("Subservice", "SUBSERVICE "+ss.Info.Name+" RESTARTED", nil)
|
|
}(ss)
|
|
}(ss)
|
|
}
|
|
}
|