Vagrant – Running Rails server in the background

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
<<-SHELL
cd /vagrant
# start rails server as a daemon
# to kill: sudo kill `cat tmp/pids/server.pid`
rails s -d
SHELL
end

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'
...
end
0 0 votes
Article Rating

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x