Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # customize_syslog_config
- #
- # Patch syslog server config
- # ref: to http://forum.synology.com/enu/viewtopic.php?f=182&t=64558#p257406
- #
- PATH=/bin:/usr/bin:/usr/syno/bin
- TMPLDIR=/volume1/@appstore/SyslogServer/etc/template
- workfile=/tmp/work-$$
- trap "/bin/rm -f $workfile" EXIT
- LOGDIR=/volume2/var/log # edit according to your preferences
- must_restart=""
- mode="apply"
- while getopts :u OPT; do
- case $OPT in
- u|+u)
- mode="undo"
- ;;
- *)
- echo "usage: `basename $0` [+-u} [--] ARGS..."
- exit 2
- esac
- done
- shift `expr $OPTIND - 1`
- OPTIND=1
- #+
- # usage:
- # _patch <file2patch> <regexp matching only added lines> <extra conf line> [<extra conf line>...]
- #-
- _patch () {
- local source="$1" ; shift
- local regexp="$1" ; shift
- local line
- (
- grep -v "$regexp" $source
- for line in "$@" ; do
- echo "$line"
- done
- ) > $workfile
- if cmp -s $source $workfile ; then
- echo >&2 "NOCHANGES: $source"
- else
- [ -f $source.ori ] || cp -p $source $source.ori
- cp $workfile $source
- echo >&2 "PATCHED: $source"
- must_restart="YES"
- fi
- }
- _apply () {
- _patch $TMPLDIR/dest_db.template \
- "$LOGDIR" \
- 'destination messages { file("'$LOGDIR'/messages-$YEAR" template("$ISODATE $HOST $MSGHDR$MSG\n") ); };'
- _patch $TMPLDIR/log_net_to_db.template \
- "log.*source.*s_syno_net.*s_syno_ietf.*destination.*messages" \
- 'log { source(s_syno_net); source(s_syno_ietf); destination(messages); };'
- _patch $TMPLDIR/system.conf \
- 'other_' \
- 'source other_local { file("/proc/kmsg");unix-stream("/dev/log");unix-stream("/var/run/syslog");unix-stream("/var/run/log");internal(); };' \
- 'destination other_file { file("'$LOGDIR'/messages-$YEAR" template("$ISODATE $HOST $MSGHDR$MSG\n") ); };' \
- 'log { source(other_local); destination(other_file); };'
- }
- _undo () {
- for file in \
- $TMPLDIR/dest_db.template \
- $TMPLDIR/log_net_to_db.template \
- $TMPLDIR/system.conf
- do
- if [ -f $file.ori ] && ! cmp -s $file $file.ori ; then
- cp $file.ori $file
- echo >&2 "RESTORED: $file"
- must_restart="YES"
- fi
- done
- }
- case $mode in
- undo)
- _undo
- ;;
- apply)
- _apply
- ;;
- esac
- if [ "$must_restart" != "" ] ; then
- echo >&2 "please stop then start syslog server"
- # echo >&2 "restarting server"
- # for action in stop start
- # do
- # # only keep path in env
- # env - PATH=$PATH synopkg $action syslogserver
- # done
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement