Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Based on the content of the Ubuntu init.d script to control nginx instances, found at : I'm trying to update Upstart version, found at: to make the configuration syntax check.

Basically what it needs to do is, call:


This should output error messages regarding wrong syntax on configuration files.

I've tried the following without success:

# nginx

description "nginx http daemon"
author "George Shammas <>"

start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]

env DAEMON=/opt/nginx/sbin/nginx
env PID=/var/run/
env NGINX_CONF_FILE=/etc/nginx/nginx.conf
console output
expect fork

pre-start script
        $DAEMON -t -c $NGINX_CONF_FILE
        if [ $? -ne 0 ]
                then exit $?
end script

post-stop script
    start-stop-daemon --stop --pidfile $PID --name nginx --exec $DAEMON --signal TERM
end script


The problem here is that, it doesn't put the output to console, even with the "console output" stanza.

Am I missing something here?

What I get when it can't start is a simple:

root@localhost:/# start nginx
start: Job failed to start
share|improve this question
up vote 0 down vote accepted

There's no easy answer here. Unfortunately, if you pipe the output of the syntax check to something like logger, you lose the return code to check if it failed.. so you have to do it something like this:

syntax_check_output=`mktemp /tmp/nginx.check.XXXXXX`
if $DAEMON -t -c $NGINX_CONF_FILE > $syntax_check_output 2>&1 ; then
  rm -f $syntax_check_output
  logger -t nginx -p daemon.err < $syntax_check_output
  rm -f $syntax_check_output
  exit 1

(incidentally, you should note that all upstart script sections are run with 'set -e', so the if statement in your original example won't be executed.. as soon as the command exits non-zero, the shell will exit.)

share|improve this answer
what about some thing like: variable=$($DAEMON -t -c $NGINX_CONF_FILE) the get the output and then, instead of getting it from file: logger -t nginx -p daemon.err $variable. Could it work? – Gabriel Mazetto Jan 19 '12 at 7:43
yes that might even be a better idea. :) – SpamapS Jan 22 '12 at 21:05

Your Answer


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.