pg_ctl patch to integrate apache's rotatelogs

Поиск
Список
Период
Сортировка
От Andrew Hammond
Тема pg_ctl patch to integrate apache's rotatelogs
Дата
Msg-id 40A4E758.1080603@ca.afilias.info
обсуждение исходный текст
Ответы Re: pg_ctl patch to integrate apache's rotatelogs  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-patches
Please find attached a patch to integrate rotatelogs into pg_ctl. I've
noticed a couple of questions about how to do this and it seems easier
(and more elegant) to solve it in code rather than in documentation. The
patch is pretty simple and I've made it reasonably self documenting. It
test for apache rotatelogs only when unless it is specifically used.
This code only adds functionality and causes no changes to current usage.

If anyone has suggestions how I could improve it or make it more
acceptable in any way, I'd very much like to hear them.

Andrew Hammond

--- pg_ctl_orig    2004-03-19 14:01:40.000000000 -0500
+++ pg_ctl_new    2004-03-24 15:30:29.000000000 -0500
@@ -39,6 +39,9 @@
 Options for start or restart:
   -l FILENAME             write (or append) server log to FILENAME.  The
                           use of this option is highly recommended.
+  -r ROTATIONTIME         pipe through apache's rotatelogs instead of writing
+                          dirrectly to FILENAME. Rotate the logs every
+              ROTATIONTIME seconds (see rotatelogs man page)
   -o OPTIONS              command line options to pass to the postmaster
                           (PostgreSQL server executable)
   -p PATH-TO-POSTMASTER   normally not necessary
@@ -62,6 +65,10 @@
 VERSION='7.4.2'
 DEF_PGPORT='5432'

+# how should this be dealt with by autoconf?
+apache_bindir='/usr/bin'
+rotatelogs_path="$apache_bindir/rotatelogs"
+
 # protect the log file
 umask 077

@@ -114,6 +121,7 @@
 wait=
 wait_seconds=60
 logfile=
+rotation_time=
 silence_echo=
 shutdown_mode=smart
 PGDATAOPTS=""
@@ -143,6 +151,12 @@
     -l*)
         logfile=`echo "$1" | sed 's/^-l//'`
         ;;
+    -r)
+        rotation_time="$2"
+        shift;;
+    -r*)
+        rotation_time=`echo "$1" | sed 's/^-m//'`
+        ;;
     -m)
         shutdown_mode="$2"
         shift;;
@@ -207,6 +221,18 @@
     exit 1
 fi

+if [ ! x"$rotation_time" = x"" ]; then
+    if [ ! -x $rotatelogs_path ]; then
+        echo "$CMDNAME: log rotation specified but can't find $rotatelogs_path" 1>&2
+        exit 1
+    fi
+
+    if [ x"$logfile" = x"" ]; then
+        echo "$CMDNAME: log rotation specified but no logfile given. Use the -l option." 1>&2
+        exit 1
+    fi
+fi
+
 if [ -z "$wait" ]; then
     case "$op" in
     start)      wait=no;;
@@ -338,7 +364,11 @@
     fi

     if [ -n "$logfile" ]; then
+        if [ -n "$rotation_time" ]; then         # use rotatelogs for logging
+            "$po_path" ${1+"$@"} ${PGDATAOPTS+$PGDATAOPTS} </dev/null 2>&1 | "$rotatelogs_path" $logfile
$rotation_time& 
+    else
         "$po_path" ${1+"$@"} ${PGDATAOPTS+$PGDATAOPTS} </dev/null >>$logfile 2>&1 &
+    fi
     else
         # when starting without log file, redirect stderr to stdout, so
         # pg_ctl can be invoked with >$logfile and still have pg_ctl's

Вложения

В списке pgsql-patches по дате отправления:

Предыдущее
От: Larry Rosenman
Дата:
Сообщение: Re: [HACKERS] threads stuff/UnixWare
Следующее
От: Larry Rosenman
Дата:
Сообщение: src/template/unixware syntax error