From c1cab90dbcd0f1fc743cb733114064f602766db6 Mon Sep 17 00:00:00 2001 From: Mel Date: Sat, 17 Feb 2024 02:09:26 +0100 Subject: Single container with a service and Postgres --- service.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 service.c (limited to 'service.c') diff --git a/service.c b/service.c new file mode 100644 index 0000000..edc6fd0 --- /dev/null +++ b/service.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +int main() { + PGconn *conn; + for (int i = 0; i < 100; i++) { + printf("trying to connect...\n"); + conn = PQconnectdb("host=localhost dbname=postgres user=postgres password="); + if (PQstatus(conn) == CONNECTION_OK) { + printf("connected :)\n"); + break; + } else { + fprintf(stderr, "connection failed: %s", PQerrorMessage(conn)); + sleep(2); + } + } + + PQfinish(conn); +} + -- cgit 1.4.1