mirror of
https://github.com/EnumeratedDev/enit.git
synced 2026-09-16 10:36:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49541f6f76
|
||
|
|
fc738e6f4e
|
||
|
|
87ea28bfa3
|
@@ -285,7 +285,7 @@ func showServiceStatus() {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Printf("Enabled: %t\n", serviceEnabled)
|
fmt.Printf("Enabled: %t\n", serviceEnabled)
|
||||||
}
|
}
|
||||||
if serviceState == "running" {
|
if serviceState == "running" && processID > 0 {
|
||||||
fmt.Printf("Process ID: %d\n", processID)
|
fmt.Printf("Process ID: %d\n", processID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,12 +319,6 @@ func listAllServices() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print json data if flag is set
|
|
||||||
if printJson {
|
|
||||||
fmt.Println(string(data))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decoode JSON data
|
// Decoode JSON data
|
||||||
var returnedJsonData map[string]any
|
var returnedJsonData map[string]any
|
||||||
err = json.Unmarshal(data, &returnedJsonData)
|
err = json.Unmarshal(data, &returnedJsonData)
|
||||||
@@ -336,12 +330,24 @@ func listAllServices() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set is_enabled and stage fields in json data
|
||||||
|
for _, serviceMap := range returnedJsonData["services"].([]any) {
|
||||||
|
serviceMap.(map[string]any)["is_enabled"], serviceMap.(map[string]any)["stage"] = isServiceEnabled(serviceMap.(map[string]any)["name"].(string))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print json data if flag is set
|
||||||
|
if printJson {
|
||||||
|
data, _ = json.Marshal(returnedJsonData)
|
||||||
|
fmt.Println(string(data))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, serviceMap := range returnedJsonData["services"].([]any) {
|
for _, serviceMap := range returnedJsonData["services"].([]any) {
|
||||||
serviceName := serviceMap.(map[string]any)["name"].(string)
|
serviceName := serviceMap.(map[string]any)["name"].(string)
|
||||||
serviceDescription := serviceMap.(map[string]any)["description"].(string)
|
serviceDescription := serviceMap.(map[string]any)["description"].(string)
|
||||||
serviceState := serviceMap.(map[string]any)["state"].(string)
|
serviceState := serviceMap.(map[string]any)["state"].(string)
|
||||||
serviceEnabled := serviceMap.(map[string]any)["is_enabled"].(bool)
|
serviceEnabled := serviceMap.(map[string]any)["is_enabled"].(bool)
|
||||||
serviceStage := int(serviceMap.(map[string]any)["stage"].(float64))
|
serviceStage := int(serviceMap.(map[string]any)["stage"].(int))
|
||||||
processID := int(serviceMap.(map[string]any)["process_id"].(float64))
|
processID := int(serviceMap.(map[string]any)["process_id"].(float64))
|
||||||
|
|
||||||
fmt.Printf("Name: %s\n", serviceName)
|
fmt.Printf("Name: %s\n", serviceName)
|
||||||
@@ -352,7 +358,7 @@ func listAllServices() {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Printf("Enabled: %t\n", serviceEnabled)
|
fmt.Printf("Enabled: %t\n", serviceEnabled)
|
||||||
}
|
}
|
||||||
if serviceState == "running" {
|
if serviceState == "running" && processID > 0 {
|
||||||
fmt.Printf("Process ID: %d\n", processID)
|
fmt.Printf("Process ID: %d\n", processID)
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|||||||
@@ -326,6 +326,12 @@ func (service *EnitService) StartService() (err error) {
|
|||||||
|
|
||||||
service.state = EnitServiceRunning
|
service.state = EnitServiceRunning
|
||||||
|
|
||||||
|
// Set PID to 0 for simple services with a stop command
|
||||||
|
if service.Type == "simple" && service.StopCmd != "" {
|
||||||
|
pid = 0
|
||||||
|
service.processID = 0
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := cmd.Wait()
|
err := cmd.Wait()
|
||||||
|
|
||||||
@@ -339,7 +345,9 @@ func (service *EnitService) StartService() (err error) {
|
|||||||
service.restartCount = 0
|
service.restartCount = 0
|
||||||
default:
|
default:
|
||||||
// Kill remaining child processes
|
// Kill remaining child processes
|
||||||
|
if pid != 0 {
|
||||||
syscall.Kill(-pid, syscall.SIGKILL)
|
syscall.Kill(-pid, syscall.SIGKILL)
|
||||||
|
}
|
||||||
|
|
||||||
if service.Type == "simple" && err == nil {
|
if service.Type == "simple" && err == nil {
|
||||||
service.restartCount = 0
|
service.restartCount = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user