Skip to content

Commit 5b912b0

Browse files
committed
pg_ctl: a script to start/stop/restart and report status of postmaster.
1 parent 169051a commit 5b912b0

File tree

2 files changed

+219
-0
lines changed

2 files changed

+219
-0
lines changed

src/bin/pg_ctl/Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# Makefile.inc--
4+
# Makefile for bin/pg_ctl
5+
#
6+
# Copyright (c) 1999, PostgreSQL Global Development Group
7+
#
8+
#
9+
# IDENTIFICATION
10+
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.1 1999/12/06 07:23:41 ishii Exp $
11+
#
12+
#-------------------------------------------------------------------------
13+
14+
SRCDIR= ../..
15+
include ../../Makefile.global
16+
17+
all: pg_ctl
18+
19+
pg_ctl: pg_ctl.sh
20+
sed -e 's@__BINDIR__@$(BINDIR)@' pg_ctl.sh > pg_ctl
21+
22+
install: pg_ctl
23+
$(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
24+
25+
clean:
26+
rm -f pg_ctl
27+
28+
dep depend:

src/bin/pg_ctl/pg_ctl.sh

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#! /bin/sh
2+
#-------------------------------------------------------------------------
3+
#
4+
# pg_ctl.sh--
5+
# Start/Stop/Restart/Report status of postmaster
6+
#
7+
# Copyright (c) 1999, PostgreSQL Global Development Group
8+
#
9+
#
10+
# IDENTIFICATION
11+
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.1 1999/12/06 07:23:41 ishii Exp $
12+
#
13+
#-------------------------------------------------------------------------
14+
CMDNAME=`basename $0`
15+
16+
# set default path to postmaster
17+
po_path=__BINDIR__/postmaster
18+
19+
# set default shutdown signal
20+
sig="-TERM"
21+
22+
while [ "$#" -gt 0 ]
23+
do
24+
case $1 in
25+
-h|--help)
26+
usage=1
27+
break
28+
;;
29+
-D)
30+
shift
31+
PGDATA="$1"
32+
;;
33+
-p)
34+
shift
35+
po_path="$1"
36+
;;
37+
-m)
38+
shift
39+
case $1 in
40+
f|fast)
41+
sig="-INT"
42+
;;
43+
i|immediate)
44+
sig="-QUIT"
45+
;;
46+
*)
47+
echo "$CMDNAME: Wrong shutdown mode $sigopt"
48+
usage=1
49+
;;
50+
esac
51+
;;
52+
-w)
53+
wait=1
54+
;;
55+
-o)
56+
shift
57+
POSTOPTS="$1"
58+
;;
59+
start)
60+
op="start"
61+
;;
62+
stop)
63+
op="stop"
64+
;;
65+
restart)
66+
op="restart"
67+
;;
68+
status)
69+
op="status"
70+
;;
71+
*)
72+
usage=1
73+
break
74+
;;
75+
esac
76+
shift
77+
done
78+
79+
if [ "$usage" = 1 -o "$op" = "" ];then
80+
echo "Usage: $CMDNAME [-w][-D database_dir][-p path_to_postmaster][-o \"postmaster_opts\"] start"
81+
echo " $CMDNAME [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]] stop"
82+
echo " $CMDNAME [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]][-o \"postmaster_opts\"] restart"
83+
echo " $CMDNAME [-D database_dir] status"
84+
exit 1
85+
fi
86+
87+
if [ -z "$PGDATA" ];then
88+
echo "$CMDNAME: No database directory or environment variable \$PGDATA is specified"
89+
exit 1
90+
fi
91+
92+
DEFPOSTOPTS=$PGDATA/postmaster.opts.default
93+
POSTOPTSFILE=$PGDATA/postmaster.opts
94+
PIDFILE=$PGDATA/postmaster.pid
95+
96+
if [ $op = "status" ];then
97+
if [ -f $PIDFILE ];then
98+
echo "$CMDNAME: postmaster is running (pid: `cat $PIDFILE`)"
99+
echo "options are:"
100+
echo "`cat $POSTOPTSFILE`"
101+
exit 0
102+
else
103+
echo "$CMDNAME: postmaster is not running"
104+
exit 1
105+
fi
106+
fi
107+
108+
if [ $op = "stop" -o $op = "restart" ];then
109+
if [ -f $PIDFILE ];then
110+
kill $sig `cat $PIDFILE`
111+
112+
# wait for postmaster shutting down
113+
if [ "$wait" = 1 -o $op = "restart" ];then
114+
cnt=0
115+
echo -n "Waiting for postmaster shutting down.."
116+
117+
while :
118+
do
119+
if [ -f $PIDFILE ];then
120+
echo -n "."
121+
cnt=`expr $cnt + 1`
122+
if [ $cnt -gt 60 ];then
123+
echo "$CMDNAME: postmaster does not shut down"
124+
exit 1
125+
fi
126+
else
127+
break
128+
fi
129+
sleep 1
130+
done
131+
echo "done."
132+
fi
133+
134+
else
135+
echo "$CMDNAME: Can't find $PIDFILE."
136+
echo "Is postmaster running?"
137+
if [ $op = "restart" ];then
138+
echo "Anyway, I'm going to start up postmaster..."
139+
else
140+
exit 1
141+
fi
142+
fi
143+
fi
144+
145+
if [ $op = "start" -o $op = "restart" ];then
146+
if [ -f $PIDFILE ];then
147+
echo "$CMDNAME: It seems another postmaster is running. Try to start postmaster anyway."
148+
pid=`cat $PIDFILE`
149+
fi
150+
151+
if [ -z "$POSTOPTS" ];then
152+
if [ -f $DEFPOSTOPTS ];then
153+
eval `cat $DEFPOSTOPTS` &
154+
else
155+
echo "$CMDNAME: Can't find $DEFPOSTOPTS"
156+
exit 1
157+
fi
158+
else
159+
$po_path $POSTOPTS &
160+
fi
161+
162+
if [ -f $PIDFILE ];then
163+
if [ "`cat $PIDFILE`" = "$pid" ];then
164+
echo "$CMDNAME: Cannot start postmaster. Is another postmaster is running?"
165+
exit 1
166+
fi
167+
fi
168+
169+
# wait for postmaster starting up
170+
if [ "$wait" = 1 ];then
171+
cnt=0
172+
echo -n "Waiting for postmaster starting up.."
173+
while :
174+
do
175+
if [ ! -f $PIDFILE ];then
176+
echo -n "."
177+
cnt=`expr $cnt + 1`
178+
if [ $cnt -gt 60 ];then
179+
echo "$CMDNAME: postmaster does not start up"
180+
exit 1
181+
fi
182+
sleep 1
183+
else
184+
break
185+
fi
186+
done
187+
echo "done."
188+
fi
189+
fi
190+
191+
exit 0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy