Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3596528

Browse files
committed
Add more portability to echo -n (code stolen from createlang)
Do not start postmaster if postgres is running
1 parentbd62e06 commit3596528

File tree

1 file changed

+62
-36
lines changed

1 file changed

+62
-36
lines changed

‎src/bin/pg_ctl/pg_ctl.sh

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,33 @@
88
#
99
#
1010
# IDENTIFICATION
11-
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.5 1999/12/22 04:41:17 ishii Exp $
11+
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.6 2000/01/09 12:06:52 ishii Exp $
1212
#
1313
#-------------------------------------------------------------------------
1414
CMDNAME=`basename$0`
1515

16+
# Check for echo -n vs echo \c
17+
18+
ECHO=echo
19+
ifecho'\c'| grep -s c>/dev/null2>&1
20+
then
21+
ECHO_N="echo -n"
22+
ECHO_C=""
23+
else
24+
ECHO_N="echo"
25+
ECHO_C='\c'
26+
fi
27+
1628
#
1729
# Find out where we're located
1830
#
19-
ifecho"$0"| grep'/'> /dev/null2>&1
31+
if$ECHO"$0"| grep'/'> /dev/null2>&1
2032
then
2133
# explicit dir name given
22-
PGPATH=`echo$0| sed's,/[^/]*$,,'`# (dirname command is not portable)
34+
PGPATH=`$ECHO$0| sed's,/[^/]*$,,'`# (dirname command is not portable)
2335
else
2436
# look for it in PATH ('which' command is not portable)
25-
fordirin`echo"$PATH"| sed's/:/ /g'`
37+
fordirin`$ECHO"$PATH"| sed's/:/ /g'`
2638
do
2739
# empty entry in path means current dir
2840
[-z"$dir" ]&& dir='.'
@@ -39,12 +51,12 @@ for prog in postmaster
3951
do
4052
if [!-x"$PGPATH/$prog" ]
4153
then
42-
echo"The program$prog needed by$CMDNAME could not be found. It was"
43-
echo"expected at:"
44-
echo"$PGPATH/$prog"
45-
echo"If this is not the correct directory, please start$CMDNAME"
46-
echo"with a full search path. Otherwise make sure that the program"
47-
echo"was installed successfully."
54+
$ECHO"The program$prog needed by$CMDNAME could not be found. It was"
55+
$ECHO"expected at:"
56+
$ECHO"$PGPATH/$prog"
57+
$ECHO"If this is not the correct directory, please start$CMDNAME"
58+
$ECHO"with a full search path. Otherwise make sure that the program"
59+
$ECHO"was installed successfully."
4860
exit 1
4961
fi
5062
done
@@ -79,7 +91,7 @@ do
7991
sig="-QUIT"
8092
;;
8193
*)
82-
echo"$CMDNAME: Wrong shutdown mode$sigopt"
94+
$ECHO"$CMDNAME: Wrong shutdown mode$sigopt"
8395
usage=1
8496
;;
8597
esac
@@ -112,15 +124,15 @@ do
112124
done
113125

114126
if ["$usage"= 1-o"$op"="" ];then
115-
echo"Usage:$CMDNAME [-w][-D database_dir][-p path_to_postmaster][-o\"postmaster_opts\"] start"
116-
echo"$CMDNAME [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]] stop"
117-
echo"$CMDNAME [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]][-o\"postmaster_opts\"] restart"
118-
echo"$CMDNAME [-D database_dir] status"
127+
$ECHO"Usage:$CMDNAME [-w][-D database_dir][-p path_to_postmaster][-o\"postmaster_opts\"] start"
128+
$ECHO"$CMDNAME [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]] stop"
129+
$ECHO"$CMDNAME [-w][-D database_dir][-m s[mart]|f[ast]|i[mmediate]][-o\"postmaster_opts\"] restart"
130+
$ECHO"$CMDNAME [-D database_dir] status"
119131
exit 1
120132
fi
121133

122134
if [-z"$PGDATA" ];then
123-
echo"$CMDNAME: No database directory or environment variable\$PGDATA is specified"
135+
$ECHO"$CMDNAME: No database directory or environment variable\$PGDATA is specified"
124136
exit 1
125137
fi
126138

@@ -130,49 +142,63 @@ PIDFILE=$PGDATA/postmaster.pid
130142

