这是我的独角兽的初始脚本(/etc/init.d/unicorn):
#! /bin/sh
PATH=/home/josue/.rvm/gems/ruby-1.9.3-p0/bin:/home/josue/.rvm/gems/ruby-1.9.3-p0@global/bin:/home/josue/.rvm/rubies/ruby-1.9.3-p0/bin:/home/josue/.rvm/bin:/usr/local/sbin:$
DAEMON=/home/josue/.rvm/gems/ruby-1.9.3-p0/bin/unicorn_rails
DAEMON_OPTS="-c /home/josue/sped/current/unicorn.rb -E production -D"
NAME=unicorn_rails
DESC=unicorn_rails
PID=/home/josue/sped/shared/pids/unicorn.pid
case "$1" in
start)
echo -n "Starting $DESC: "
exec $DAEMON $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
kill -QUIT `cat $PID`
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
kill -QUIT `cat $PID`
sleep 1
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
kill -HUP `cat $PID`
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0
当我以普通用户身份运行/etc/init.d/unicorn start
时,它运行正常,但当我尝试以root身份运行时,结果就是这样:
Starting unicorn_rails: /home/josue/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find unicorn (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)
from /home/josue/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /home/josue/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
from /home/josue/.rvm/gems/ruby-1.9.3-p0/bin/unicorn_rails:18:in `<main>'
因此,当服务器启动时,不会自动加载独角兽。
我正在使用:
答案 0 :(得分:3)
有几种方法可以让它发挥作用:
关注您的代码:
PATH=/home/josue/.rvm/gems/ruby-1.9.3-p0/bin:/home/josue/.rvm/gems/ruby-1.9.3-p0@global/bin:/home/josue/.rvm/rubies/ruby-1.9.3-p0/bin:/home/josue/.rvm/bin:$PATH
GEM_HOME=/home/josue/.rvm/gems/ruby-1.9.3-p0
GEM_PATH=/home/josue/.rvm/gems/ruby-1.9.3-p0:/home/josue/.rvm/gems/ruby-1.9.3-p0@global
使用rvm包装器:https://rvm.io/integration/init-d/
答案 1 :(得分:1)
如果您在生产环境中,您可能不希望以root用户身份安装某些gem,而其他一些gem也与Rails应用程序捆绑/安装...
有一种简单的方法可以解决OP问题:还可以设置GEM_PATH和GEM_HOME
如果您正确设置了root帐户(〜/ .bashrc)的PATH,GEM_PATH和GEM_HOME环境变量,那么您将能够使其工作。 例如unicorn可执行文件应该在root的PATH中,并且GEM相关的env变量应该正确设置到“bundle install”期间安装gem的位置(例如,这可以在另一个用户的主目录中)。
$ cat /root/.bashrc
export PATH=/home/josue/.rvm/gems/ruby-1.9.3-p0/bin:/home/josue/.rvm/gems/ruby-1.9.3-p0@global/bin:/home/josue/.rvm/rubies/ruby-1.9.3-p0/bin:/home/josue/.rvm/bin:$PATH
export GEM_HOME=/home/josue/.rvm/gems/ruby-1.9.3-p0/gems
export GEM_PATH=/home/josue/.rvm/gems/ruby-1.9.3-p0/gems:/home/josue/.rvm/gems/ruby-1.9.3-p0@global/gems
启动后,您还应该触摸文件/ var / lock / subsys / $ APP_NAME 杀死Unicorns后删除该文件,以便您的LINUX系统知道您的应用程序正在运行。
这对我来说非常有效。
我通常会将/etc/init.d/unicorn脚本重命名为我的应用程序名称,以防我运行多个应用程序。
答案 2 :(得分:-1)
似乎Unicorn gem未在root用户下安装。您是否尝试以root身份登录然后安装它?