parse_rackup_file':rackup 文件(config.ru)不可读(ArgumentError)Unicorn Nginx

parse_rackup_file':rackup 文件(config.ru)不可读(ArgumentError)Unicorn Nginx

我使用了一键Rails、NGINX、Unicorn、MySQL droplet 设置创建我的服务器,但无法让 Unicorn 作为守护进程启动。以下是执行以下操作时的堆栈跟踪/etc/init.d/unicorn start

/usr/local/rvm/gems/ruby-2.0.0-p195/gems/unicorn-4.8.0/lib/unicorn/configurator.rb:659:in `parse_rackup_file': rackup file (config.ru) not readable (ArgumentError)
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/unicorn-4.8.0/lib/unicorn/configurator.rb:77:in `reload'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/unicorn-4.8.0/lib/unicorn/configurator.rb:68:in `initialize'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/unicorn-4.8.0/lib/unicorn/http_server.rb:100:in `new'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/unicorn-4.8.0/lib/unicorn/http_server.rb:100:in `initialize'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/unicorn-4.8.0/bin/unicorn:126:in `new'
from /usr/local/rvm/gems/ruby-2.0.0-p195/gems/unicorn-4.8.0/bin/unicorn:126:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/bin/unicorn:23:in `load'
from /usr/local/rvm/gems/ruby-2.0.0-p195/bin/unicorn:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.0.0-p195/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.0.0-p195/bin/ruby_executable_hooks:15:in `<main>'

当我which unicorn得到: /usr/local/rvm/gems/ruby-2.0.0-p195/bin/unicorn这看起来应该是好的。

我已经尝试了所有我能想到的方法,其中包括:

  • 创建 RVM 包装器=>No bin path suitable for lining wrapper. Try setting 'rvm_bin_path'.
  • sudo gem install unicorn=> 无法kgio 2.8.1). It's looking in为 extconf.rb 构建本机扩展...(对于 /usr/bin/ruby1.9.1`。我从未接触过低于 2.0 的 Ruby 版本。
  • rvm remove 2.0.0-p353=> 一堆文件权限错误。RVMsudo也无法识别这是什么意思。搞不懂……
  • 联系 DigitalOcean => 他们说去询问“社区”。
  • 遵循了其他几个关于符号链接、将 PATH 相关信息放入配置文件等的教程和建议。但都不起作用。

如果我在后台启动它(-D切换),它工作正常,但一旦我断开与终端的连接,进程仍然会被终止。我实在是没有主意了,而且已经这样做了两天。

如果您希望我发布任何文件片段或运行命令,请告诉我。我不想用多余的信息填满这篇文章。

帮助我,AskUbuntu,你是我唯一的希望......

*编辑: */etc/init.d/unicorn

set -e
NAME=unicorn
DESC="Unicorn web server"

. /lib/lsb/init-functions

if [ -f /etc/default/unicorn ]; then
  . /etc/default/unicorn
fi

export PATH=/usr/local/rvm/gems/ruby-2.0.0-p195/bin:$PATH
export GEM_HOME=/usr/local/rvm/gems/ruby-2.0.0-p195
export GEM_PATH=/usr/local/rvm/gems/ruby-2.0.0-p195:/usr/local/rvm/gems/ruby-2.0.0-p195/gems:/usr/local/rvm/gems/ruby-2.0.0-p195@global/gems

DAEMON=/usr/local/rvm/gems/ruby-2.0.0-p195/bin/unicorn

PID=${PID-/run/unicorn.pid}

run_by_init() {
    ([ "${previous-}" ] && [ "${runlevel-}" ]) || [ "${runlevel-}" = S ]
}

exit_with_message() {
  if ! run_by_init; then
    log_action_msg "$1 Not starting."
  fi
  exit 0
}
check_config() {
  if [ $CONFIGURED != "yes" ]; then
    exit_with_message "Unicorn is not configured (see /etc/default/unicorn)."
  fi
}

check_app_root() {
  if ! [ -d $APP_ROOT ]; then
    exit_with_message "Application directory $APP_ROOT is not exist."
  fi
}

