在继续执行nosetests之前,等待postgres在ENTRYPOINT内完全启动的最佳方法是什么?
现在我把我的机器上的启动时间定在50秒左右.所以我只是睡了60秒.这感觉不太好,因为在另一台机器上运行时这可能不起作用.
ENTRYPOINT \ runuser -l postgres -c '/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf & ' && \ sleep 60 && \ nosetests --verbose --cover-erase --with-coverage --cover-package=stalker
这是启动postgres的输出:
2017-02-13 13:46:49.541 UTC [9] LOG: database system was interrupted; last kNown up at 2017-02-13 12:53:23 UTC 2017-02-13 13:47:37.951 UTC [9] LOG: database system was not properly shut down; automatic recovery in progress 2017-02-13 13:47:37.994 UTC [9] LOG: redo starts at 0/1783EA0 2017-02-13 13:47:37.995 UTC [9] LOG: record with zero length at 0/17841E8 2017-02-13 13:47:37.995 UTC [9] LOG: redo done at 0/17841B8 2017-02-13 13:47:37.995 UTC [9] LOG: last completed transaction was at log time 2017-02-13 12:53:23.731984+00 2017-02-13 13:47:38.384 UTC [9] LOG: Multixact member wraparound protections are Now enabled 2017-02-13 13:47:38.387 UTC [7] LOG: database system is ready to accept connections 2017-02-13 13:47:38.387 UTC [13] LOG: autovacuum launcher started
感谢@zeppelin建议pg_isready.我最终使用了这个:
#!/bin/bash # wait-for-postgres.sh set -e cmd="$@" timer="5" until runuser -l postgres -c 'pg_isready' 2>/dev/null; do >&2 echo "Postgres is unavailable - sleeping for $timer seconds" sleep $timer done >&2 echo "Postgres is up - executing command" exec $cmd
我在我的ENTRYPOINT中使用它:
ENTRYPOINT \ # Start Postgresql runuser -l postgres -c '/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf & ' && \ # Exectute tests when db is up ./wait-for-postgres.sh nosetests --verbose --cover-erase --with-coverage --cover-package=stalker
原文地址:https://www.jb51.cc/bash/385036.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。