feat: migrate to golang
This commit is contained in:
50
internal/service/status.go
Normal file
50
internal/service/status.go
Normal file
@ -0,0 +1,50 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Status returns a human-readable status string for the named service.
|
||||
// Direct port of CoreManager.get_service_status (core_manager.py:389-434).
|
||||
func Status(name string) string {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
out, err := exec.Command("sc", "query", name).CombinedOutput()
|
||||
if err != nil {
|
||||
return "Service not installed or not found"
|
||||
}
|
||||
for _, line := range strings.Split(string(out), "\n") {
|
||||
if strings.Contains(line, "STATE") {
|
||||
return strings.TrimSpace(line)
|
||||
}
|
||||
}
|
||||
return "Service exists but status unknown"
|
||||
|
||||
case "linux":
|
||||
out, err := exec.Command("systemctl", "is-active", name).CombinedOutput()
|
||||
status := strings.TrimSpace(string(out))
|
||||
if err != nil {
|
||||
return "Service not installed or not found"
|
||||
}
|
||||
if status == "active" {
|
||||
return "Service is running"
|
||||
}
|
||||
return "Service is " + status
|
||||
|
||||
case "darwin":
|
||||
out, err := exec.Command("launchctl", "list").CombinedOutput()
|
||||
if err != nil {
|
||||
return "Error checking service status: " + err.Error()
|
||||
}
|
||||
output := string(out)
|
||||
if strings.Contains(output, name) || strings.Contains(output, "com."+name) {
|
||||
return "Service is loaded (check launchctl status for details)"
|
||||
}
|
||||
return "Service not installed or not loaded"
|
||||
|
||||
default:
|
||||
return "Unsupported system: " + runtime.GOOS
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user