mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-21 21:27:34 +08:00
cli cleanup phase3: unify gateway scope preference parsing via shared helper
This commit is contained in:
@@ -740,14 +740,22 @@ func gatewayServiceControlCmd(action string) error {
|
|||||||
return runSystemctl(scope, action, gatewayServiceName)
|
return runSystemctl(scope, action, gatewayServiceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func gatewayScopePreference() string {
|
||||||
|
v := strings.ToLower(strings.TrimSpace(os.Getenv("CLAWGO_GATEWAY_SCOPE")))
|
||||||
|
if v == "user" || v == "system" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func detectGatewayServiceScopeAndPath() (string, string, error) {
|
func detectGatewayServiceScopeAndPath() (string, string, error) {
|
||||||
if runtime.GOOS != "linux" {
|
if runtime.GOOS != "linux" {
|
||||||
return "", "", fmt.Errorf("gateway service registration currently supports Linux systemd only")
|
return "", "", fmt.Errorf("gateway service registration currently supports Linux systemd only")
|
||||||
}
|
}
|
||||||
if strings.ToLower(strings.TrimSpace(os.Getenv("CLAWGO_GATEWAY_SCOPE"))) == "user" {
|
switch gatewayScopePreference() {
|
||||||
|
case "user":
|
||||||
return userGatewayUnitPath()
|
return userGatewayUnitPath()
|
||||||
}
|
case "system":
|
||||||
if strings.ToLower(strings.TrimSpace(os.Getenv("CLAWGO_GATEWAY_SCOPE"))) == "system" {
|
|
||||||
return "system", "/etc/systemd/system/" + gatewayServiceName, nil
|
return "system", "/etc/systemd/system/" + gatewayServiceName, nil
|
||||||
}
|
}
|
||||||
if os.Geteuid() == 0 {
|
if os.Geteuid() == 0 {
|
||||||
@@ -781,7 +789,7 @@ func detectInstalledGatewayService() (string, string, error) {
|
|||||||
userExists = true
|
userExists = true
|
||||||
}
|
}
|
||||||
|
|
||||||
preferredScope := strings.ToLower(strings.TrimSpace(os.Getenv("CLAWGO_GATEWAY_SCOPE")))
|
preferredScope := gatewayScopePreference()
|
||||||
switch preferredScope {
|
switch preferredScope {
|
||||||
case "system":
|
case "system":
|
||||||
if systemExists {
|
if systemExists {
|
||||||
|
|||||||
Reference in New Issue
Block a user