Skip to content

Commit

Permalink
Add pidfile as argument, enable option for access_log and improve con…
Browse files Browse the repository at this point in the history
…trol script
  • Loading branch information
jriguera committed Aug 27, 2018
1 parent 7b3aa70 commit d1474f4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
4 changes: 3 additions & 1 deletion jobs/nginx-lua/spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,4 +89,3 @@ properties:
also available as env variable "${TLS_CRT}".
nginx-lua.env:
description: A hash of environment variables

37 changes: 25 additions & 12 deletions jobs/nginx-lua/templates/bin/ctl
Original file line number Diff line number Diff line change
Expand Up @@ -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

10 changes: 7 additions & 3 deletions jobs/nginx-lua/templates/config/nginx.conf.erb
Original file line number Diff line number Diff line change
@@ -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') %>;
Expand Down Expand Up @@ -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/*;
}

0 comments on commit d1474f4

Please sign in to comment.