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.
我有一个rails应用程序,我想在机器启动时自动启动服务器。现在我cd到目录然后键入rails s命令。如何配置我的机器以在启动时运行我的Rail服务器?我正在使用Ubuntu和Rails 3.0.0。
2 个解决方案
#1
6
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
.
您可以使用cron作业。要添加cron作业,请使用命令crontab -e。您可以定义一个在启动时运行并使用@reboot命令重新启动的cron作业。
So you'd have something like:
所以你有类似的东西:
@reboot cd /home/[path to project] && rails server
#2
2
@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
为我做了诀窍。您可能需要重新加载RVM并为此
@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.
将达到目的。
#1
6
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
.
您可以使用cron作业。要添加cron作业,请使用命令crontab -e。您可以定义一个在启动时运行并使用@reboot命令重新启动的cron作业。
So you'd have something like:
所以你有类似的东西:
@reboot cd /home/[path to project] && rails server
#2
2
@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
为我做了诀窍。您可能需要重新加载RVM并为此
@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.
将达到目的。