Created
February 16, 2012 17:03
-
-
Save naokij/1846479 to your computer and use it in GitHub Desktop.
init script for rsyslog to forward remote syslog to another server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# rsyslogforwarder Starts rsyslogd/rklogd forwarder. | |
# | |
# | |
# chkconfig: 2345 12 88 | |
# description: Syslog is the facility by which many daemons use to log \ | |
# messages to various system log files. It is a good idea to always \ | |
# run rsyslog. | |
### BEGIN INIT INFO | |
# Provides: $syslog | |
# Required-Start: $local_fs | |
# Required-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Enhanced system logging and kernel message trapping daemons | |
# Description: Rsyslog is an enhanced multi-threaded syslogd supporting, | |
# among others, MySQL, syslog/tcp, RFC 3195, permitted | |
# sender lists, filtering on any message part, and fine | |
# grain output format control. | |
### END INIT INFO | |
# Source function library. | |
. /etc/init.d/functions | |
RETVAL=0 | |
PIDFILE=/var/run/syslogdforwarder.pid | |
prog=rsyslog | |
exec=/sbin/rsyslogd | |
lockfile=/var/lock/subsys/rsyslogforwarder | |
# Source config | |
if [ -f /etc/sysconfig/$prog ] ; then | |
. /etc/sysconfig/$prog | |
fi | |
start() { | |
[ -x $exec ] || exit 5 | |
umask 077 | |
echo -n $"Starting system logger: " | |
daemon --pidfile="$PIDFILE" $exec -i "$PIDFILE" $SYSLOGD_OPTIONS -f /etc/rsyslogforwarder.conf | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && touch $lockfile | |
return $RETVAL | |
} | |
stop() { | |
echo -n $"Shutting down system logger: " | |
killproc -p "$PIDFILE" $exec | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && rm -f $lockfile | |
return $RETVAL | |
} | |
reload() { | |
RETVAL=1 | |
syslog=$(cat "${PIDFILE}" 2>/dev/null) | |
echo -n "Reloading system logger..." | |
if [ -n "${syslog}" ] && [ -e /proc/"${syslog}" ]; then | |
kill -HUP "$syslog"; | |
RETVAL=$? | |
fi | |
if [ $RETVAL -ne 0 ]; then | |
failure | |
else | |
success | |
fi | |
echo | |
return $RETVAL | |
} | |
rhstatus() { | |
status -p "$PIDFILE" -l $prog $exec | |
} | |
restart() { | |
stop | |
start | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
reload|force-reload) | |
reload | |
;; | |
status) | |
rhstatus | |
;; | |
condrestart|try-restart) | |
rhstatus >/dev/null 2>&1 || exit 0 | |
restart | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|condrestart|try-restart|reload|force-reload|status}" | |
exit 2 | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment