Vagrant – Running Rails server in the background

Let’s say when you boot up or restart your virtual machine, you want to run the Rails server in the background for your Rails application.

It is pretty easy. First, let’s create a function for the script block. Put following code on the top of the Vagrant file.

def start_rails_server
cd /vagrant
# start rails server as a daemon
# to kill: sudo kill `cat tmp/pids/`
rails s -d

Now in the Vagrantfile configuration block, use the script function and set it to run always. 

Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: start_rails_server, run: 'always'
0 0 votes
Article Rating

By Sinaru Gunawardena

Sinaru is a software developer at work and a painter in free time. He enjoys writing tech notes on his personal website. He currently lives in Dublin, Ireland.

Notify of
Inline Feedbacks
View all comments