diff --git a/Dockerfile b/Dockerfile index b2ccbc737166eccf961f85b3d8b618ca7e59e77a..e0c7f5b3807550e2ac66443f57424fa0781d0dcd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,8 +50,10 @@ WORKDIR /app ADD scripts/entrypoint.sh /usr/local/bin/entrypoint.sh ADD scripts/hivesync.sh /usr/local/bin/hivesync.sh +ADD scripts/hivesynccontinue.sh /usr/local/bin/hivesynccontinue.sh RUN chmod +x /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/hivesync.sh +RUN chmod +x /usr/local/bin/hivesynccontinue.sh RUN \ pip3 install . && \ diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index c5793c55acd3ec13afd70991a8a515aeb51dda24..95cfa3e12bed24a6a4705d9cca095b15588e3b3c 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -5,7 +5,9 @@ # a non-micro-fork was encountered. Hive has a startup routine which attempts # to recover automatically, so database should be kept intact between restarts. -# eb need to set: RUN_IN_EB, S3_BUCKET, SYNC_TO_S3 (boolean) if a syncer +# eb with self-contained postgres need to set: RUN_IN_EB, S3_BUCKET, and SYNC_TO_S3 (boolean) if a syncer +# eb with external postgres do not require RUN_IN_EB, S3_BUCKET, or SYNC_TO_S3 +# with external postgres need to set: SYNC_SERVICE if a syncer # hive expects: DATABASE_URL, LOG_LEVEL, STEEMD_URL, JUSSI_URL # default DATABASE_URL should be postgresql://postgres:postgres@localhost:5432/postgres @@ -65,24 +67,39 @@ if [[ "$RUN_IN_EB" ]]; then service postgresql restart fi -fi - -cd $APP_ROOT - -# startup hive -echo hivemind: starting sync -exec "${POPULATE_CMD}" sync 2>&1& + cd $APP_ROOT + # startup hive + echo hivemind: starting sync + exec "${POPULATE_CMD}" sync 2>&1& -echo hivemind: starting server -if [[ ! "$SYNC_TO_S3" ]]; then - exec "${POPULATE_CMD}" server + echo hivemind: starting server + if [[ ! "$SYNC_TO_S3" ]]; then + exec "${POPULATE_CMD}" server + else + exec "${POPULATE_CMD}" server --log-level=warning 2>&1& + mkdir -p /etc/service/hivesync + cp /usr/local/bin/hivesync.sh /etc/service/hivesync/run + chmod +x /etc/service/hivesync/run + echo hivemind: starting hivesync service + runsv /etc/service/hivesync + fi else - exec "${POPULATE_CMD}" server --log-level=warning 2>&1& + # start hive with an external postgres + cd $APP_ROOT + if [[ "$SYNC_SERVICE" ]]; then + echo hivemind: starting sync + exec "${POPULATE_CMD}" sync 2>&1& + echo hivemind: starting server + exec "${POPULATE_CMD}" server 2>&1& + # make sure hive sync and server continually run mkdir -p /etc/service/hivesync - cp /usr/local/bin/hivesync.sh /etc/service/hivesync/run + cp /usr/local/bin/hivesynccontinue.sh /etc/service/hivesync/run chmod +x /etc/service/hivesync/run - echo hivemind: starting hivesync service runsv /etc/service/hivesync + else + echo hivemind: starting server + exec "${POPULATE_CMD}" server + fi fi echo hivemind: application has stopped, see log for errors diff --git a/scripts/hivesynccontinue.sh b/scripts/hivesynccontinue.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e1f68dca18d98ee4ea93304d21071b4bd8cc47f --- /dev/null +++ b/scripts/hivesynccontinue.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +POPULATE_CMD="$(which hive)" + +HIVESYNC_PID=`pgrep -f 'hive sync'` + +if [[ ! $? -eq 0 ]]; then + echo NOTIFYALERT! hivemindsync quit unexpectedly, restarting hive sync... + cd $APP_ROOT + exec "${POPULATE_CMD}" sync 2>&1& +fi + +sleep 30 + +HIVESERVER_PID=`pgrep -f 'hive server'` + +if [[ ! $? -eq 0 ]]; then + echo NOTIFYALERT! hivemindserver quit unexpectedly, restarting hive server... + cd $APP_ROOT + exec "${POPULATE_CMD}" server 2>&1& +fi + +# prevent flapping +sleep 120 \ No newline at end of file