diff --git a/global/global.go b/global/global.go index 4af53b2..bd10d55 100644 --- a/global/global.go +++ b/global/global.go @@ -7,6 +7,7 @@ import ( var ConfigPath *string var DBPath_data *string var DBPath_log *string +var CurrentPath string type SoftwareInfo struct { Name string @@ -22,7 +23,7 @@ var Software = SoftwareInfo{ Version: "0.0.1", Developer: "Madobi Nanami", BuildVer: 1, - BuildType: "release", + BuildType: "pre-release", } type StatusFlags struct { diff --git a/main.go b/main.go index 78062bd..aabf3a1 100644 --- a/main.go +++ b/main.go @@ -21,10 +21,11 @@ import ( ) func main() { + global.CurrentPath = utils.GetCurrentPath() postLog.Info(fmt.Sprintf("%s %s (Build %d.%s) by %s", global.Software.Name, global.Software.Version, global.Software.BuildVer, global.Software.BuildType, global.Software.Developer)) - global.ConfigPath = flag.String("config", "./config.json", "path to config file") - global.DBPath_data = flag.String("db", "./database.db", "path to database file") - global.DBPath_log = flag.String("log", "./logs.db", "path to logs database file") + global.ConfigPath = flag.String("config", global.CurrentPath+string(os.PathSeparator)+"config.json", "path to config file") + global.DBPath_data = flag.String("db", global.CurrentPath+string(os.PathSeparator)+"database.db", "path to database file") + global.DBPath_log = flag.String("log", global.CurrentPath+string(os.PathSeparator)+"logs.db", "path to logs database file") flag.Parse() if _, err := os.Stat(*global.ConfigPath); os.IsNotExist(err) { @@ -66,8 +67,6 @@ func main() { frpLogger.SetDatabase(global.ConfigDB, global.FrpcDB) frpLogger.SetDebugMode(global.CurrentConfig.Debug) - config.GetConfig() - postLog.InitLogBroadcaster() setupRoutes() diff --git a/utils/handlers.go b/utils/handlers.go index dd33912..d6723a4 100644 --- a/utils/handlers.go +++ b/utils/handlers.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" "time" + "path/filepath" "super-frpc/database" "super-frpc/global" @@ -200,3 +201,15 @@ func RestartProcess() error { os.Exit(0) return nil } + +func GetCurrentPath() (string) { + filePath, _ := exec.LookPath(os.Args[0]) + if filePath == "" { + return "" + } + absPath, err := filepath.Abs(filePath) + if err != nil { + return "" + } + return filepath.Dir(absPath) +} \ No newline at end of file diff --git a/watchdog/client.go b/watchdog/client.go index 18e44b2..1b4cac3 100644 --- a/watchdog/client.go +++ b/watchdog/client.go @@ -94,7 +94,7 @@ func syncRunningInstancesToWatchdog() { func ensureWatchdogProcess() error { watchdogName, err := getWatchdogBinaryName() - exec.Command("chmod", "+x", filepath.Join(".", "watchdog", watchdogName)).Run() + exec.Command("chmod", "+x", filepath.Join(global.CurrentPath, "watchdog", watchdogName)).Run() if err != nil { return err } @@ -105,7 +105,7 @@ func ensureWatchdogProcess() error { } postLog.Info(fmt.Sprintf("Watchdog process %s is not running, starting it...", watchdogName)) - watchdogPath := filepath.Join(".", "watchdog", watchdogName) + watchdogPath := filepath.Join(global.CurrentPath, "watchdog", watchdogName) if !utils.IsFileExist(watchdogPath) { return fmt.Errorf("watchdog binary not found: %s", watchdogPath) } @@ -136,7 +136,7 @@ func getWatchdogBinaryName() (string, error) { case "init.d": return "watchdog_initd", nil case "windows": - if utils.IsFileExist(filepath.Join(".", "watchdog", "watchdog_windows.exe")) { + if utils.IsFileExist(filepath.Join(global.CurrentPath, "watchdog", "watchdog_windows.exe")) { return "watchdog_windows.exe", nil } return "watchdog_windows", nil