Skip to content

Instantly share code, notes, and snippets.

@jrjsmrtn
Last active March 10, 2024 14:33
Show Gist options
  • Select an option

  • Save jrjsmrtn/3bc40007778d2002b8f520498f56fa54 to your computer and use it in GitHub Desktop.

Select an option

Save jrjsmrtn/3bc40007778d2002b8f520498f56fa54 to your computer and use it in GitHub Desktop.
Publish PostgreSQL Cluster service using avahi-publish
[Unit]
Description=Avahi Service Publisher for PostgreSQL Cluster %i
AssertPathExists=/etc/postgresql/%I/postgresql.conf
AssertFileIsExecutable=/usr/bin/avahi-publish-service
Wants=postgresql@%i.service
After=postgresql@%i.service
BindsTo=postgresql@%i.service
[Service]
Environment="N=%i"
Environment="T=_postgresql._tcp"
Environment="PUBLISH=/usr/bin/avahi-publish-service"
ExecCondition=/bin/bash -c \
'LA="$(pg_conftool ${N/-/ } show --short listen_addresses)"; [ "$LA" = "*" ]'
ExecStart=/bin/bash -c \
'P="$(pg_conftool ${N/-/ } show --short port)"; $PUBLISH "PostgreSQL Cluster %I @ %H" $T $P'
[Install]
WantedBy=postgresql@%i.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment