summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2015-03-19 12:53:28 +0100
committerPavel Raiskup <praiskup@redhat.com>2015-03-19 12:56:38 +0100
commit8c7b2cd5f6d9efb59568382cd8b6e88d9be517bb (patch)
treeeaba95c6d219f5f9bed707ea578e6358b0aace59
parent00b185f55bf37dfb5c29220218ff6e4a078a71db (diff)
downloadpostgresql-setup-8c7b2cd5f6d9efb59568382cd8b6e88d9be517bb.tar.gz
postgresql-setup-8c7b2cd5f6d9efb59568382cd8b6e88d9be517bb.tar.xz
postgresql-setup-8c7b2cd5f6d9efb59568382cd8b6e88d9be517bb.zip
init: add PGSTARTTIMEOUT config env variable
* postgresql.init.in (PGSTARTTIMEOUT): New variable. (start): Use postgresql-ctl and respect PGSTARTTIMEOUT. * postgresql.service.in: Better document the timeouts. (PGSTARTTIMEOUT): New env variable. (ExecStart): Respect PGSTARTTIMEOUT. * NEWS: Document.
-rw-r--r--NEWS2
-rw-r--r--postgresql.init.in18
-rw-r--r--postgresql.service.in10
3 files changed, 24 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 051a30a..c2d0c5c 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,8 @@ New in 3.0 version
* The sysvinit support should be OK finally, sysvinit system is now
automatically detected without --with-sysvinit configure option.
+* The starting timeout is now configurable via PGSTARTTIMEOUT.
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
New in 2.0 version
diff --git a/postgresql.init.in b/postgresql.init.in
index 70058d6..ca0909e 100644
--- a/postgresql.init.in
+++ b/postgresql.init.in
@@ -73,6 +73,7 @@ PG_OOM_ADJ=-17
export PGDATA
export PGPORT
+export PGSTARTTIMEOUT
lockfile="/var/lock/subsys/${NAME}"
@@ -111,13 +112,22 @@ start()
# is already running. We should probably 'status' first and start only if
# postmaster is down. This just unnecessarily wastes time and generates
# too much (false) rush in $PGLOG.
+ #
+ # The maximum waiting time PGSTARTTIMEOUT is set to 30 second to not hold
+ # the system too long. See `man pg_ctl & -w option`. This is not issue in
+ # case of systemd.
+
run_cmd_as_dbadmin \
- "$PGENGINE/postgres ${PGPORT+-o "-p $PGPORT"} \
- -D '$PGDATA' ${PGOPTS} &" \
+ "@libexecdir@/postgresql-ctl start -D ${PGDATA} -s \
+ -w -t ${PGSTARTTIMEOUT-30}" \
"$PGLOG" "$PGLOG"
- # TODO: parametrize
- sleep 2
+ if test $? -ne 0; then
+ failure "$PSQL_START"
+ echo
+ script_result=1
+ return
+ fi
pid=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null`
if [ "x$pid" != x ]
diff --git a/postgresql.service.in b/postgresql.service.in
index 897f732..aac0054 100644
--- a/postgresql.service.in
+++ b/postgresql.service.in
@@ -26,6 +26,10 @@ OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0
+# Maximum number of seconds pg_ctl will wait for postgres to start. Note that
+# PGSTARTTIMEOUT should be less than TimeoutSec value.
+Environment=PGSTARTTIMEOUT=270
+
@PGDATA_ENVIRONMENT@
ExecStartPre=@libexecdir@/postgresql-check-db-dir %N
@@ -33,11 +37,13 @@ ExecStartPre=@libexecdir@/postgresql-check-db-dir %N
# Use convenient postgresql-ctl wrapper instead of directly pg_ctl. See the
# postgresql-ctl file itself for more info.
-ExecStart=@libexecdir@/postgresql-ctl start -D ${PGDATA} -s -w -t 300
+ExecStart=@libexecdir@/postgresql-ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
ExecStop=@libexecdir@/postgresql-ctl stop -D ${PGDATA} -s -m fast
ExecReload=@libexecdir@/postgresql-ctl reload -D ${PGDATA} -s
-# Give a reasonable amount of time for the server to start up/shut down
+# Give a reasonable amount of time for the server to start up/shut down.
+# Ideally, the timeout for starting PostgreSQL server should be handled more
+# nicely by pg_ctl in ExecStart, so keep its timeout smaller than this value.
TimeoutSec=300
[Install]