Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm a new Linode/Linux user running Debian 6. I'm trying to get my Unicorn server to start at boot, but for some reason it is not, and I'm not able to track down any error message. Nginx is starting fine, and I have a multi-user RVM install. My gut feeling is that is has something to do with RVM. This is my unicorn_init.sh file in /rails/todo, and there's a symlink to it at /etc/init.d/unicorn:

# unicorn_init.sh
#!/bin/sh

set -e

TIMEOUT=${TIMEOUT-60}
APP_ROOT=/rails/todo
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="$APP_ROOT/bin/unicorn_rails -D -c $APP_ROOT/config/unicorn.rb -E production"
GEM_HOME="/usr/local/rvm/gems/ruby-1.9.2-p290@global"
action="$1"
set -u

old_id="$PID.oldbin"

cd $APP_ROOT || exit 1
export GEM_HOME=$GEM_HOME

sig () {
  test -s "$PID" && kill -$1 `cat $PID`
}

oldsig () {
  test -s $old_pid && kill -$1 `cat $old_pid`
}

case $action in
  start)
    sig 0 && echo >&2 "Already running" && exit 0
    su -c "$CMD" - root
    ;;
  stop)
    sig QUIT && exit 0
    echo >&2 "Not running"
    ;;
  force-stop)
    sig TERM && exit 0
    echo >&2 "Not running"
    ;;
  restart|reload)
    sig HUP && echo reloaded OK && exit 0
    echo >&2 "Couldn't reload, starting '$CMD' instead"
    su -c "$CMD" - root
    ;;
  upgrade)
    if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
    then
      n=$TIMEOUT
      while test -s $old_pid && test $n -ge 0
      do
        printf '.' && sleep 1 && n=$(( $n - 1 ))
      done
      echo

      if test $n -lt 0 && test -s $old_pid
      then
        echo >&2 "$old_pid still exists after $TIMEOUT seconds"
        exit 1
      fi
      exit 0
    fi
    echo >&2 "Couldn't upgrade, starting '$CMD' instead"
    su -c "$CMD" - root
    ;;
  reopen-logs)
    sig USR1
    ;;
  *)
    echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
    exit 1
    ;;
esac

I'm 99% of the way to getting my setup working—any advice would be much appreciated.


Update

Here is the output of $ update-rc.d unicorn defaults:

update-rc.d: using dependency based boot sequencing
insserv: warning: script 'unicorn' missing LSB tags and overrides
insserv: There is a loop between service nginx and unicorn if stopped
insserv:  loop involving service unicorn at depth 2
insserv:  loop involving service nginx at depth 1
insserv: Stopping unicorn depends on nginx and therefore on system facility `$all' which can not be true!
insserv: exiting now without changing boot order!
update-rc.d: error: insserv rejected the script header
share|improve this question
    
Looks like your unicorn startup script is depending on nginx for some reason, this should't be the case. –  Patrick Tescher Dec 8 '11 at 22:32

1 Answer 1

Shebang (#!/bin/sh) should be first line of the script

Edited:

Please put following after the shebang and before any application specific settings

### BEGIN INIT INFO
# Provides:          APPLICATION
# Required-Start:    $all
# Required-Stop:     $network $local_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start the APPLICATION unicorns at boot
# Description:       Enable APPLICATION at boot time.
### END INIT INFO
# 
# Use this as a basis for your own Unicorn init script.
# Make sure that all paths are correct.

set -u
set -e

It should surely get-rid of LSB warnings.

share|improve this answer
    
It is, that comment is just there to identify the file here. –  clem Jan 15 '12 at 18:06

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.