2

I'm hoping this is just a problem with my not understanding how the $PATH variable works. I'm using Ubuntu 14.04. I'm trying to run rails through a unicorn server. I have the below configuration for my unicorn server

# 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/mydomain

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

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

export GEM_HOME=/home/rails/.gem
export GEM_PATH=$GEM_HOME/ruby/2.4.0
PATH=$GEM_HOME/bin:/usr/local/rvm/rubies/ruby-2.4.0/bin/:/usr/local/sbin:/usr/bin:/bin:/sbin:/usr/local/rvm/bin
which bundle
cd $APP_ROOT
DAEMON="bundle exec $GEM_PATH/bin/unicorn"

When I go to run my unicorn server, I get this error

myuser@mydomain:~$ sudo service unicorn restart
/home/rails/.gem/bin/bundle
 * Restarting Unicorn web server unicorn 

 start-stop-daemon: unable to stat //bundle (No such file or directory)

Why is it complaining about "bundle (No such file or directory)" when I just printed that out in the "which" statement? Clearly the file bundle exists. I have included my /etc/init.d/unicorn file below if it is useful.

#!/bin/sh
### BEGIN INIT INFO
# Provides:          unicorn
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: unicorn initscript
# Description:       unicorn
### END INIT INFO

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

. /lib/lsb/init-functions

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

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
3
  • Is there a /home/rails/.gem/bin/bundle, mine is /home/george/.rbenv/shims/bundle. Did you create a /home/rails home directory? Run this ls -al /home/rails what does it return? Apr 5 '17 at 23:53
  • Hi, Yes, when I run "ls -al /home/rails/.gem/bin/bundle" I do get "-rwxr-xr-x 1 rails rails 501 Jan 5 13:47 /home/rails/.gem/bin/bundle"
    – Dave
    Apr 5 '17 at 23:59
  • 2
    I'm not a server guy, but I have a suggestion: try changing the DAEMON line to DAEMON="/home/rails/.gem/bin/bundle exec $GEM_PATH/bin/unicorn" and see what happens.
    – wjandrea
    Apr 9 '17 at 18:02
1

The reason is that the execution path passed to start-stop-daemon must be fully qualified. The fix is to set

DAEMON="/path/to/bundle exec $GEM_PATH/bin/unicorn"

You can test this using this simple example

$ sudo start-stop-daemon --start --oknodo --user lathiat --pidfile /tmp/pid1 --exec sleep 60 -- 
[sudo] password for lathiat: 
start-stop-daemon: unable to stat //sleep (No such file or directory)

$ sudo start-stop-daemon --start --oknodo --user lathiat --pidfile /tmp/pid1 --exec /bin/sleep 60 -- 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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