Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process self-destruction mechanism for vm-supervisor #16

Closed
yaroslav-gwit opened this issue May 16, 2023 · 1 comment
Closed

Process self-destruction mechanism for vm-supervisor #16

yaroslav-gwit opened this issue May 16, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@yaroslav-gwit
Copy link
Owner

There is no exact number to be named, but for some weird reason after issuing 4-6 reboot commands from within the VM, the vm-supervisor process can't start a new bhyve child.

To resolve this issue I'll need to create a self-destruction mechanism for the parent process for vm-supervisor, whenever it sees that the VM was rebooted. And then simply start a new detached process that will execute hoster vm start vm-name again to start the VM.

@yaroslav-gwit yaroslav-gwit added the bug Something isn't working label May 16, 2023
@yaroslav-gwit yaroslav-gwit self-assigned this May 16, 2023
@yaroslav-gwit yaroslav-gwit changed the title Process self-destroy mechanism for vm-supervisor Process self-destruction mechanism for vm-supervisor May 16, 2023
@yaroslav-gwit
Copy link
Owner Author

Completely re-written the main() function loop to deal with all possible child exit cases:

		done := make(chan error)
		startVmProcess(hupCmd, done)
		wg.Wait()

		processErr := <-done
		if processErr != nil {
			logFileOutput(LOG_SUPERVISOR, "VM child process ended with a non-zero exit code: " + processErr.Error())
		}

		processExitStatus, correctReturnType := processErr.(*exec.ExitError)
		if correctReturnType {
			exitCode := processExitStatus.ProcessState.ExitCode()
			if exitCode == 1 || exitCode == 2 {
				logFileOutput(LOG_SUPERVISOR, "Bhyve received a shutdown signal: " + strconv.Itoa(exitCode) + ". Executing the shutdown sequence...")
				logFileOutput(LOG_SUPERVISOR, "Shutting down -> Performing network cleanup")
				cmd.NetworkCleanup(vmName, true)
				logFileOutput(LOG_SUPERVISOR, "Shutting down -> Performing Bhyve cleanup")
				cmd.BhyvectlDestroy(vmName, true)
				logFileOutput(LOG_SUPERVISOR, "SUPERVISED SESSION ENDED. The VM has been shutdown.")
				os.Exit(0)
			} else {
				logFileOutput(LOG_SUPERVISOR, "Bhyve returned a panic exit code: " + strconv.Itoa(exitCode))
				logFileOutput(LOG_SUPERVISOR, "Shutting down all VM related processes and performing system clean up")
				cmd.NetworkCleanup(vmName, true)
				cmd.BhyvectlDestroy(vmName, true)
				logFileOutput(LOG_SUPERVISOR, "SUPERVISED SESSION ENDED. Unexpected exit code.")
				os.Exit(101)
			}
		} else {
			logFileOutput(LOG_SUPERVISOR, "Bhyve received a reboot signal. Executing the reboot sequence...")
			logFileOutput(LOG_SUPERVISOR, "Rebooting -> Performing network cleanup")
			cmd.NetworkCleanup(vmName, true)
			logFileOutput(LOG_SUPERVISOR, "Rebooting -> Performing Bhyve cleanup")
			cmd.BhyvectlDestroy(vmName, true)
			logFileOutput(LOG_SUPERVISOR, "SUPERVISED SESSION ENDED. The VM will start back up in a moment.")
			restartVmProcess(vmName)
			os.Exit(0)
		}
		logFileOutput(LOG_SUPERVISOR, "SUPERVISED SESSION ENDED. SOMETHING UNPREDICTED HAPPENED! THE PROCESS HAD TO EXIT!")
		cmd.NetworkCleanup(vmName, true)
		cmd.BhyvectlDestroy(vmName, true)
		os.Exit(1000)
	}

The issue can be closed, as VM Supervisor now works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant