I've attached a patch for pg_ctl which integrates the Apache project's rotatelogs for logging. Is there any interested in the community for such a thing? I have not yet added the appropriate stuff to autoconf to completely integrate this.

I would appreciate any suggestions for improvement.

Drew
--- pg_ctl	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         use apache's rotatelogs instead of writing
+                          dirrectly tto FILENAME. Rotate the logs every 
+			  ROTATIONTIME seconds (see man for rotatelogs)
   -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'
 
+# have autoconf detect this?
+apache_bindir='/opt/OXRS/apache/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. Try 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
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to