131143
if [$op="status" ];then
132144
if [-f$PIDFILE ];then
133-
echo"$CMDNAME: postmaster is running (pid:`cat$PIDFILE`)"
134-
echo"options are:"
135-
echo"`cat$POSTOPTSFILE`"
145+
PID=`cat$PIDFILE`
146+
if [$PID-lt 0 ];then
147+
PID=`expr 0 -$PID`
148+
$ECHO"$CMDNAME: postgres is running (pid:$PID)"
149+
else
150+
$ECHO"$CMDNAME: postmaster is running (pid:$PID)"
151+
$ECHO"options are:"
152+
$ECHO"`cat$POSTOPTSFILE`"
153+
fi
136154
exit 0
137155
else
138-
echo"$CMDNAME: postmaster is not running"
156+
$ECHO"$CMDNAME: postmaster or postgres is not running"
139157
exit 1
140158
fi
141159
fi
142160

143161
if [$op="stop"-o$op="restart" ];then
144162
if [-f$PIDFILE ];then
163+
PID=`cat$PIDFILE`
164+
if [$PID-lt 0 ];then
165+
PID=`expr 0 -$PID`
166+
$ECHO"$CMDNAME: Cannot restart postmaster. postgres is running (pid:$PID)"
167+
$ECHO"Please terminate postgres and try again"
168+
exit 1
169+
fi
170+
145171
kill$sig`cat$PIDFILE`
146172

147173
# wait for postmaster shutting down
148174
if ["$wait"= 1-o$op="restart" ];then
149175
cnt=0
150-
echo -n"Waiting for postmaster shutting down.."
176+
$ECHO_N"Waiting for postmaster shutting down.."$ECHO_C
151177

152178
while:
153179
do
154180
if [-f$PIDFILE ];then
155-
echo -n"."
181+
$ECHO_N"."$ECHO_C
156182
cnt=`expr$cnt + 1`
157183
if [$cnt-gt 60 ];then
158-
echo"$CMDNAME: postmaster does not shut down"
184+
$ECHO"$CMDNAME: postmaster does not shut down"
159185
exit 1
160186
fi
161187
else
162188
break
163189
fi
164190
sleep 1
165191
done
166-
echo"done."
192+
$ECHO"done."
167193
fi
168194

169-
echo"postmaster successfully shut down."
195+
$ECHO"postmaster successfully shut down."
170196

171197
else
172-
echo"$CMDNAME: Can't find$PIDFILE."
173-
echo"Is postmaster running?"
198+
$ECHO"$CMDNAME: Can't find$PIDFILE."
199+
$ECHO"Is postmaster running?"
174200
if [$op="restart" ];then
175-
echo"Anyway, I'm going to start up postmaster..."
201+
$ECHO"Anyway, I'm going to start up postmaster..."
176202
else
177203
exit 1
178204
fi
@@ -181,7 +207,7 @@ fi
181207

182208
if [$op="start"-o$op="restart" ];then
183209
if [-f$PIDFILE ];then
184-
echo"$CMDNAME: It seems another postmaster is running. Try to start postmaster anyway."
210+
$ECHO"$CMDNAME: It seems another postmaster is running. Try to start postmaster anyway."
185211
pid=`cat$PIDFILE`
186212
fi
187213

@@ -192,7 +218,7 @@ if [ $op = "start" -o $op = "restart" ];then
192218
if [-f$DEFPOSTOPTS ];then
193219
eval`cat$DEFPOSTOPTS`&
194220
else
195-
echo"$CMDNAME: Can't find$DEFPOSTOPTS"
221+
$ECHO"$CMDNAME: Can't find$DEFPOSTOPTS"
196222
exit 1
197223
fi
198224
else
@@ -205,33 +231,33 @@ if [ $op = "start" -o $op = "restart" ];then
205231

206232
if [-f$PIDFILE ];then
207233
if ["`cat$PIDFILE`"="$pid" ];then
208-
echo"$CMDNAME: Cannot start postmaster. Is another postmaster is running?"
234+
$ECHO"$CMDNAME: Cannot start postmaster. Is another postmaster is running?"
209235
exit 1
210236
fi
211237
fi
212238

213239
# wait for postmaster starting up
214240
if ["$wait"= 1 ];then
215241
cnt=0
216-
echo -n"Waiting for postmaster starting up.."
242+
$ECHO_N"Waiting for postmaster starting up.."$ECHO_C
217243
while:
218244
do
219245
if [!-f$PIDFILE ];then
220-
echo -n"."
246+
$ECHO_N"."$ECHO_C
221247
cnt=`expr$cnt + 1`
222248
if [$cnt-gt 60 ];then
223-
echo"$CMDNAME: postmaster does not start up"
249+
$ECHO"$CMDNAME: postmaster does not start up"
224250
exit 1
225251
fi
226252
sleep 1
227253
else
228254
break
229255
fi
230256
done
231-
echo"done."
257+
$ECHO"done."
232258
fi
233259

234-
echo"postmaster successfully started up."
260+
$ECHO"postmaster successfully started up."
235261
fi
236262

237263
exit 0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp