I need to cd to a directory and run the 'rails server' command after bootup. example
cd /home/bab/rails/app/
then when am in the app directory it runs the rails server command.
Can some1 help me with this...using ubuntu 9.10 and rails 3.0.0
try to add to /etc/rc.local
this:
ruby /path/to/your/app/script/rails s -P /path/to/your/app/tmp/pids/server.pid -c /path/to/your/app/config.ru -d
But better to use passenger gem
here with Nginx or Apache
It is easy to setup and easy to use
I've was getting the same error with RVM, ruby, and rails. My directory is /home/user/rails-project/
. Putting this in .bashrc
allows me to use the "rvm" command:
source ~/.rvm/scripts/rvm
server$:which rails
:
/home/user/.rvm/gems/ruby-2.2.1/bin/rails
The above shows the current rails bin.
So, the final command in rc.local
is:
su user-c "source ~/.rvm/scripts/rvm ; cd /home/user/rails-project/ ; /home/user/.rvm/gems/ruby-2.2.1/bin/rails s -d -e production"
You can use this code in rc.local
to debug:
exec 2> /tmp/rc.local.log # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x # tell sh to display commands before execution
Use sudo service rc.local start
for testing without a reboot.
I was able to accomplish this in the following way:
create a script "rails.run" with the following line to start the ruby on rails with the desired user and parameters:
sudo -H -u <username> bash -c '/home/username/.rbenv/versions/2.2.3/bin/ruby bin/rails server --port=3000 --binding=ip_address -d'
Then add the script in the rc.local file with a simple line such as:
/home/username/rails.run
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.