Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I used the one-click Rails, NGINX, Unicorn, MySQL droplet set up to create my server and I can't get Unicorn to start as a daemon. Here's the stack trace when I /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>'

When I which unicorn I get: /usr/local/rvm/gems/ruby-2.0.0-p195/bin/unicorn which seems like it should be good.

I've tried everything I can think of, some of which include:

  • Creating an RVM wrapper => No bin path suitable for lining wrapper. Try setting 'rvm_bin_path'.
  • sudo gem install unicorn => Failed to build native extensions... (for kgio 2.8.1). It's looking in/usr/bin/ruby1.9.1` for extconf.rb. I've never even touched a version of Ruby lower than 2.0.
  • rvm remove 2.0.0-p353 => A bunch of file permissions errors. RVM doesn't recognize what sudo means either. Beats me...
  • Contacting DigitalOcean => They said to go ask 'the community'.
  • Followed several other tutorials & suggestions about symlinking, putting PATH-related information in config files, and more. Nothing worked.

It works fine if I start it in the background (-D switch), but the processes still get killed once I disconnect from the terminal. I'm simply out of ideas and have been at this for two days.

Let me know if you want me to post any snippets of files or run commands. I didn't want to fill this post with superfluous information.

Help me, AskUbuntu, you're my only hope...

*EDIT: * /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:$
~

EDIT 2:

Success!

A long trail of CHOWNs and CHMODs later (for different Unicorn log & pid files), I'm simply got a master failed to start, check stderr log for details when I try to /etc/init.d/unicorn/ but my unicorn.stderr.log file is blank. Tracing more config files, lead me to some error log that said some unicorn/pid/ directory was unwritable. A little CHOWN action later, all is well.

Thanks Ben!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

When unicorn — or any Rack-compliant server process — runs, it needs a rackup (.ru) file to tell it what to do. If you don't point it at one, it doesn't know what to serve up. I'd say the script at /etc/init.d/unicorn doesn't contain the full path to your project's rackup file, and it needs it. Most if not all Rails apps have one included nowadays as part of the Rails project generator (config.ru).

That guide you're following instructs you to place your code inside of /home/rails, yet places it's configuration file elsewhere (/home/unicorn/unicorn.conf). In most setups I've seen, the contents of that file usually reside in the root of the Rails directory it serves, but no biggie.

The guide has a bunch of configuration in a separate file at /etc/default/unicorn, which I'm guessing may be where the culprit lies. Can you post the source of that file?

share|improve this answer
1  
Odd, I've never seen any mention of a rackup file needed for Unicorn ever. Not sure where to start on that one. And there is no /etc/init.d/unicorn.conf, but I do have one without the .conf & have already tailored it to my app. Posted the init script, but no rackup. –  Kyle Carlson Jan 17 at 4:36
1  
Apologies, I didn't mean to put .conf on the end! I've edited my answer accordingly. Do you happen to have a config.ru file in the root of your app? Most if not all Rails apps should have one. Does the file at /etc/default/unicorn have anything in it? I believe the init script is looking for $APP_ROOT which seems to be undefined when it boots up. I'm wondering if that environment variable lives in /etc/default/unicorn. –  Ben Kreeger Jan 17 at 13:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.