新手问题 VPS 开机自动启动 rake sunspot:solr:start

xufeng · January 13, 2014 · Last by xufeng replied at January 15, 2014 · 3493 hits

请教一下,如何在 VPS 重启自动开启 sunspot,不用手工命令啊?

我知道是很菜鸟的问题,我 google 了,但是没有找到解决办法。请大神给支个招,

thanks.

rake sunspot:solr:start

1.把要执行的命令写一个 shell 脚本,然后在/etc/rc.local 里加上要执行的脚本(每次重启后自动运行,最简单的办法)。 2.或者写成 upstart 脚本在/etc/init/目录下(相当于自己创建一个系统服务)。 3.使用 supervisor 之类的守护工具。

cd /var/www/xxx.com && RAILS_ENV=production rake sunspot:solr:start 把上面那段命令加入到/etc/rc.local,重启后不起作用,请问命令是否写得有问题啊

感谢@beiersi

su - nonrootuser -c "xxx.sh"

你要启动的不是 sunspot 是 solr 应该在 server 上配置一个 solr 或者说配置一个 tomcat + deploy solr

官方 WIKI

https://github.com/sunspot/sunspot/wiki/Configuring-solr-for-use-with-sunspot-in-development,-testing,-and-production

说真的,建议还是换用 elasticsearch 吧,好用很多

#2 楼 @xufeng 我猜想可能是 rvm 的原因,所以应该先 source rvm 以后再执行 rake xxx,另外还要注意 rc.local 是以 root 来执行命令,所以有必要使用 sudo -u xxx -c "xxx"来执行。

实际上就是

desc "Start Solr Server"
task :start do
  exec 'cd solr/solr && java -jar start.jar'
end

可以写个脚本 screen solr jar 就好了

setup with whenever

config/schedule.rb

every :reboot do command "cd /home/deployer/apps/brandinlabs/current/ && RAILS_ENV=production bundle exec sunspot-solr start --port=8983 --data-directory=/home/deployer/apps/brandinlabs/shared/solr/data --pid-dir=/home/deployer/apps/brandinlabs/shared/pids" end

You need to Sign in before reply, if you don't have an account, please Sign up first.