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
+3 -25
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
for {
err := unix.Unmount(mountpoint, 0) err := unix.Unmount(mountpoint, 0)
if errors.Is(err, syscall.EBUSY) { if errors.Is(err, syscall.EBUSY) {
fmt.Print(".") fmt.Println(" Busy.")
tries++
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
if tries >= 60 {
unix.Unmount(mountpoint, syscall.MNT_FORCE)
fmt.Println(" Timeout.")
break
}
} else if err != nil { } else if err != nil {
fmt.Printf(" Error: %s\n", err.Error()) fmt.Printf(" Error: %s\n", err.Error())
break
} else { } else {
fmt.Println(" Done.") 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 {
err := unix.Mount(source, "/", filesystem, syscall.MS_RDONLY|syscall.MS_REMOUNT, fsData)
if errors.Is(err, syscall.EBUSY) { if errors.Is(err, syscall.EBUSY) {
fmt.Print(".") fmt.Println(" Busy.")
tries++
time.Sleep(1 * time.Second)
if tries >= 60 {
fmt.Println(" Timeout.")
break
}
} else if err != nil { } else if err != nil {
fmt.Printf(" Error: %s\n", err.Error()) fmt.Printf(" Error: %s\n", err.Error())
break
} else { } else {
fmt.Println(" Done.") fmt.Println(" Done.")
break
}
} }
} }
+3 -6
View File
@@ -325,13 +325,8 @@ 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
} }
if !service.CrashOnSafeExit { if !service.CrashOnSafeExit {
@@ -423,6 +418,7 @@ func (service *EnitService) StopService() error {
} }
} }
if service.Type == "background" {
// Check if the process has stopped gracefully, otherwise send sigkill on timeout // Check if the process has stopped gracefully, otherwise send sigkill on timeout
exited := make(chan bool) exited := make(chan bool)
go func() { go func() {
@@ -436,10 +432,11 @@ func (service *EnitService) StopService() error {
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
logger.Printf("Service (%s) has stopped!\n", service.Name) logger.Printf("Service (%s) has stopped!\n", service.Name)