set -u

    case "$1" in
      start)
            check_config
            check_app_root

            log_daemon_msg "Starting $DESC" $NAME || true
            if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then
              log_end_msg 0 || true
            else
              log_end_msg 1 || true
            fi
                  ;;
 stop)
        log_daemon_msg "Stopping $DESC" $NAME || true
        if start-stop-daemon --stop --signal QUIT --quiet --oknodo --pidfile $PID; then
          log_end_msg 0 || true
        else
          log_end_msg 1 || true
        fi
        ;;
  force-stop)
        log_daemon_msg "Forcing stop of $DESC" $NAME || true
        if start-stop-daemon --stop --quiet --oknodo --pidfile $PID; then
          log_end_msg 0 || true
        else
          log_end_msg 1 || true
        fi
        ;;
  restart|force-reload)
        log_daemon_msg "Restarting $DESC" $NAME || true
        start-stop-daemon --stop --quiet --oknodo --pidfile $PID
        sleep 1
        if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then
          log_end_msg 0 || true
        else
          log_end_msg 1 || true
        fi
        ;;
  reload)
        log_daemon_msg "Reloading $DESC" $NAME || true
        if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID; then
          log_end_msg 0 || true
        else
     log_end_msg 1 || true
    fi
        ;;
  reopen-logs)
        log_daemon_msg "Relopening log files of $DESC" $NAME || true
        if start-stop-daemon --stop --signal USR1 --quiet --oknodo --pidfile $PID; then
          log_end_msg 0 || true
        else
          log_end_msg 1 || true
        fi
        ;;
  status)
        status_of_proc -p $PID $DAEMON $NAME && exit 0 || exit $?
        ;;
  *)
        log_action_msg "Usage: $0 <start|stop|restart|force-reload|reload|force-stop|reopen-logs|status>" || true
        exit 1
        ;;
esac

/etc/default/unicorn

# Change parameters below to appropriate values and set CONFIGURED to yes.
CONFIGURED=yes

# Default timeout until child process is killed during server upgrade,
# it has *no* relation to option "timeout" in server's config.rb.
TIMEOUT=60

# Path to your web application, sh'ld be also set in server's config.rb,
# option "working_directory". Rack's config.ru is located here.
APP_ROOT=/home/rails/current/

# Server's config.rb, it's not a rack's config.ru
CONFIG_RB=/home/unicorn/unicorn.conf

# Where to store PID, sh'ld be also set in server's config.rb, option "pid".
PID=/home/unicorn/pids/unicorn.pid
UNICORN_OPTS="-D -c $CONFIG_RB -E production"

PATH=/usr/local/rvm/rubies/ruby-2.0.0-p195/bin:/home/unicorn/.rvm/bin:/usr/local/sbin:/usr/bin:/bin:/sbin:$
~

编辑2:

成功!

CHOWNs经过长时间的跟踪(针对不同的 Unicorn 日志和 pid 文件),当我尝试时,CHMODs我只是得到了一个,但我的文件是空白的。跟踪更多配置文件,导致我找到一些错误日志,其中说某些 unicorn/pid/ 目录不可写。稍后采取一些措施,一切都很好。master failed to start, check stderr log for details/etc/init.d/unicorn/unicorn.stderr.logCHOWN

谢谢本!

答案1

当 unicorn(或任何兼容 Rack 的服务器进程)运行时,它需要一个 rackup ( .ru) 文件来告诉它要做什么。如果你不指定它,它就不知道要提供什么。我想说 中的脚本/etc/init.d/unicorn不包含项目 rackup 文件的完整路径,但它需要它。如今,大多数(如果不是全部)Rails 应用程序都包含一个文件,作为 Rails 项目生成器 ( config.ru) 的一部分。

您所遵循的指南指示您将代码放在 中/home/rails,但将其配置文件放在其他地方(/home/unicorn/unicorn.conf)。在我见过的大多数设置中,该文件的内容通常位于它所服务的 Rails 目录的根目录中,但没什么大不了的。

该指南在 的一个单独文件中包含大量配置/etc/default/unicorn,我猜这可能是罪魁祸首所在。你能发布该文件的源代码吗?

相关内容