2019-06-14 02:12:56 +00:00
|
|
|
#!/bin/sh
|
2019-10-02 14:10:37 +00:00
|
|
|
# Runs the db migrations and starts the super node services
|
2019-06-10 17:17:14 +00:00
|
|
|
|
|
|
|
# Exit if the variable tests fail
|
|
|
|
set -e
|
2020-03-08 16:49:50 +00:00
|
|
|
set +x
|
2019-06-10 17:17:14 +00:00
|
|
|
|
|
|
|
# Check the database variables are set
|
2020-03-08 16:49:50 +00:00
|
|
|
test $DATABASE_HOSTNAME
|
|
|
|
test $DATABASE_NAME
|
|
|
|
test $DATABASE_PORT
|
|
|
|
test $DATABASE_USER
|
|
|
|
test $DATABASE_PASSWORD
|
2020-01-27 20:13:54 +00:00
|
|
|
test $IPFS_INIT
|
2020-03-22 17:14:43 +00:00
|
|
|
test $IPFS_PATH
|
|
|
|
test $VDB_COMMAND
|
2019-06-14 02:12:56 +00:00
|
|
|
set +e
|
2019-06-10 17:17:14 +00:00
|
|
|
|
|
|
|
# Export our database variables so that the IPFS Postgres plugin can use them
|
2020-03-08 16:49:50 +00:00
|
|
|
export IPFS_PGHOST=$DATABASE_HOSTNAME
|
|
|
|
export IPFS_PGUSER=$DATABASE_USER
|
|
|
|
export IPFS_PGDATABASE=$DATABASE_NAME
|
|
|
|
export IPFS_PGPORT=$DATABASE_PORT
|
|
|
|
export IPFS_PGPASSWORD=$DATABASE_PASSWORD
|
2019-06-10 17:17:14 +00:00
|
|
|
|
2020-03-22 17:14:43 +00:00
|
|
|
# Construct the connection string for postgres
|
|
|
|
VDB_PG_CONNECT=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME:$DATABASE_PORT/$DATABASE_NAME?sslmode=disable
|
|
|
|
|
|
|
|
# Run the DB migrations
|
|
|
|
echo "Connecting with: $VDB_PG_CONNECT"
|
|
|
|
echo "Running database migrations"
|
|
|
|
./goose -dir migrations/vulcanizedb postgres "$VDB_PG_CONNECT" up
|
|
|
|
|
|
|
|
|
|
|
|
# If the db migrations ran without err
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
# and IPFS_INIT is true
|
|
|
|
if [[ "$IPFS_INIT" = true ]] ; then
|
|
|
|
# initialize PG-IPFS
|
|
|
|
echo "Initializing Postgres-IPFS profile"
|
|
|
|
./ipfs init --profile=postgresds
|
|
|
|
else
|
|
|
|
echo "IPFS profile already initialized, skipping initialization"
|
|
|
|
fi
|
2019-06-10 17:17:14 +00:00
|
|
|
else
|
2020-03-22 17:14:43 +00:00
|
|
|
echo "Could not run migrations. Are the database details correct?"
|
|
|
|
exit 1
|
2019-06-10 17:17:14 +00:00
|
|
|
fi
|
2019-06-14 02:12:56 +00:00
|
|
|
|
|
|
|
# If IPFS initialization was successful
|
2020-01-27 20:13:54 +00:00
|
|
|
if [[ $? -eq 0 ]]; then
|
2020-03-02 22:30:46 +00:00
|
|
|
echo "Beginning the vulcanizedb super node process"
|
2020-03-22 17:14:43 +00:00
|
|
|
./vulcanizedb ${VDB_COMMAND} --config=config.toml 2>&1 | tee -a vulcanizedb.log &
|
2019-06-14 02:12:56 +00:00
|
|
|
else
|
2020-03-02 22:30:46 +00:00
|
|
|
echo "Could not initialize IPFS."
|
2020-03-18 17:21:29 +00:00
|
|
|
exit 1
|
2019-06-14 02:12:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If Vulcanizedb startup was successful
|
|
|
|
if [ $? -eq 0 ]; then
|
2020-03-18 13:48:25 +00:00
|
|
|
echo "Super node successfully booted"
|
2019-06-14 02:12:56 +00:00
|
|
|
else
|
2020-03-18 13:48:25 +00:00
|
|
|
echo "Could not start vulcanizedb super node process. Is the config file correct?"
|
2020-03-18 17:21:29 +00:00
|
|
|
exit 1
|
2019-06-14 02:12:56 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-22 17:14:43 +00:00
|
|
|
tail -f vulcanizedb.log
|