[Unit]
Description=A lightweight connection pooler for PostgreSQL
Documentation=https://www.pgbouncer.org/
After=syslog.target
After=network.target

[Service]
LimitNOFILE=655360
Type=simple
User={{ pg_dbsu|default('postgres') }}
Group=postgres

# Runtime Directory
RuntimeDirectory=postgresql
RuntimeDirectoryMode=0755
RuntimeDirectoryPreserve=yes

Environment=BOUNCERCONF=/etc/pgbouncer/pgbouncer.ini
PIDFile=/run/postgresql/pgbouncer.pid
{% if os_package is defined and os_package == 'deb' %}
ExecStart=/usr/sbin/pgbouncer ${BOUNCERCONF}
{% else %}
ExecStart=/usr/bin/pgbouncer ${BOUNCERCONF}
{% endif %}
ExecReload=/usr/bin/kill -HUP $MAINPID
KillSignal=SIGINT
TimeoutSec=300
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target