From 8c7b2cd5f6d9efb59568382cd8b6e88d9be517bb Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Thu, 19 Mar 2015 12:53:28 +0100 Subject: 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. --- NEWS | 2 ++ postgresql.init.in | 18 ++++++++++++++---- postgresql.service.in | 10 ++++++++-- 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] -- cgit