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
DESC="Unicorn web server"

. /lib/lsb/init-functions

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

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



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

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

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

set -u

    case "$1" in

            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
              log_end_msg 1 || true
        log_daemon_msg "Stopping $DESC" $NAME || true
        if start-stop-daemon --stop --signal QUIT --quiet --oknodo --pidfile $PID; then
          log_end_msg 0 || true
          log_end_msg 1 || true
        log_daemon_msg "Forcing stop of $DESC" $NAME || true
        if start-stop-daemon --stop --quiet --oknodo --pidfile $PID; then
          log_end_msg 0 || true
          log_end_msg 1 || true
        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
          log_end_msg 1 || true
        log_daemon_msg "Reloading $DESC" $NAME || true
        if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID; then
          log_end_msg 0 || true
     log_end_msg 1 || true
        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
          log_end_msg 1 || true
        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


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

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

# 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.

# Server's config.rb, it's not a rack's config.ru

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




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!

  • 1
    I too ran into similar problem and was wondering about problem for 2 days.. Your solution saves me.. Thanks so much for putting up solution :) – Veer Feb 27 '15 at 6:30

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?

  • 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 '14 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 '14 at 13:07

protected by Community Feb 23 '16 at 11:08

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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