Example #1
0
func teardown() {
	// Clear namespace so that we hit all the VMs
	SetNamespace("")

	vncClear()
	clearAllCaptures()
	vms.Kill(Wildcard)
	dnsmasqKillAll()
	ksmDisable()
	vms.Flush()
	vms.CleanDirs()
	containerTeardown()

	if err := bridgesDestroy(); err != nil {
		log.Errorln(err)
	}

	commandSocketRemove()
	goreadline.Rlcleanup()

	if err := os.Remove(filepath.Join(*f_base, "minimega.pid")); err != nil {
		log.Fatalln(err)
	}

	if cpuProfileOut != nil {
		pprof.StopCPUProfile()
		cpuProfileOut.Close()
	}

	os.Exit(0)
}
Example #2
0
// Nuke all possible leftover state
// Similar to teardown(), but designed to be called from nuke
func nukeState() {
	goreadline.Rlcleanup()
	vncClear()
	clearAllCaptures()
	ksmDisable()
	vms.CleanDirs()
}
Example #3
0
func teardown() {
	vncClear()
	clearAllCaptures()
	vms.kill(Wildcard)
	dnsmasqKillAll()
	err := bridgesDestroy()
	if err != nil {
		log.Errorln(err)
	}
	ksmDisable()
	vms.cleanDirs()
	commandSocketRemove()
	goreadline.Rlcleanup()
	err = os.Remove(*f_base + "minimega.pid")
	if err != nil {
		log.Fatalln(err)
	}
	os.Exit(0)
}
Example #4
0
func cliAttach() {
	// try to connect to the local minimega
	mm, err := DialMinimega()
	if err != nil {
		log.Fatalln(err)
	}

	// set up signal handling
	sig := make(chan os.Signal, 1024)
	signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
	go func() {
		<-sig
		if *f_panic {
			panic("teardown")
		}
		log.Debug("caught signal, disconnecting")
		goreadline.Rlcleanup()
		os.Exit(0)
	}()

	// start our own rlwrap
	fmt.Println("CAUTION: calling 'quit' will cause the minimega daemon to exit")
	fmt.Println("use 'disconnect' or ^d to exit just the minimega command line")
	fmt.Println()
	defer goreadline.Rlcleanup()

	var exitNext bool
	for {
		prompt := fmt.Sprintf("minimega:%v$ ", mm.url)
		line, err := goreadline.Rlwrap(prompt, true)
		if err != nil {
			return
		}
		command := string(line)
		log.Debug("got from stdin: `%s`", line)

		// HAX: Shortcut some commands without using minicli
		if command == "disconnect" {
			log.Debugln("disconnecting")
			return
		} else if command == "quit" {
			if !exitNext {
				fmt.Println("CAUTION: calling 'quit' will cause the minimega daemon to exit")
				fmt.Println("If you really want to stop the minimega daemon, enter 'quit' again")
				exitNext = true
				continue
			}
		}

		exitNext = false

		cmd, err := minicli.CompileCommand(command)
		if err != nil {
			log.Error("%v", err)
			//fmt.Println("closest match: TODO")
			continue
		}

		// No command was returned, must have been a blank line or a comment
		// line. Either way, don't try to run a nil command.
		if cmd == nil {
			continue
		}

		for resp := range mm.runCommand(cmd) {
			pageOutput(resp.Rendered)

			errs := resp.Resp.Error()
			if errs != "" {
				fmt.Fprintln(os.Stderr, errs)
			}
		}

		if command == "quit" {
			return
		}
	}
}
Example #5
0
// Attach creates a CLI interface to the dialed minimega instance
func (mm *Conn) Attach() {
	// set up signal handling
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
	go func() {
		for s := range sig {
			if s == os.Interrupt {
				goreadline.Signal()
			} else {
				log.Debug("caught term signal, disconnecting")
				goreadline.Rlcleanup()
				os.Exit(0)
			}
		}
	}()
	defer signal.Stop(sig)

	// start our own rlwrap
	fmt.Println("CAUTION: calling 'quit' will cause the minimega daemon to exit")
	fmt.Println("use 'disconnect' or ^d to exit just the minimega command line")
	fmt.Println()
	defer goreadline.Rlcleanup()

	var exitNext bool
	for {
		prompt := fmt.Sprintf("minimega:%v$ ", mm.url)
		line, err := goreadline.Readline(prompt, true)
		if err != nil {
			return
		}
		command := string(line)
		log.Debug("got from stdin: `%s`", line)

		// HAX: Shortcut some commands without using minicli
		if command == "disconnect" {
			log.Debugln("disconnecting")
			return
		} else if command == "quit" {
			if !exitNext {
				fmt.Println("CAUTION: calling 'quit' will cause the minimega daemon to exit")
				fmt.Println("If you really want to stop the minimega daemon, enter 'quit' again")
				exitNext = true
				continue
			}
		}

		exitNext = false

		cmd, err := minicli.Compile(command)
		if err != nil {
			log.Error("%v", err)
			//fmt.Println("closest match: TODO")
			continue
		}

		// No command was returned, must have been a blank line or a comment
		// line. Either way, don't try to run a nil command.
		if cmd == nil {
			continue
		}

		mm.RunAndPrint(cmd, true)

		if command == "quit" {
			return
		}
	}
}