Вращение файлов журнала, в то время как процесс, все еще работающий

Следующие работы, но это является довольно подробным. Предложенные приветствующиеся улучшения.

while [ $# -gt 1 ]
do
    echo $CFLAGS
    case ${1} in
      -pthread*)
        CFLAGS="${CFLAGS} -D_REENTRANT"
        shift
        ;;
      -x)
        shift
        shift
        ;;
      -I)
        CFLAGS="${CFLAGS} ${1}"
        shift
        CFLAGS="${CFLAGS} ${1}"
        shift
        ;;
      -include)
        CFLAGS="${CFLAGS} ${1}"
        shift
        RELPATH_AFTER_INCLUDE="${1##*include/}"
        CFLAGS="${CFLAGS} ${RELPATH_AFTER_INCLUDE}"
        shift
        ;;
      -I*)
        CFLAGS="${CFLAGS} ${1}"
        shift
        ;;
      -include*)
        # strip off leading -include                                                                                                                              
        REMOVE_LEADING_INCLUDE="${1##-include}"
        echo "REMOVE-LEADING-INCLUDE" ${REMOVE_LEADING_INCLUDE}
        RELPATH_AFTER_INCLUDE="${REMOVE_LEADING_INCLUDE##*include/}"
        CFLAGS="${CFLAGS} -include${RELPATH_AFTER_INCLUDE}"
        shift
        ;;
      *)
       CFLAGS="${CFLAGS} ${1}"
        shift
        ;;
   esac
done

echo $CFLAGS
16
02.08.2014, 01:10
1 ответ

опция logrotate, которая делает то, что Вы описываете, является copytruncate. Просто добавьте эту опцию в Вашу существующую конфигурацию логирования. Вот выдержка из руководства logrotate.conf:

   copytruncate
          Truncate  the  original log file in place after creating a copy,
          instead of moving the old log file and optionally creating a new
          one,  It  can be used when some program can not be told to close
          its logfile and thus might continue writing (appending)  to  the
          previous log file forever.  Note that there is a very small time
          slice between copying the file and truncating it, so  some  log-
          ging  data  might be lost.  When this option is used, the create
          option will have no effect, as the old log file stays in  place.
14
27.01.2020, 19:49

Теги

Похожие вопросы