-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdatabase.sh
executable file
·49 lines (32 loc) · 1.4 KB
/
database.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
if [ "$1" == "start" ]; then
# Start database in Docker
docker stop @@NAME_db
docker rm @@NAME_db
docker run --name @@NAME_db -d --restart always -v @@DATABASE_PATH:/data/db -v @@CERTS_PATH:/data/certs -p @@DATABASE_REPL_NODES_PORT:27017 mongo --auth --keyFile /data/certs/@@DATABASE_REPL_KEY --replSet @@DATABASE_REPL_NAME @@MONGO_CONFIG
elif [ "$1" == "stop" ]; then
# Stop database in Docker
docker stop @@NAME_db
docker rm @@NAME_db
elif [ "$1" == "reset" ]; then
# Clean and reset database directory
docker stop @@NAME_db
docker rm @@NAME_db
rm -r @@DATABASE_PATH
docker run --name @@NAME_db -d --restart always -v @@DATABASE_PATH:/data/db -v @@CERTS_PATH:/data/certs -p @@DATABASE_REPL_NODES_PORT:27017 mongo --auth --keyFile /data/certs/@@DATABASE_REPL_KEY --replSet @@DATABASE_REPL_NAME
sleep 1
docker exec -i @@NAME_db mongo < ./mongodb.js
sleep 0.5
docker stop @@NAME_db
docker rm @@NAME_db
elif [ "$1" == "restart" ]; then
# Stop database in Docker
docker stop @@NAME_db
docker rm @@NAME_db
# Start database in Docker
docker stop @@NAME_db
docker rm @@NAME_db
docker run --name @@NAME_db -d --restart always -v @@DATABASE_PATH:/data/db -v @@CERTS_PATH:/data/certs -p @@DATABASE_REPL_NODES_PORT:27017 mongo --auth --keyFile /data/certs/@@DATABASE_REPL_KEY --replSet @@DATABASE_REPL_NAME @@MONGO_CONFIG
else
echo "Commands are start, stop, restart and reset"
fi