2 Commits
Author SHA1 Message Date
EnumDev 8abc4cf49c Tweak timeouts 2025-11-25 21:52:21 +02:00
EnumDev e5c465610c Only wait for background service processes to exit 2025-11-24 16:34:55 +02:00
4 changed files with 33 additions and 58 deletions
+1 -1
View File
@@ -405,7 +405,7 @@ func dialSocket() {
log.Fatalf("Failed to connect to esvm.sock! Error: %s\n", err) log.Fatalf("Failed to connect to esvm.sock! Error: %s\n", err)
} }
if err := conn.SetDeadline(time.Now().Add(5 * time.Second)); err != nil { if err := conn.SetDeadline(time.Now().Add(30 * time.Second)); err != nil {
log.Fatalf("Failed to set write deadline! Error: %s\n", err) log.Fatalf("Failed to set write deadline! Error: %s\n", err)
} }
} }
+1 -1
View File
@@ -175,7 +175,7 @@ func stopServiceManager() {
case <-exited: case <-exited:
fmt.Println("Done.") fmt.Println("Done.")
return return
case <-time.After(60 * time.Second): case <-time.After(300 * time.Second):
log.Println("Could not stop service manager!") log.Println("Could not stop service manager!")
syscall.Kill(serviceManagerPid, syscall.SIGKILL) syscall.Kill(serviceManagerPid, syscall.SIGKILL)
return return
+15 -37
View File
@@ -280,25 +280,14 @@ func unmountFilesystems() {
// Unmount filesystem at mountpoint // Unmount filesystem at mountpoint
fmt.Printf("Unmounting %s...", mountpoint) fmt.Printf("Unmounting %s...", mountpoint)
tries := 0 err := unix.Unmount(mountpoint, 0)
for { if errors.Is(err, syscall.EBUSY) {
err := unix.Unmount(mountpoint, 0) fmt.Println(" Busy.")
if errors.Is(err, syscall.EBUSY) { time.Sleep(1 * time.Second)
fmt.Print(".") } else if err != nil {
tries++ fmt.Printf(" Error: %s\n", err.Error())
time.Sleep(1 * time.Second) } else {
if tries >= 60 { fmt.Println(" Done.")
unix.Unmount(mountpoint, syscall.MNT_FORCE)
fmt.Println(" Timeout.")
break
}
} else if err != nil {
fmt.Printf(" Error: %s\n", err.Error())
break
} else {
fmt.Println(" Done.")
break
}
} }
} }
} }
@@ -341,23 +330,12 @@ func remountRootReadonly() {
} }
} }
tries := 0 err = unix.Mount(source, "/", filesystem, syscall.MS_RDONLY|syscall.MS_REMOUNT, fsData)
for { if errors.Is(err, syscall.EBUSY) {
err := unix.Mount(source, "/", filesystem, syscall.MS_RDONLY|syscall.MS_REMOUNT, fsData) fmt.Println(" Busy.")
if errors.Is(err, syscall.EBUSY) { } else if err != nil {
fmt.Print(".") fmt.Printf(" Error: %s\n", err.Error())
tries++ } else {
time.Sleep(1 * time.Second) fmt.Println(" Done.")
if tries >= 60 {
fmt.Println(" Timeout.")
break
}
} else if err != nil {
fmt.Printf(" Error: %s\n", err.Error())
break
} else {
fmt.Println(" Done.")
break
}
} }
} }
+16 -19
View File
@@ -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(15 * 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