2 Commits
2 changed files with 11 additions and 3 deletions
+2 -2
View File
@@ -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)
} }
} }
@@ -358,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()
+9 -1
View File
@@ -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
syscall.Kill(-pid, syscall.SIGKILL) if pid != 0 {
syscall.Kill(-pid, syscall.SIGKILL)
}
if service.Type == "simple" && err == nil { if service.Type == "simple" && err == nil {
service.restartCount = 0 service.restartCount = 0