Advertisement
CoolRaoul

customize_syslog_config

Apr 11th, 2013
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.73 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. #   customize_syslog_config
  4. #  
  5. #   Patch syslog server config
  6. #   ref: to http://forum.synology.com/enu/viewtopic.php?f=182&t=64558#p257406
  7. #  
  8. PATH=/bin:/usr/bin:/usr/syno/bin
  9.  
  10. TMPLDIR=/volume1/@appstore/SyslogServer/etc/template
  11.  
  12. workfile=/tmp/work-$$
  13. trap "/bin/rm -f $workfile" EXIT
  14.  
  15. LOGDIR=/volume2/var/log         # edit according to your preferences
  16.  
  17. must_restart=""
  18. mode="apply"
  19.  
  20. while getopts :u OPT; do
  21.     case $OPT in
  22.         u|+u)
  23.             mode="undo"
  24.             ;;
  25.         *)
  26.             echo "usage: `basename $0` [+-u} [--] ARGS..."
  27.             exit 2
  28.     esac
  29. done
  30. shift `expr $OPTIND - 1`
  31. OPTIND=1
  32. #+
  33. #   usage:
  34. #       _patch <file2patch> <regexp matching only added lines> <extra conf line> [<extra conf line>...]
  35. #-     
  36. _patch () {
  37.     local source="$1" ; shift
  38.     local regexp="$1" ; shift
  39.     local line
  40.  
  41.     (
  42.         grep -v "$regexp" $source
  43.         for line in "$@" ; do
  44.             echo "$line"
  45.         done
  46.     ) > $workfile
  47.  
  48.     if  cmp -s $source $workfile ; then
  49.         echo >&2 "NOCHANGES: $source"
  50.     else
  51.         [ -f $source.ori ] || cp -p $source $source.ori
  52.         cp $workfile $source
  53.         echo >&2 "PATCHED: $source"
  54.         must_restart="YES"
  55.  
  56.     fi
  57. }
  58.  
  59. _apply () {
  60.     _patch $TMPLDIR/dest_db.template  \
  61.         "$LOGDIR" \
  62.         'destination messages { file("'$LOGDIR'/messages-$YEAR" template("$ISODATE $HOST $MSGHDR$MSG\n") ); };'
  63.  
  64.     _patch $TMPLDIR/log_net_to_db.template \
  65.         "log.*source.*s_syno_net.*s_syno_ietf.*destination.*messages"  \
  66.         'log { source(s_syno_net); source(s_syno_ietf); destination(messages); };'
  67.  
  68.     _patch $TMPLDIR/system.conf \
  69.         'other_' \
  70.         'source other_local { file("/proc/kmsg");unix-stream("/dev/log");unix-stream("/var/run/syslog");unix-stream("/var/run/log");internal(); };' \
  71.         'destination other_file { file("'$LOGDIR'/messages-$YEAR" template("$ISODATE $HOST $MSGHDR$MSG\n") ); };' \
  72.         'log { source(other_local);  destination(other_file); };'
  73. }
  74.  
  75. _undo () {
  76.     for file in \
  77.         $TMPLDIR/dest_db.template  \
  78.         $TMPLDIR/log_net_to_db.template \
  79.         $TMPLDIR/system.conf
  80.     do
  81.         if [ -f $file.ori ] && ! cmp -s $file $file.ori ; then
  82.             cp $file.ori $file
  83.             echo >&2 "RESTORED: $file"
  84.             must_restart="YES"
  85.         fi
  86.     done
  87. }
  88.  
  89. case $mode in
  90.     undo)
  91.         _undo
  92.         ;;
  93.     apply)
  94.         _apply
  95.         ;;
  96. esac
  97.  
  98. if [  "$must_restart" != "" ] ;  then
  99.     echo >&2 "please stop then start syslog server"
  100.    
  101.     # echo >&2 "restarting server"
  102.     # for action in stop start
  103.     # do
  104.     #     # only keep path in env
  105.     #     env - PATH=$PATH synopkg $action syslogserver
  106.     # done
  107. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement