Browse Source

PR#202 run-time check and related issues

Thomas Lotterer 22 years ago
parent
commit
a60c4dc2db
2 changed files with 48 additions and 42 deletions
  1. 38 38
      postgresql/postgresql.spec
  2. 10 4
      postgresql/rc.postgresql

+ 38 - 38
postgresql/postgresql.spec

@@ -40,7 +40,7 @@ Distribution: OpenPKG [BASE]
 Group:        Database
 License:      GPL
 Version:      %{V_postgresql}
-Release:      20030722
+Release:      20030723
 
 #   package options
 %option       with_cxx      no
@@ -319,38 +319,33 @@ AutoReqProv:  no
     rm -rf $RPM_BUILD_ROOT
 
 %pre
-    if [ $1 -gt 1 ]; then
-        #   upgrading of installation
-        if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
-             -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
-            #   database migration dumping hint
-            v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
-            v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
-            v_new_all="%{V_postgresql}"
-            v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
-            if [ ".$v_old_maj" != ".$v_new_maj" ]; then
-               if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$PG_MIGRATE" != .ignore ]; then
-                    ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
-                      echo "which is a major version change. We expect a database incompatibility,"
-                      echo "so we strongly recommend that you backup your existing database"
-                      echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
-                      echo "    \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
-                      echo "Alternatively, if you want force this package to be installed without"
-                      echo "performing a database dump, run the following command before upgrading:"
-                      echo "    \$ PG_MIGRATE=ignore; export PG_MIGRATE"
-                    ) | %{l_rpmtool} msg -b -t error
-                    exit 1
-                fi
+    #   before upgrade, check migration dump, save status and stop service
+    [ $1 -eq 2 ] || exit 0
+    if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a \
+         -f $RPM_INSTALL_PREFIX/bin/pg_migrate ]; then
+        #   database migration dumping hint
+        v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
+        v_old_maj=`echo "$v_old_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
+        v_new_all="%{V_postgresql}"
+        v_new_maj=`echo "$v_new_all" | sed -e 's/^\([0-9]*\.[0-9]*\).*/\1/'`
+        if [ ".$v_old_maj" != ".$v_new_maj" ]; then
+           if [ ! -f $RPM_INSTALL_PREFIX/var/postgresql/db.dump.sql.bz2 -a ".$PG_MIGRATE" != .ignore ]; then
+                ( echo "You are upgrading from PostgreSQL $v_old_all to PostgresSQL $v_new_all,"
+                  echo "which is a major version change. We expect a database incompatibility,"
+                  echo "so we strongly recommend that you backup your existing database"
+                  echo "($RPM_INSTALL_PREFIX/var/postgresql/db/) first by running:"
+                  echo "    \$ $RPM_INSTALL_PREFIX/bin/pg_migrate dump"
+                  echo "Alternatively, if you want force this package to be installed without"
+                  echo "performing a database dump, run the following command before upgrading:"
+                  echo "    \$ PG_MIGRATE=ignore; export PG_MIGRATE"
+                ) | %{l_rpmtool} msg -b -t error
+                exit 1
             fi
         fi
-        rm -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART >/dev/null 2>&1 || true
-        if [ ".`$l_prefix/etc/rc postgresql status 2>&1 | grep 'is running'`" != . ]; then
-            echo "Shutting down currently running database engine." | %{l_rpmtool} msg -b -t notice
-            $RPM_INSTALL_PREFIX/etc/rc postgresql stop
-            touch $RPM_INSTALL_PREFIX/var/posgresql/RESTART
-            sleep 4
-        fi
     fi
+    eval `%{l_rc} postgresql status 2>/dev/null | tee %{l_tmpfile}`
+    %{l_rc} postgresql stop 2>/dev/null
+    exit 0
 
 %post
     if [ $1 -eq 1 ]; then
@@ -401,14 +396,11 @@ AutoReqProv:  no
           echo "Threading       = 2"
         ) | $RPM_INSTALL_PREFIX/bin/odbcinst -i -d -r
 %endif
-    elif [ $1 -gt 1 ]; then
-        #   upgrading of installation
-        if [ -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART ]; then
-            echo "Starting database engine again." | %{l_rpmtool} msg -b -t notice
-            $RPM_INSTALL_PREFIX/etc/rc postgresql start
-            rm -f $RPM_INSTALL_PREFIX/var/posgresql/RESTART >/dev/null 2>&1 || true
-            sleep 2
-        fi
+    fi
+    if [ $1 -eq 2 ]; then
+        #   after upgrade, restore status
+        { eval `cat %{l_tmpfile}`; rm -f %{l_tmpfile}; true; } >/dev/null 2>&1
+        [ ".$postgresql_active" = .yes ] && %{l_rc} postgresql start
         if [ -f $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION -a ".$PG_MIGRATE" != .ignore ]; then
             #   database migration restoring hint
             v_old_all=`cat $RPM_INSTALL_PREFIX/var/postgresql/db/PG_VERSION`
@@ -425,4 +417,12 @@ AutoReqProv:  no
             fi
         fi
     fi
+    exit 0
+
+%preun
+    #   before erase, stop service and remove log files
+    [ $1 -eq 0 ] || exit 0
+    %{l_rc} postgresql stop 2>/dev/null
+    rm -f $RPM_INSTALL_PREFIX/var/postgresql/run/* >/dev/null 2>&1 || true
+    exit 0
 

+ 10 - 4
postgresql/rc.postgresql

@@ -8,9 +8,8 @@
     postgresql_flags=""
     postgresql_datadir="@l_prefix@/var/postgresql/db"
     postgresql_shut_mode="smart"
-    postgresql_socket_inet="localhost"
+    postgresql_socket_inet="127.0.0.1"
     postgresql_socket_unix="@l_prefix@/var/postgresql/run/"
-    postgresql_log_file="@l_prefix@/var/postgresql/run/postmaster.log"
     postgresql_log_prolog="true"
     postgresql_log_epilog="true"
     postgresql_log_numfiles="10"
@@ -20,6 +19,7 @@
 %common
     postgresql_opts="-i -h $postgresql_socket_inet -k $postgresql_socket_unix"
     postgresql_opts="$postgresql_opts $postgresql_flags"
+    postgresql_log_file="@l_prefix@/var/postgresql/run/postgresql.log"
 
 %status -u @l_rusr@ -o
     postgresql_usable="unknown"
@@ -32,26 +32,32 @@
 
 %start -p 400 -u @l_rusr@
     rcService postgresql enable yes || exit 0
+    rcService postgresql active yes && exit 0
     @l_prefix@/bin/pg_ctl start -l $postgresql_log_file -D $postgresql_datadir -o "$postgresql_opts"
 
 %stop -p 400 -u @l_rusr@
     rcService postgresql enable yes || exit 0
+    rcService postgresql active no  && exit 0
     @l_prefix@/bin/pg_ctl stop -l $postgresql_log_file -D $postgresql_datadir -m $postgresql_shut_mode
 
 %restart -p 400 -u @l_rusr@
     rcService postgresql enable yes || exit 0
+    rcService postgresql active no  && exit 0
     @l_prefix@/bin/pg_ctl restart -l $postgresql_log_file -D $postgresql_datadir -o "$postgresql_opts" -m $postgresql_shut_mode
 
 %reload -p 400 -u @l_rusr@
     rcService postgresql enable yes || exit 0
+    rcService postgresql active no  && exit 0
     @l_prefix@/bin/pg_ctl reload -D $postgresql_datadir
 
 %daily -u @l_rusr@
     rcService postgresql enable yes || exit 0
+
+    #   rotate logfile
     shtool rotate -f \
         -n ${postgresql_log_numfiles} -s ${postgresql_log_minsize} -d \
-        -z ${postgresql_log_complevel} -m 644 \
+        -z ${postgresql_log_complevel} -m 600 -o @l_rusr@ -g @l_rgrp@ \
         -P "$postgresql_log_prolog" \
-        -E "@l_prefix@/bin/pg_ctl reload -D $postgresql_datadir; $postgresql_log_epilog" \
+        -E "$postgresql_log_epilog && rc postgresql reload" \
         $postgresql_log_file