ruby on rails : 如何在重启时使 "rc.local" 运行

ruby on rails : How can I make "rc.local" run when reboot

这是我的rc.local。

sh /var/www/test.sh   
exit 0

这是我的 test.sh

cd /home/jeff/test && rails s Puma -d

问题是找不到 rmv 并且 ruby 在 usr/bin(1.9.3) 中。我的 ruby 正确版本是 2.1.5。我该如何解决这个问题?

也许我应该添加 test.sh 的路径,但我不知道如何让它识别 ruby 2.1.5 的路径。

我自己找到了答案。 在 rc.local 文件中,我在下面写了这个。

#!/bin/bash
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
cd /home/jeff/thingspeak@
source /etc/profile.d/rvm.sh
source $(rvm 2.1.0 do rvm env --path)
rvm use 2.1.5
sh   /var/www/thingspeak@/rails.sh

exit 0