diff --git a/jobs/nginx-lua/spec b/jobs/nginx-lua/spec index c3a66b9..3d23dee 100644 --- a/jobs/nginx-lua/spec +++ b/jobs/nginx-lua/spec @@ -35,6 +35,9 @@ properties: nginx-lua.loglevel: description: Error loglevel default: error + nginx-lua.access_log: + description: Enable access_log type + example: timed_combined nginx-lua.workers: description: Number of worker processes default: auto @@ -86,4 +89,3 @@ properties: also available as env variable "${TLS_CRT}". nginx-lua.env: description: A hash of environment variables - diff --git a/jobs/nginx-lua/templates/bin/ctl b/jobs/nginx-lua/templates/bin/ctl index bbe6e6e..6d5c81a 100644 --- a/jobs/nginx-lua/templates/bin/ctl +++ b/jobs/nginx-lua/templates/bin/ctl @@ -21,23 +21,36 @@ case ${1:-help} in pid_guard $PIDFILE $COMPONENT # Load python library path for dynamic libs ldconf "$LD_LIBRARY_PATH" - { - setcap 'cap_net_bind_service=+ep' $(readlink -nf $(which nginx)) - exec chpst -u vcap:vcap nginx -g "pid $PIDFILE;" -c $JOB_DIR/config/nginx.conf - } >>$LOG_DIR/$COMPONENT.stdout.log 2>>$LOG_DIR/$COMPONENT.stderr.log - echo "$(<${PIDFILE}). Done" + ( + { + setcap 'cap_net_bind_service=+ep' $(readlink -nf $(which nginx)) + exec chpst -u vcap:vcap nginx -g "pid $PIDFILE;" -c $JOB_DIR/config/nginx.conf + } >>$LOG_DIR/$COMPONENT.stdout.log 2>>$LOG_DIR/$COMPONENT.stderr.log + ) & + sleep 3 + if [ -s "${PIDFILE}" ] + then + echo "$(<${PIDFILE}). Done" + else + log "Failed!" + echo "Failed!" + exit 1 + fi ;; stop) - echo_log "Stopping $COMPONENT: $(<${PIDFILE}). " - kill -QUIT $(<${PIDFILE}) - sleep 5 - kill_and_wait $PIDFILE - rm -f $PIDFILE - echo_log "Done" + if [ -s "${PIDFILE}" ] + then + echo_log "Stopping $COMPONENT: $(<${PIDFILE}). " + kill -QUIT $(<${PIDFILE}) + sleep 5 + [ -s "${PIDFILE}" ] && kill_and_wait ${PIDFILE} && rm -f ${PIDFILE} + echo_log "Done" + else + echo_log "$COMPONENT already stopped! " + fi ;; *) echo "Usage: $0 {start|stop}" ;; esac exit 0 - diff --git a/jobs/nginx-lua/templates/config/nginx.conf.erb b/jobs/nginx-lua/templates/config/nginx.conf.erb index 70131e1..c304775 100644 --- a/jobs/nginx-lua/templates/config/nginx.conf.erb +++ b/jobs/nginx-lua/templates/config/nginx.conf.erb @@ -1,6 +1,6 @@ # user vcap; -daemon off; - +daemon on; +# pid /var/vcap/sys/run/nginx-lua/nginx-lua.pid; error_log /var/vcap/sys/log/nginx-lua/error.log <%= p('nginx-lua.loglevel', 'error') %>; worker_processes <%= p('nginx-lua.workers', 'auto') %>; @@ -53,6 +53,10 @@ http { # Log format log_format timed_combined '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time $upstream_response_time $pipe'; - + <% if_p("nginx-lua.access_log") do |access| %> + access_log /var/vcap/sys/log/nginx-lua/access.log <%= p('access') %>; + <% end.else do %> + access_log off; + <% end %> include /var/vcap/jobs/nginx-lua/config/sites/*; }