gvialetto / pgsql-consul

Tiny application to register a running postgresql server on consul for discovery

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pgsql-consul

This application monitor a PostgreSQL server status and updates consul as/if needed, assigning tags application can use to connect to a master/slave server without the need of a proxy, completely independent from the mechanism used to managed the actual failover/switchover for the cluster.

It will not deregister the service created, ever, since doing that would be an availability risk.

Building

Building requires dep to be installed and in $PATH.

$ dep ensure
$ go build

Alternatively, a Dockerfile is provided to build a scratch image with the binary (requires docker CE 17.06+, since I'm using multi-stage builds).

$ docker build -t pgsql-consul:latest .

Running

% pgsql-consul --help
Usage of pgsql-consul:
      --check-interval duration   Interval between checks to PostgreSQL (default 10s)
      --cluster string            Name of the PostgreSQL cluster (default "main")
      --consul string             Consul API endpoint (default "127.0.0.1:8500")
      --consul-resync duration    Frequency at which consul is resynchronized if no updates are detected (default 30s)
      --db string                 PostgreSQL database connection string (default "user=postgres dbname=postgres")
      --debug                     Enable verbose logging

Todo

  • add more command line parameters (service name, consul check interval...)
  • get command line parameters from environment variables

About

Tiny application to register a running postgresql server on consul for discovery


Languages

Language:Go 100.0%