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
}
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;
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
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