Skip to content

Commit

Permalink
feat: Add MODE ENV to limit services running in offline operation
Browse files Browse the repository at this point in the history
Setting -e MODE=offline boots a selective set of services, currently
limited to cardano-rosetta-server
  • Loading branch information
rhyslbw committed Aug 25, 2020
1 parent f77bd0b commit 013024a
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,38 @@ set -euo pipefail
DB_NAME=cexplorer
DATA_DIR_POSTGRES=/data/postgresql
DATA_DIR_NODE=/data/node-db
MODE=${MODE:-online}

if [ ! -d $DATA_DIR_POSTGRES ]; then
mv /var/lib/postgresql/12/main $DATA_DIR_POSTGRES
chmod 0700 $DATA_DIR_POSTGRES
fi
if [ ! -d $DATA_DIR_NODE ]; then
mkdir -p $DATA_DIR_NODE
fi
if [ "$MODE" == "offline" ]; then
echo 'Cardano Rosetta: Offline Mode';
exec gosu postgres pm2-runtime start ecosystem.config.js --env production --only 'cardano-rosetta-server'

chown postgres:postgres -R \
/config \
$DATA_DIR_POSTGRES \
$DATA_DIR_NODE \
/ipc
elif [ "$MODE" == "online" ]; then
echo 'Cardano Rosetta';
if [ ! -d $DATA_DIR_POSTGRES ]; then
mv /var/lib/postgresql/12/main $DATA_DIR_POSTGRES
chmod 0700 $DATA_DIR_POSTGRES
fi
if [ ! -d $DATA_DIR_NODE ]; then
mkdir -p $DATA_DIR_NODE
fi

/etc/init.d/postgresql stop 1> /dev/null && /etc/init.d/postgresql start 1> /dev/null
if [ ! "$( gosu postgres psql -tAc "SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" )" = '1' ]; then
echo 'Initializing PostgreSQL'
gosu postgres createdb -T template0 --owner="postgres" --encoding=UTF8 "${DB_NAME}"
fi
chown postgres:postgres -R \
/config \
$DATA_DIR_POSTGRES \
$DATA_DIR_NODE \
/ipc

/etc/init.d/postgresql stop 1> /dev/null
exec gosu postgres pm2-runtime start ecosystem.config.js --env production
/etc/init.d/postgresql stop 1> /dev/null && /etc/init.d/postgresql start 1> /dev/null
if [ ! "$( gosu postgres psql -tAc "SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" )" = '1' ]; then
echo 'Initializing PostgreSQL';
gosu postgres createdb -T template0 --owner="postgres" --encoding=UTF8 "${DB_NAME}"
fi

/etc/init.d/postgresql stop 1> /dev/null
exec gosu postgres pm2-runtime start ecosystem.config.js --env production

else
echo "Cardano Rosetta: Invalid MODE: ${MODE}. If set, must be offline or online";
exit 1
fi

0 comments on commit 013024a

Please sign in to comment.