-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongodb.sh
51 lines (36 loc) · 919 Bytes
/
mongodb.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
#!/bin/bash
USERID=$(id -u)
DATE=$(date +%F)
LOG_FILE_DIRECTORY=/tmp
SCRIPT_NAME=$0
LOGFILE=$LOG_FILE_DIRECTORY/$0-$DATE.log
R="\e[31m"
N="\e[0m"
Y="\e[33m"
G="\e[32m"
if [ $USERID -ne 0 ];
then
echo -e "$R ERROR:: Please run this script with root access $N"
exit 1
fi
VALIDATE(){
if [ $1 -ne 0 ]
then
echo -e "$2 ... $R FAILURE $N"
exit 1
else
echo -e "$2 ... $G SUCCESS $N"
fi
}
cp mongo.repo /etc/yum.repos.d/mongo.repo &>>$LOGFILE
VALIDATE $? "copied mongo.repo into yum.repos.d"
yum install mongodb-org -y &>>$LOGFILE
VALIDATE $? "Installation of MongoDB"
systemctl enable mongod &>>$LOGFILE
VALIDATE $? "Enabling MongoDB"
systemctl start mongod &>>$LOGFILE
VALIDATE $? "Starting MongoDB"
sed -i 's/127.0.0.1/0.0.0.0/' /etc/mongod.conf &>>$LOGFILE
VALIDATE $? "edited mongoDB conf"
systemctl restart mongod &>>$LOGFILE
VALIDATE $? "restarting mongoDB"