SOURCES: postgresql.init - use awk instead of sed (to be consisten...

qboosh qboosh at pld-linux.org
Tue Feb 19 22:18:32 CET 2008


Author: qboosh                       Date: Tue Feb 19 21:18:32 2008 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- use awk instead of sed (to be consistent with rc-scripts dependencies)
- more sane way to check for PID existence (grep can be easily misleaded)

---- Files affected:
SOURCES:
   postgresql.init (1.73 -> 1.74) 

---- Diffs:

================================================================
Index: SOURCES/postgresql.init
diff -u SOURCES/postgresql.init:1.73 SOURCES/postgresql.init:1.74
--- SOURCES/postgresql.init:1.73	Sun Dec 10 00:05:48 2006
+++ SOURCES/postgresql.init	Tue Feb 19 22:18:27 2008
@@ -79,7 +79,7 @@
 	elif [ $status -eq 0 ]; then
 		PG_STATUS="running"
         # or maybe grab it from postmaster.pid file?
-		PG_PID=`echo "$output" | sed 's/^pg_ctl:.*PID: \([0-9]\+\).*/\1/' | head -n 1`
+		PG_PID=$(echo "$output" | awk '/PID: / { match($0, "PID: [0-9]+"); print substr($0,RSTART+5,RLENGTH-5) }')
 	fi
 }
 
@@ -120,7 +120,7 @@
 		if [ "$PG_STATUS" = "running" ]; then
 			# pg_ctl status can misinform us about postgresql status
 			# so let's check if postmaster is really alive
-			if ps ax | grep -v grep | grep -q "$PG_PID"; then
+			if ps -p "$PG_PID" >/dev/null; then
 				msg_already_running "PostgreSQL $pgdir"
 			else
 				# pg_ctl has misinformed us about postgresql status;
@@ -145,7 +145,7 @@
 			msg_stopping "PostgreSQL $pgdir"
 			busy
 			# is postgresql really alive?
-			if ps ax | grep -v grep | grep -q "$PG_PID"; then
+			if ps -p "$PG_PID" >/dev/null; then
 				TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -w -D $pgdir stop -m fast 2>&1 >/dev/null"
 				pgstatus "$pgdir"
 				if [ "$PG_STATUS" != "not running" ]; then
@@ -200,7 +200,7 @@
 			msg_reloading "PostgreSQL $pgdir"
 			busy
 			# is postgresql really alive?
-			if ps ax | grep -v grep | grep -q "$PG_PID"; then
+			if ps -p "$PG_PID" >/dev/null; then
 				TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -D $pgdir restart 2>&1 >/dev/null"
 					pgstatus "$pgdir"
 				if [ "$PG_STATUS" = "running" ]; then
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/postgresql.init?r1=1.73&r2=1.74&f=u



More information about the pld-cvs-commit mailing list