Hey guys, I am new to CircleCI and the CircleCI community. Thank you for having me. I am trying to set up a run command that waits to see if postgresql is listening on its default port. I keep getting nc not found. I tried ‘which nc -z …’ that seemed to rid of the command not found error but it still fails when postgres is booted and waiting for connections. although the wait circle still spins next to ‘Container postgres…’ step.
Heres my config.yml:
version: 2.1
jobs:
build:
docker:
- image: node:12
- image: circleci/postgres:11-alpine-ram
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: testdb
working_directory: ~/repo
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: yarn install
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run:
name: Waiting for Postgres to be ready
command: |
for i in `seq 1 10`;
do
nc -z localhost 5432 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Postgres && exit 1
# run tests!
- run: yarn ci:test
my postgresql output:
The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /dev/shm/pgdata/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... sh: locale: not found
2020-07-29 22:58:44.456 UTC [49] WARNING: no usable system locales were found
ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /dev/shm/pgdata/data -l logfile start
waiting for server to start....2020-07-29 22:58:44.821 UTC [94] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-07-29 22:58:44.830 UTC [99] LOG: database system was shut down at 2020-07-29 22:58:44 UTC
2020-07-29 22:58:44.831 UTC [94] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down....2020-07-29 22:58:45.133 UTC [94] LOG: received fast shutdown request
2020-07-29 22:58:45.133 UTC [94] LOG: aborting any active transactions
2020-07-29 22:58:45.134 UTC [94] LOG: background worker "logical replication launcher" (PID 105) exited with exit code 1
2020-07-29 22:58:45.134 UTC [100] LOG: shutting down
2020-07-29 22:58:45.136 UTC [94] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2020-07-29 22:58:45.238 UTC [7] LOG: listening on IPv4 address "0.0.0.0", port 5432
2020-07-29 22:58:45.238 UTC [7] LOG: listening on IPv6 address "::", port 5432
2020-07-29 22:58:45.238 UTC [7] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-07-29 22:58:45.247 UTC [111] LOG: database system was shut down at 2020-07-29 22:58:45 UTC
2020-07-29 22:58:45.248 UTC [7] LOG: database system is ready to accept connections
And step Waiting for Postgres:
#!/bin/bash -eo pipefail
for i inseq 1 10
;
do
nc -z localhost 5432 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Postgres && exit 1
/bin/bash: line 2: nc: command not found
./bin/bash: line 2: nc: command not found
./bin/bash: line 2: nc: command not found
./bin/bash: line 2: nc: command not found
.
/bin/bash: line 2: nc: command not found
.
/bin/bash: line 2: nc: command not found
.
/bin/bash: line 2: nc: command not found
.
/bin/bash: line 2: nc: command not found
.
/bin/bash: line 2: nc: command not found
.
/bin/bash: line 2: nc: command not found
.
Failed waiting for PostgresExited with code exit status 1
CircleCI received exit code 1
Any ideas where I am off on this?