Skip to content

Instantly share code, notes, and snippets.

@Iristyle
Created March 15, 2013 18:35
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save Iristyle/5171999 to your computer and use it in GitHub Desktop.
Save Iristyle/5171999 to your computer and use it in GitHub Desktop.
Windows startup script to fire up a Vagrant VM safely on boot (using Run registry key for instance)
ECHO OFF
cd /d %~dp0
for /f "tokens=2* delims= " %%F IN ('vagrant status ^| find /I "default"') DO (SET "STATE=%%F%%G")
ECHO Close this window if it remains open, and http://localhost:8081 is responsive
IF "%STATE%" NEQ "saved" (
ECHO Starting Vagrant VM from powered down state...
vagrant up
) ELSE (
ECHO Resuming Vagrant VM from saved state...
vagrant resume
)
if errorlevel 1 (
ECHO FAILURE! Vagrant VM unresponsive...
)
@Iristyle
Copy link
Author

Intended to be run from the directory containing .vagrant and Vagrantfile

@ganni
Copy link

ganni commented Mar 4, 2015

THank you!

@AnsPunktF
Copy link

This helped me a lot, but I've changed it a little bit for my scripts.

Maybe this is useful:

for /f "tokens=2* delims=," %%F IN ('vagrant status --machine-readable ^| find /I "state-human-short"') DO (SET "STATE=%%F%%G")
SET STATE=%STATE:~25%

It's just because %STATE% returned crap, if vagrantbox doesn't exist.

The first chars of STATE will be "defaultstate-human-short," (25 chars). You should cut them off.

@emrahoruc
Copy link

Use Vagrant Manager. It is amazing.
http://vagrantmanager.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment