Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start rails server automatically when ever I start my ubuntu machine

I have a rails application and I want to start the server automatically whenever the machine boots up. Right now I cd to the directory and then type the rails s command. How can I configure my machine to run my Rail server on boot? I am using Ubuntu and Rails 3.0.0.

like image 910
bsanneh Avatar asked Apr 06 '11 08:04

bsanneh


2 Answers

You can use a cron job for this. To add the cron job use the command crontab -e. Than you can define a cron job that runs at boot and reboot with @reboot command.

So you'd have something like:

@reboot cd /home/[path to project] && rails server
like image 148
Stefaan Colman Avatar answered Nov 15 '22 11:11

Stefaan Colman


@reboot /bin/bash -l -c 'cd PATH_TO_PROJECT && rails s'

did the trick for me. You might need to reload RVM and for that

@reboot /bin/bash -l -c 'cd PATH_TO_PROJECT && source ~/.rvm/scripts/rvm && rvm use ruby-RUBY_VERSION_HERE && rails s'

will serve the purpose.

like image 30
Saqib R. Avatar answered Nov 15 '22 11:11

Saqib R.