### First let's draft up a quick script to check if pipes exist and create them if needed.
### /scripts/nginxfifo.sh:
#!/bin/bash
#
# nginx Syslog-ng Support
# FIFO Creation Script
# Justin Uni Griggs
# Written for Ishikawa
# DEPENDS: nginx,fifo,syslog-ng
#
#
# Check for and Create the Access Log
# FIFO if it doesn't exist.
#
if [ ! -p /var/log/nginx/access.log ]; then
/bin/rm -f /var/log/nginx/access.log
/usr/bin/mkfifo --mode=0640 /var/log/nginx/access.log
fi
#
# Check for and create the Error log
# FIFO if it doesn't exist.
#
if [ ! -p /var/log/nginx/error.log ] ; then
/bin/rm -f /var/log/nginx/error.log
/usr/bin/mkfifo --mode=0640 /var/log/nginx/error.log
fi
#
# Change the Ownership and Permissions
#
/bin/chown nginx:root /var/log/nginx/access.log
/bin/chown nginx:root /var/log/nginx/error.log
###
### Now we need to configure syslog-ng to read from the source.
### In my case I wanted those messages dropped into a log file so that I could run
### logcheck on them as well as archive them with logrotate.
###
### /etc/syslog-ng/syslog-ng.conf
source nginx_access { pipe("/var/log/nginx/access.log" program_override("nginx-access-log: ")); };
source nginx_error { pipe("/var/log/nginx/error.log" program_override("nginx-error-log: ")); };
destination nginxaccess { file("/var/log/syslog-ng/nginx.access.log"); };
destination nginxerror { file("/var/log/syslog-ng/nginx.error.log"); };
filter f_naccess { program("nginx-access-log: "); };
filter f_nerror { program("nginx-error-log: "); };
log { source(nginx_access); filter(f_naccess); destination(nginxaccess); };
log { source(nginx_error); filter(f_nerror); destination(nginxerror); };
###
### Now, Syslog-ng will flip a shit if it tries to activate itself and the pipes don't exist.
### So what we need to do is make nginx dependent on syslog-ng, so that syslog-ng starts first
### and we don't get a queue of logs that will dump in (in the event of an attack even the short
### time between nginx init and syslog-ng init may result in a very large queue which would be
### very very bad), and then inside syslog-ng's startup system we need to call the fifo creation
### script BEFORE we call the service start for syslog-ng.
###
### This way, the order goes mkfifo->syslog-ng->nginx.
###
###
### First nginx dependencies. This is kinda gentoo centric.
###
### /etc/init.d/nginx
depend() {
need net
need syslog-ng
use dns logger netmount
}
###
### Now we modify syslog-ng
###
### /etc/init.d/syslog-ng
start() {
checkconfig || return 1
ebegin "Creating nginx FIFO Pipe"
/scripts/nginxfifo.sh
eend $? "Failed to create nginx FIFO Pipe"
ebegin "Starting syslog-ng"
...
}
### Then call syslog-ng to reboot which will take down nginx with it and set everything up.
### Done and done.