Vagrant – Running Rails server in the background

Tagged As:

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'

Leave a Reply

Be the First to Comment!

Notify of