mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
NOISSUE - Stop computation gracefully (#241)
* stop gracefully Signed-off-by: Sammy Oina <sammyoina@gmail.com> * use constant Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
This commit is contained in:
committed by
GitHub
parent
c14a6338cc
commit
2f4ca414cb
@@ -62,14 +62,3 @@ func RunCmdOutput(command string, args ...string) (string, error) {
|
||||
|
||||
return string(output), nil
|
||||
}
|
||||
|
||||
// RunCmdStart starts the specified command and returns the *exec.Cmd for the running process.
|
||||
func RunCmdStart(command string, args ...string) (*exec.Cmd, error) {
|
||||
cmd := exec.Command(command, args...)
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, fmt.Errorf("error starting command '%s': %s", cmd.String(), err)
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
+28
-6
@@ -17,11 +17,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
firmwareVars = "OVMF_VARS"
|
||||
KernelFile = "bzImage"
|
||||
rootfsFile = "rootfs.cpio"
|
||||
tmpDir = "/tmp"
|
||||
interval = 5 * time.Second
|
||||
firmwareVars = "OVMF_VARS"
|
||||
KernelFile = "bzImage"
|
||||
rootfsFile = "rootfs.cpio"
|
||||
tmpDir = "/tmp"
|
||||
interval = 5 * time.Second
|
||||
shutdownTimeout = 30 * time.Second
|
||||
)
|
||||
|
||||
type qemuVM struct {
|
||||
@@ -78,7 +79,28 @@ func (v *qemuVM) Start() (err error) {
|
||||
}
|
||||
|
||||
func (v *qemuVM) Stop() error {
|
||||
return v.cmd.Process.Kill()
|
||||
err := v.cmd.Process.Signal(syscall.SIGTERM)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send SIGTERM: %v", err)
|
||||
}
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := v.cmd.Process.Wait()
|
||||
done <- err
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-done:
|
||||
return err
|
||||
case <-time.After(shutdownTimeout):
|
||||
err := v.cmd.Process.Kill()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to kill process: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *qemuVM) SetProcess(pid int) error {
|
||||
|
||||
Reference in New Issue
Block a user