Skip to content

How to run commands when starting up a Vagrant box

Some of us at Culture Foundry run vagrant instances for development. This virtual machine lets you manage different environments or work in a unix environment if that is your wish. It’s heavier weight than a solution like docker, but depending on your infrastructure and/or sysadmin skills, may be more intuitive.

Our development depends on a database, which may be PostgreSQL or MySQL. However, for the version of Ubuntu that we were running, MySQL didn’t start up, at least the version we were using. After some searching, the easiest solution to implement was just to put the startup script in the Vagrant file. This looks like:

config.vm.provision "shell", inline: "sudo service mysql start", run: "always"

You can use this syntax to run any command you want run once and only once as your Vagrant machine boots up. More on the shell provisioner here.

Cultivate

Join the Culture Foundry Community

Even if you’re not ready to make the leap yet, you’ll find our community to be a helpful source of key insights and advice to help you learn more about how to thrive in digital. All are welcome.

Join the Community