From b3e56078cdf646390b3a6cd58285414e64da745c Mon Sep 17 00:00:00 2001 From: Jakub Bogusz Date: Tue, 19 Feb 2008 21:18:27 +0000 Subject: [PATCH] - 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) Changed files: postgresql.init -> 1.74 --- postgresql.init | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/postgresql.init b/postgresql.init index 34b2d2a..727c275 100644 --- a/postgresql.init +++ b/postgresql.init @@ -79,7 +79,7 @@ pgstatus() { 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 @@ start() { 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 @@ stop() { 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 @@ case "$action" in 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 -- 2.44.0