I have a script trying to restart postgresql docker container:
DOCKER_CONTAINER_NAME="timescaledb"
docker restart -t 1 $DOCKER_CONTAINER_NAME
timeout 9000000s bash -c "until docker exec $DOCKER_CONTAINER_NAME pg_isready ; do sleep 1 ; done"
However, this line (with any -t number)
docker restart -t 1 $DOCKER_CONTAINER_NAME
Takes extremely large amount of time to shutdown postgresql. Generally I have to go to the screen container postgresql (I used screens to manage my orchestration). and press Ctrl-C to force it shutdown and enter
docker run -ti --user 1000:1000 -p 5432:5432 --name timescaledb --volume=/home/ubuntu/pgdata3:/home/postgresql/pgdata --rm -e POSTGRES_PASSWORD=dashdhwqehqwhhkshajdkh -e PGDATA=/home/postgresql/pgdata timescale/timescaledb-ha:pg13-latest;
Is it possible to complete this process of force restart without me entering into the "screen" and press Ctrl-C and restart manually?
A related question is posted here:
postgresql docker ctrl C seems to be better than docker kill
I wanted to find a way to mimic Ctrl-C shut down of postgresql.
2
Answers
ok, it seems this is sequence of command served my purpose. Thanks, everyone!
You can use
docker-compose up
to start your docker and addrestart: always
to restart the docker when it shuts down for any reason.Example of docker-compose.yml
EDIT. Replying to your comment, maybe you could prepare a bash script, forcing the docker to restart every x minutes:
Or, probably better, you could program a task in crontab:
crontab -e
I’m assuming you’re working with Linux