mirror of
https://github.com/EnumeratedDev/enit.git
synced 2026-09-16 02:26:11 +00:00
Only wait for background service processes to exit
This commit is contained in:
+16
-19
@@ -325,12 +325,7 @@ func (service *EnitService) StartService() (err error) {
|
|||||||
// Reload service if needed
|
// Reload service if needed
|
||||||
if service.shouldReload {
|
if service.shouldReload {
|
||||||
LoadService(service.Filepath)
|
LoadService(service.Filepath)
|
||||||
if GetServiceByName(service.Name) == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
service.state = EnitServiceRunning
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -423,22 +418,24 @@ func (service *EnitService) StopService() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the process has stopped gracefully, otherwise send sigkill on timeout
|
if service.Type == "background" {
|
||||||
exited := make(chan bool)
|
// Check if the process has stopped gracefully, otherwise send sigkill on timeout
|
||||||
go func() {
|
exited := make(chan bool)
|
||||||
for {
|
go func() {
|
||||||
if err := syscall.Kill(pid, syscall.Signal(0)); err != nil {
|
for {
|
||||||
break
|
if err := syscall.Kill(pid, syscall.Signal(0)); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
exited <- true
|
||||||
exited <- true
|
}()
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-exited:
|
case <-exited:
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
service.GetProcess().Signal(syscall.SIGKILL)
|
service.GetProcess().Signal(syscall.SIGKILL)
|
||||||
return fmt.Errorf("could not stop process gracefully")
|
return fmt.Errorf("could not stop process gracefully")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newServiceStatus = EnitServiceStopped
|
newServiceStatus = EnitServiceStopped
|
||||||
|
|||||||
Reference in New Issue
Block a user