예제 #1
0
// initialize
func initialize(ccmd *cobra.Command, args []string) {

	// PreRun: runnable

	// check to see if a box needs to be installed
	box.Install(nil, args)

	// creates a project folder at ~/.nanobox/apps/<name> where the Vagrantfile and
	// .vagrant dir will live for each app
	if err := os.MkdirAll(config.AppDir, 0755); err != nil {
		config.Fatal("[commands/init] os.Mkdir() failed", err.Error())
	}

	// set up a dedicated vagrant logger
	vagrant.NewLogger(config.AppDir + "/vagrant.log")

	// set up a dedicated server logger
	server.NewLogger(config.AppDir + "/server.log")

	// 'parse' the .vmfile (either creating one, or parsing it)
	config.VMfile = config.ParseVMfile()

	//
	// generate a Vagrantfile at ~/.nanobox/apps/<app-name>/Vagrantfile
	// only if one doesn't already exist (unless forced)
	if !config.Force {
		if _, err := os.Stat(config.AppDir + "/Vagrantfile"); err == nil {
			return
		}
	}

	vagrant.Init()
}
예제 #2
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())
	}

	// indicate that the VM has recently been reloaded; we do this under the assumption
	// that the reload command was called because something went wrong with the VM
	// and a user is trying to "reset" things.
	config.VMfile.ReloadedIs(true)
}