nginx-formula/nginx/templates/RedHat-sysvinit-logger.jinja

101 lines
2.2 KiB
Plaintext
Raw Normal View History

2014-10-20 10:59:16 +02:00
#!/bin/bash
# /etc/init.d/nginx-logger-{{ type }}
#
# chkconfig: 345 84 16
# description: Nginx logger for {{ type }}
# processname: nginx-logger-{{ type }}
NAME=nginx-logger-{{ type }}
DESC="syslog forwarder for nginx {{type}} logs"
DAEMON=/usr/bin/logger
DAEMON_ARGS=" -f /var/log/nginx/{{ type }}.fifo -t nginx -p {% if type == 'error' %}warn{% else %}debug{% endif %}"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the daemon program isn't installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
. /etc/init.d/functions
do_start() {
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
echo -n "Starting $NAME"
pid=$(cat $PIDFILE 2>/dev/null)
if [ -n "$pid" ]; then
failure
echo
return 1;
fi
if [ ! -r /var/log/nginx/{{ type }}.fifo ]; then
mkdir -p /var/log/nginx
mkfifo /var/log/nginx/{{ type }}.fifo
chown root.root /var/log/nginx/{{ type }}.fifo
chmod 660 /var/log/nginx/{{ type }}.fifo
fi
$DAEMON $DAEMON_ARGS &
ERROR=$?
PID=$!
if [ $ERROR -eq 0 ]; then
success
echo
echo $PID > $PIDFILE
else
failure
echo
exit 2
fi
}
do_stop() {
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
echo -n Stopping $NAME
pid=$(cat $PIDFILE 2>/dev/null)
if [ $? -eq 0 ]; then
echo $pid | xargs kill 2&1>/dev/null
success
RETVAL=0
else
failure
RETVAL=1
fi
echo
[ "$RETVAL" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
status)
status -p "$PIDFILE" "$DAEMON" && exit 0 || exit $?
;;
restart|force-reload)
do_stop
do_start
;;
*)
echo "Usage: /etc/init.d/nginx-logger-{{ type }} {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
exit 0