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 have a Rails app running on nginx/passenger. It restarts happily in a shell using sudo /etc/init.d/nginx stop|start|restart. But Passenger throws an error when the system is rebooted: "Missing the Rails #{version} gem". But GEM_HOME and GEM_PATH are both set in /etc/environment so surely they would be available to all processes during reboot?

/etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games"
GEM_HOME=/var/lib/gems/1.8
GEM_PATH=/var/lib/gems/1.8

/etc/init.d/nginx

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /var/log/nginx/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /var/log/nginx/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                 /var/log/nginx/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                 /var/log/nginx/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  reload)
      echo -n "Reloading $DESC configuration: "
      start-stop-daemon --stop --signal HUP --quiet --pidfile  /var/log/nginx/$NAME.pid \
          --exec $DAEMON
      echo "$NAME."
      ;;
  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

$ opt/nginx/sbin/nginx -v
nginx version: nginx/0.7.67

Ubuntu lucid

share|improve this question

1 Answer 1

up vote 1 down vote accepted

On a Ubuntu Maverick I'm not seeing anything that will read in /etc/environment before the init scripts are run. The best bet would be to create a file called /etc/default/nginx, if it doesn't already exist, and put your three lines from the environment file in there.

share|improve this answer
    
Thanks Niall, can you explain a bit more about the sequence of events on boot up or point me in the direction of docs? Also, will /etc/default/nginx be read by, um, default then? –  Dave Nolan Jan 6 '11 at 11:30
    
If you look at at /etc/init.d/nginx, there will probably be a section near the top checking to see if /etc/default/nginx exists. If it does, it will be run adding in the variables you want. So yes, they will be read by default. I think /etc/environment is meant to be more for interactive sessions but I'm not 100% sure on that! –  Niall Donegan Jan 6 '11 at 11:42
    
Ah yes so there is, thanks! –  Dave Nolan Jan 7 '11 at 7:15

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.