|
@@ -16,6 +16,7 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
+ "imuslab.com/arozos/mod/info/logger"
|
|
|
modules "imuslab.com/arozos/mod/modules"
|
|
|
"imuslab.com/arozos/mod/network/reverseproxy"
|
|
|
"imuslab.com/arozos/mod/network/websocketproxy"
|
|
@@ -48,9 +49,13 @@ type SubServiceRouter struct {
|
|
|
listenPort int
|
|
|
userHandler *user.UserHandler
|
|
|
moduleHandler *modules.ModuleHandler
|
|
|
+ logger *logger.Logger
|
|
|
}
|
|
|
|
|
|
func NewSubServiceRouter(ReservePaths []string, basePort int, userHandler *user.UserHandler, moduleHandler *modules.ModuleHandler, parentPort int) *SubServiceRouter {
|
|
|
+ //Create a service logger
|
|
|
+ thisLogger, _ := logger.NewLogger("system", "system/logs/subservice", true)
|
|
|
+
|
|
|
return &SubServiceRouter{
|
|
|
ReservePaths: ReservePaths,
|
|
|
RunningSubService: []SubService{},
|
|
@@ -59,6 +64,7 @@ func NewSubServiceRouter(ReservePaths []string, basePort int, userHandler *user.
|
|
|
listenPort: parentPort,
|
|
|
userHandler: userHandler,
|
|
|
moduleHandler: moduleHandler,
|
|
|
+ logger: thisLogger,
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -72,7 +78,8 @@ func (sr *SubServiceRouter) LoadSubservicesFromRootPath(rootpath string) {
|
|
|
//Only enable module with no suspended config file
|
|
|
err := sr.Launch(servicePath, true)
|
|
|
if err != nil {
|
|
|
- log.Println(err)
|
|
|
+ sr.logger.PrintAndLog("Subservice", "Failed to start subservice: "+filepath.Base(servicePath)+" "+err.Error(), err)
|
|
|
+ //log.Println(err)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -95,8 +102,8 @@ func (sr *SubServiceRouter) Launch(servicePath string, startupMode bool) error {
|
|
|
if fileExists(servicePath + "/.startscript") {
|
|
|
//Launch from start.bat or start.sh
|
|
|
if !(fileExists(servicePath+"/start.sh") || fileExists(servicePath+"/start.bat")) {
|
|
|
- log.Println("Failed to load subservice: " + serviceRoot + ", .startscript flag is TRUE but no start script found")
|
|
|
- return errors.New("Failed to load subservice")
|
|
|
+ //log.Println("Failed to load subservice: " + serviceRoot + ", .startscript flag is TRUE but no start script found")
|
|
|
+ return errors.New(".startscript flag is TRUE but no start script found")
|
|
|
}
|
|
|
|
|
|
startScriptName := "start.sh"
|
|
@@ -109,10 +116,10 @@ func (sr *SubServiceRouter) Launch(servicePath string, startupMode bool) error {
|
|
|
//No startscript defined. Start from binary files if exists
|
|
|
if runtime.GOOS == "windows" && !fileExists(servicePath+"/"+binaryExecPath) {
|
|
|
if startupMode {
|
|
|
- log.Println("Failed to load subservice: "+serviceRoot, " File not exists "+servicePath+"/"+binaryExecPath+". Skipping this service")
|
|
|
- return errors.New("Failed to load subservice")
|
|
|
+ //log.Println("Failed to load subservice: " + serviceRoot)
|
|
|
+ return errors.New("Subservice executable not exists " + servicePath + "/" + binaryExecPath + ". Skipping this service")
|
|
|
} else {
|
|
|
- return errors.New("Failed to load subservice")
|
|
|
+ return errors.New("Subservice executable " + servicePath + "/" + binaryExecPath + ". Skipping this service")
|
|
|
}
|
|
|
|
|
|
} else if runtime.GOOS == "linux" {
|
|
@@ -123,18 +130,17 @@ func (sr *SubServiceRouter) Launch(servicePath string, startupMode bool) error {
|
|
|
//This is not installed. Check if it exists as a binary (aka ./myservice)
|
|
|
if !fileExists(servicePath + "/" + binaryExecPath) {
|
|
|
if startupMode {
|
|
|
- log.Println("Package not installed. " + serviceRoot)
|
|
|
- return errors.New("Failed to load subservice: Package not installed")
|
|
|
+ //log.Println("Package not installed. " + serviceRoot)
|
|
|
+ return errors.New("Package not installed")
|
|
|
} else {
|
|
|
- return errors.New("Package not installed.")
|
|
|
+ return errors.New("Package not installed")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if runtime.GOOS == "darwin" {
|
|
|
//Skip the whereis approach that linux use
|
|
|
if !fileExists(servicePath + "/" + binaryExecPath) {
|
|
|
- log.Println("Failed to load subservice: "+serviceRoot, " File not exists "+servicePath+"/"+binaryExecPath+". Skipping this service")
|
|
|
- return errors.New("Failed to load subservice")
|
|
|
+ return errors.New("Subservice executable not exists " + servicePath + "/" + binaryExecPath + ". Skipping this service")
|
|
|
}
|
|
|
}
|
|
|
}
|