pgbouncer 1.14 supports compilation with systemd support and includes a example service unit file. It would be nice to add systemd as USE flag for this ebuild for the systems that use systemd as their init system.
For more information look at this commit: https://github.com/pgbouncer/pgbouncer/commit/3816a0073f09944a6f7eaa278d2226ca4942b911
Created attachment 664474 [details]
Here's my pgbouncer.service file that worked for my case.
Let me first state I have neither the time nor the interest to learn about systemd. I use OpenRC, and it would not benefit me to waste my time on it. This also mean I don't know enough to truly advise how to best approach any desired outcome using systemd's tools.
But, I'm happy to include support for systemd.
Reading through the sample you've provided appears a bit incomplete/incorrect, so we can't include it as is. The service file should try to adhere to the init script as much as possible. You may want to look at the PostgreSQL service files for inspiration.
It's expected that:
- the socket file be in the /run/postgresql directory
- the mode of /run/postgresql 1755
- the ownership of /run/postgresql be root:postgres
- the log file (/var/log/pgbouncer/pgbouncer.log, I think) be owned pgbouncer:postgres
- the log file (/var/log/pgbouncer/pgbouncer.log, I think) have mode 0640
- the log file directory (/var/log/pgbouncer/, I think) have mode 0755
- the log file directory (/var/log/pgbouncer/, I think) be owned pgbouncer:postgres
This is because the default installation should assume that all applications will connect through pgbouncer rather than directly to PostgreSQL. So, it needs to put the socket file in the default location Postgres would put it.
I think there's some limitations to systemd that won't allow us to avoid conflicts with the PostgreSQL service files, but you should ask somebody who knows more than me. Maybe chat with the guys on Freenode IRC #gentoo-proxy-maint.
Created attachment 664582 [details]
Created attachment 664585 [details]
Created attachment 665038 [details]
Having both service and socket file, the socket would be created, but the pgbouncer daemon would not listen on the tcp port, so you could only connect via the socket. Having just the service file, the daemon listens to the host interface and tcp port that you have configured in pgbouncer.ini and the socket file is also created under /run/postgresql. This works fine for me.