2021-08-13 18:53:18 +08:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
#Allow to run outside of directory
|
|
|
|
cd $(dirname $0)
|
|
|
|
|
|
|
|
echo "Starting mongoDB"
|
|
|
|
|
|
|
|
#wait for mongo startup
|
|
|
|
MONGO_OK=0
|
|
|
|
|
|
|
|
while [ "$MONGO_OK" = "0" ]; do
|
2022-03-24 04:50:19 +08:00
|
|
|
MONGO_OK=$(ss -lan | grep 127.0.1.1 | grep 27017 &> /dev/null && echo 1 || echo 0)
|
2021-08-13 18:53:18 +08:00
|
|
|
sleep 1;
|
|
|
|
done;
|
|
|
|
|
|
|
|
echo "Mongo started";
|
|
|
|
|
|
|
|
echo "Initializing replicaset"
|
2023-04-28 20:31:40 +08:00
|
|
|
mongosh 127.0.1.1 --eval 'rs.initiate({ _id: "rs0", members: [ {_id: 0, host: "127.0.1.1"} ]})'
|
2021-08-13 18:53:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
echo "Waiting to become a master"
|
|
|
|
IS_MASTER="XX"
|
|
|
|
while [ "$IS_MASTER" \!= "true" ]; do
|
2023-04-28 20:31:40 +08:00
|
|
|
IS_MASTER=$(mongosh mongodb://127.0.1.1:27017/ --eval 'db.isMaster().ismaster' | tail -n 1)
|
2021-08-13 18:53:18 +08:00
|
|
|
sleep 0.5;
|
|
|
|
done;
|
|
|
|
|
|
|
|
echo "I'm the master!"
|
|
|
|
|
|
|
|
if [ -z $1 ]
|
|
|
|
then
|
|
|
|
INSTANCE_ID=1
|
|
|
|
else
|
|
|
|
INSTANCE_ID=$1
|
|
|
|
fi
|
|
|
|
|
|
|
|
PORT=$(echo "3999+$INSTANCE_ID" | bc)
|
|
|
|
|
|
|
|
echo "instanceId = $INSTANCE_ID and port = $PORT and role is backend (in backend file)"
|
|
|
|
|
|
|
|
export INSTANCE_ID=$INSTANCE_ID
|
|
|
|
export BBB_HTML5_ROLE=backend
|
2021-11-21 05:45:08 +08:00
|
|
|
# this might be already set by a systemd unit override in case this node is run
|
|
|
|
# behind a load balancer proxy node
|
|
|
|
if [[ -z $ROOT_URL ]] ; then
|
|
|
|
export ROOT_URL=http://127.0.0.1/html5client
|
|
|
|
fi
|
2021-08-13 18:53:18 +08:00
|
|
|
export MONGO_OPLOG_URL=mongodb://127.0.1.1/local
|
|
|
|
export MONGO_URL=mongodb://127.0.1.1/meteor
|
|
|
|
export NODE_ENV=production
|
|
|
|
export SERVER_WEBSOCKET_COMPRESSION=0
|
|
|
|
export BIND_IP=127.0.0.1
|
2022-07-13 00:25:37 +08:00
|
|
|
PORT=$PORT /usr/lib/bbb-html5/node/bin/node --max-old-space-size=2048 --max_semi_space_size=128 main.js NODEJS_BACKEND_INSTANCE_ID=$INSTANCE_ID
|
2021-08-13 18:53:18 +08:00
|
|
|
|