1.mkfifo /map/logs/nginx/wireless/access.log
nohup cat /map/app/nginx-1.2.2/logs/error.log | /map/app/tools/cronolog-1.7.0/sbin/cronolog /map/logs/nginx/wireless/error/%Y/%m/%d/%H.log &
nohup cat /map/logs/nginx/wireless/access.log | /map/app/tools/cronolog-1.7.0/sbin/cronolog /map/logs/nginx/wireless/%Y/%m/%d/%H.log &
留意:在启动nginx前必需先启动cronolog,不然无法启动
2.把cronolog增加到nginx启动剧本中
剧本内容如下:
#!/bin/sh
#
# Comments to support chkconfig
#
# chkconfig: 2345 77 77
# Description: Startup script for nginx webserver
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/map/app/nginx/sbin/$NAME
CONFIGFILE=/map/app/nginx/conf/nginx.conf
PIDFILE=/map/app/nginx/logs/$NAME.pid
SERVICENAME=/etc/init.d/nginxd-map
cronolog=/map/app/tools/cronolog-1.7.0/sbin/cronolog
ErrorLog=/map/app/nginx-1.0.6/logs/error.log
AccessLog=/map/logs/nginx/wireless/access.log
##赤色部门是新增加的,,检测文件是否是pipe范例,启动cronolog,杀掉cronolog,很简朴,可是可以或许实现成果
d_mkfifo(){
[ ! -p $ErrorLog ] || [ ! -p $AccessLog ] && /bin/rm $ErrorLog $AccessLog && mkfifo $ErrorLog $AccessLog
}
cronolog_start()
{
#ps -ef|grep wireless|grep -v grep |awk '{print $2}'|xargs kill -9
nohup cat /map/app/nginx-1.0.6/logs/error.log | $cronolog /map/logs/nginx/wireless/error/%Y/%m/%d/%H.log &
nohup cat /map/logs/nginx/wireless/access.log | $cronolog /map/logs/nginx/wireless/%Y/%m/%d/%H.log &
}
cronolog_kill()
{
ps -ef|grep wireless|grep -v grep |awk '{print $2}'|xargs kill -9
}
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
d_mkfifo
cronolog_start
$DAEMON -c $CONFIGFILE || echo -n " already running"
}
d_stop() {
# kill -QUIT `cat $PIDFILE` || echo -n " not running"
cronolog_kill
killall nginx || echo -n " not running"
}
d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
status)
pgrep -x $NAME > /dev/null && echo $NAME (pid `pgrep $NAME`) is running... || echo "$NAME is stoped."
;;
test|-t)
$DAEMON -t
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 2
d_start
echo "...done!"
;;
*)
echo "Usage: $SERVICENAME {start|stop|restart|reload|status|check}"
exit 3
;;
esac
exit 0