Пример #1
0
// destroy
func destroy(ccmd *cobra.Command, args []string) {

	// PreRun: runnable

	// if the command is being run with --remove-entry, it means an entry needs
	// to be removed from the hosts file and execution yielded back to the parent
	if removeEntry {
		hosts.RemoveDomain()
		os.Exit(0) // this exits the sudoed (child) destroy, not the parent proccess
	}

	// destroy the vm; this needs to happen before cleaning up the app to ensure
	// there is a Vagrantfile to run the command with (otherwise it will just get
	// re-created)
	fmt.Printf(stylish.Bullet("Destroying nanobox..."))
	fmt.Printf(stylish.Bullet("Nanobox may require admin privileges to modify your /etc/hosts and /etc/exports files."))
	if err := vagrant.Destroy(); err != nil {

		// dont care if the project no longer exists... thats what we're doing anyway
		if err != err.(*os.PathError) {
			vagrant.Fatal("[commands/destroy] vagrant.Destroy() failed", err.Error())
		}
	}

	// remove app; this needs to happen after the VM is destroyed so that the app
	// isn't just created again upon running the vagrant command
	fmt.Printf(stylish.Bullet("Deleting nanobox files (%s)", config.AppDir))
	if err := os.RemoveAll(config.AppDir); err != nil {
		config.Fatal("[commands/destroy] os.RemoveAll() failed", err.Error())
	}

	// attempt to remove the entry regardless of whether its there or not
	util.PrivilegeExec("dev destroy --remove-entry", fmt.Sprintf("Removing %s domain from /etc/hosts", config.Nanofile.Domain))
}
Пример #2
0
//
// create
func create(ccmd *cobra.Command, args []string) {

	// PreRun: initialize

	// if the command is being run with the "add" flag, it means an entry needs to
	// be added to the hosts file and execution yielded back to the parent
	if addEntry {
		Hosts.AddDomain()
		os.Exit(0) // this exits the sudoed (child) created, not the parent proccess
	}

	// boot the vm
	fmt.Printf(stylish.Bullet("Creating a nanobox"))
	fmt.Printf(stylish.Bullet("Nanobox may require admin privileges to modify your /etc/hosts and /etc/exports files."))
	if err := vagrant.Up(); err != nil {
		vagrant.Fatal("[commands/create] vagrant.Up() failed", err.Error())
	}

	// after the machine boots, update the docker images
	updateImages(nil, args)

	// add the entry if needed
	if !Hosts.HasDomain() {
		privilegeExec("create --add-entry", fmt.Sprintf("Adding %v domain to hosts file", config.Nanofile.Domain))
	}

	// if devmode is detected, the machine needs to be rebooted for devmode to take
	// effect
	if config.Devmode {
		fmt.Printf(stylish.Bullet("Rebooting machine to finalize 'devmode' configuration..."))
		reload(nil, args)
	}
}
Пример #3
0
// ssh
func ssh(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	fmt.Printf(stylish.Bullet("SSHing into nanobox..."))
	if err := vagrant.SSH(); err != nil {
		vagrant.Fatal("[commands/ssh] vagrant.SSH() failed", err.Error())
	}
}
Пример #4
0
// resume runs 'vagrant resume'
func resume(ccmd *cobra.Command, args []string) {

	// PreRun: initialize

	fmt.Printf(stylish.Bullet("Resuming nanobox..."))
	if err := vagrant.Resume(); err != nil {
		vagrant.Fatal("[commands/resume] vagrant.Resume() failed", err.Error())
	}
}
Пример #5
0
// stop runs 'vagrant suspend'
func stop(ccmd *cobra.Command, args []string) {

	// PreRun: initialize

	//
	if err := vagrant.Suspend(); err != nil {
		vagrant.Fatal("[commands/stop] vagrant.Suspend() failed", err.Error())
	}

	// boot the machine normally (not backgrounded) on next command
	config.VMfile.BackgroundIs(false)
}
Пример #6
0
// reload runs 'vagrant reload --provision'
func reload(ccmd *cobra.Command, args []string) {

	// PreRun: initialize

	//
	fmt.Printf(stylish.Bullet("Reloading nanobox..."))
	fmt.Printf(stylish.Bullet("Nanobox may require admin privileges to modify your /etc/hosts file and /etc/exports."))
	if err := vagrant.Reload(); err != nil {
		vagrant.Fatal("[commands/reload] vagrant.Reload() failed", err.Error())
	}

	// indeicate that the VM has recently been reloaded
	config.VMfile.ReloadedIs(true)
}
Пример #7
0
// reload runs 'vagrant reload --provision'
func reload(ccmd *cobra.Command, args []string) {

	// PreRun: initialize

	// generate a new Vagrantfile on reload; this is done because there may be times
	// when a user needs a new Vagrantfile (ie. adding a custom engine after the VM
	// already exists). The only way to accomplish this otherwise is either destroying
	// the VM entirely or running the hidden "nanobox init -f"
	Vagrant.Init()

	//
	fmt.Printf(stylish.Bullet("Reloading nanobox..."))
	fmt.Printf(stylish.Bullet("Nanobox may require admin privileges to modify your /etc/hosts and /etc/exports files."))
	if err := vagrant.Reload(); err != nil {
		vagrant.Fatal("[commands/reload] vagrant.Reload() failed", err.Error())
	}

	// indeicate that the VM has recently been reloaded
	config.VMfile.ReloadedIs(true)
}