forked from cloudframeworks-springcloud/PiggyMetrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
33 lines (28 loc) · 817 Bytes
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
if test -z "$MONGODB_PASSWORD"; then
echo "MONGODB_PASSWORD not defined"
exit 1
fi
auth="-u user -p $MONGODB_PASSWORD"
# MONGODB USER CREATION
(
echo "setup mongodb auth"
create_user="if (!db.getUser('user')) { db.createUser({ user: 'user', pwd: '$MONGODB_PASSWORD', roles: [ {role:'readWrite', db:'piggymetrics'} ]}) }"
until mongo piggymetrics --eval "$create_user" || mongo piggymetrics $auth --eval "$create_user"; do sleep 5; done
killall mongod
sleep 1
killall -9 mongod
) &
# INIT DUMP EXECUTION
(
if test -n "$INIT_DUMP"; then
echo "execute dump file"
until mongo piggymetrics $auth $INIT_DUMP; do sleep 5; done
fi
) &
echo "start mongodb without auth"
chown -R mongodb /data/db
gosu mongodb mongod "$@"
echo "restarting with auth on"
sleep 5
exec gosu mongodb mongod --auth "$@"