aboutsummaryrefslogtreecommitdiffstats
path: root/meta-openstack/recipes-support/postgresql/postgresql/postgresql
diff options
context:
space:
mode:
Diffstat (limited to 'meta-openstack/recipes-support/postgresql/postgresql/postgresql')
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql/postgresql117
1 files changed, 32 insertions, 85 deletions
diff --git a/meta-openstack/recipes-support/postgresql/postgresql/postgresql b/meta-openstack/recipes-support/postgresql/postgresql/postgresql
index cfff7596..2bdd5824 100644
--- a/meta-openstack/recipes-support/postgresql/postgresql/postgresql
+++ b/meta-openstack/recipes-support/postgresql/postgresql/postgresql
@@ -1,93 +1,40 @@
-#!/bin/sh
+[Unit]
+Description=PostgreSQL database server
+After=network.target
-### BEGIN INIT INFO
-# Provides: postgresql
-# Required-Start: $local_fs $remote_fs $network $time
-# Required-Stop: $local_fs $remote_fs $network $time
-# Should-Start: $syslog
-# Should-Stop: $syslog
-# Default-Start: 2 3 4 5
-# Default-Stop: 0 1 6
-# Short-Description: PostgreSQL RDBMS server
-### END INIT INFO
+[Service]
+Type=forking
-DAEMON=/usr/bin/postmaster
-DESC="PostgreSQL RDBMS server"
-DEFAULT_DATA_DIR=%DB_DATADIR%
+User=postgres
+Group=postgres
-datadir=`grep ^data_directory $DEFAULT_DATA_DIR/postgresql.conf |sed -e "s#^.*= '##; s#'.*##"`
-if [ "$datadir" = "" ] ; then
- datadir=$DEFAULT_DATA_DIR
-else
- if [ ! -e $datadir/postgresql.conf ] ; then
- if [ -e $DEFAULT_DATA_DIR/postgresql.conf -a -e $datadir ] ; then
- ln -s $DEFAULT_DATA_DIR/*.conf $datadir/
- fi
- fi
-fi
+# Where to send early-startup messages from the server (before the logging
+# options of postgresql.conf take effect)
+# This is normally controlled by the global default set by systemd
+# StandardOutput=syslog
-cd /
+# Disable OOM kill on the postmaster
+OOMScoreAdjust=-1000
+# ... but allow it still to be effective for child processes
+# (note that these settings are ignored by Postgres releases before 9.5)
+Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
+Environment=PG_OOM_ADJUST_VALUE=0
-start ()
-{
- echo -n "Starting postgres server..."
- if pidof ${DAEMON} > /dev/null; then
- echo "already running."
- exit 0
- fi
- touch /var/log/postgresql.log
- chown postgres /var/log/postgresql.log
- sudo -u postgres /usr/bin/pg_ctl start -w -D $datadir -s -l /var/log/postgresql.log
- if [ $? -eq 0 ]; then
- echo "done."
- else
- echo "failed."
- fi
-}
+# Maximum number of seconds pg_ctl will wait for postgres to start. Note that
+# PGSTARTTIMEOUT should be less than TimeoutSec value.
+Environment=PGSTARTTIMEOUT=270
-stop ()
-{
- echo -n "Stopping postgres server..."
- if ! pidof ${DAEMON} >/dev/null; then
- echo "not running."
- exit 0
- fi
- sudo -u postgres /usr/bin/pg_ctl stop -w -D $datadir -m fast -s
- if [ $? -eq 0 ]; then
- echo "done."
- else
- if [ -f $DEFAULT_DATA_DIR/postmaster.pid -a "$datadir" != "$DEFAULT_DATA_DIR" ] ; then
- # Special case for transition
- sudo -u postgres /usr/bin/pg_ctl stop -w -D $DEFAULT_DATA_DIR -m fast -s
- fi
- if ! pidof ${DAEMON} > /dev/null; then
- echo "done."
- else
- echo "failed."
- exit 1
- fi
- fi
-}
+Environment=PGDATA=/usr/local/pgsql/data
-case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- force-reload)
- stop
- start
- ;;
- restart)
- stop
- start
- ;;
- *)
- echo "Usage: $0 {start|stop|force-reload|restart}"
- exit 1
- ;;
-esac
-exit 0
+ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
+ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
+ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s
+
+# 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]
+WantedBy=multi-user.target