[Unit]
Description=CFEngine Enterprise PostgreSQL Database
After=syslog.target
ConditionPathExists=/var/cfengine/bin/pg_ctl
PartOf=cfengine3.service

[Service]
Type=forking
WorkingDirectory=/tmp
User=cfpostgres
Restart=always
RestartSec=10

PIDFile=/var/cfengine/state/pg/data/postmaster.pid
SyslogIdentifier=postgres

# 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

# Maximum number of seconds pg_ctl will wait for postgres to start.  Note that
# PGSTARTTIMEOUT should be less than TimeoutSec value.
#Environment=PGSTARTTIMEOUT=270

Environment=PGDATA=/var/cfengine/state/pg/data

ExecStart=/var/cfengine/bin/pg_ctl -w -D ${PGDATA} -l /var/log/postgresql.log start
ExecStop=/var/cfengine/bin/pg_ctl -w -D ${PGDATA} -l /var/log/postgresql.log stop -m fast
ExecReload=/var/cfengine/bin/pg_ctl -w -D ${PGDATA} -l /var/log/postgresql.log reload -m fast

[Install]
WantedBy=multi-user.target
