forked from deepweather/init_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo_init.sh
84 lines (67 loc) · 2.31 KB
/
mongo_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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# MongoDB installation
echo ##############################################
echo ##############################################
echo Starting Database Initialization
echo ##############################################
echo ##############################################
sleep 3
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 68818C72E52529D4
sudo echo "deb http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl enable mongod
sudo systemctl start mongod
sleep 5
# Initialize the DB with User and PW
echo -e "\n NOTE: IF YES, THE FILE WILL BE DELETED AFTER INITIALIZATION \n YOU WILL NOT HAVE ACCESS TO THE PASSWORD AFTER THIS STEP ANYMORE\n Initialize the database with the given credentials (mongo_init_script.js)?"
read -p "(y/n)" CONT
if [ "$CONT" = "y" ]; then
echo "Okay, starting Initialization with given credentials"
sleep 1
mongo < mongo_init_script.js
sudo systemctl daemon-reload
sudo service mongod restart
# Enable authentication
echo "
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
[Install]
WantedBy=multi-user.target" | sudo tee /lib/systemd/system/mongod.service
sudo systemctl daemon-reload
sudo service mongod restart
sudo rm mongo_init_script.js
else
echo "Okay... Database initialized without password protection."
sleep 1
fi
echo ##############################################
echo ##############################################
echo Database successfully initialized
echo ##############################################
echo ##############################################