#!/usr/bin/env ssm

# PostgreSQL.
#
# postgres writes its own postmaster.pid file, so ssm doesn't create one
# — instead it waits for the pidfile to appear and treats any process
# exit as a failure. This is how services with their own pidfile should
# be written.

service_respawn = on-failure
service_command = /usr/lib/postgresql/17/bin/postgres -D /var/lib/postgresql/data
service_pidfile = /var/lib/postgresql/data/postmaster.pid
service_pidfile_timeout = 30

# Wait for the server to actually accept connections.
ready() {
    (exec 3<>/dev/tcp/127.0.0.1/5432) 2>/dev/null
}
