-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.sh
More file actions
51 lines (41 loc) · 1.28 KB
/
mongodb.sh
File metadata and controls
51 lines (41 loc) · 1.28 KB
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)
R="\e[31m"
G="\e[32m"
Y="\e[33m"
N="\e[0m"
LOGS_FOLDER="/var/log/roboshop-logs"
SCRIPT_NAME=$(echo $0 | cut -d "." -f1)
LOG_FILE="$LOGS_FOLDER/$SCRIPT_NAME.log"
mkdir -p $LOGS_FOLDER
echo "Script started executing at: $(date)" | tee -a $LOG_FILE
# check the user has root priveleges or not
if [ $USERID -ne 0 ]
then
echo -e "$R ERROR:: Please run this script with root access $N" | tee -a $LOG_FILE
exit 1 #give other than 0 upto 127
else
echo "You are running with root access" | tee -a $LOG_FILE
fi
# validate functions takes input as exit status, what command they tried to install
VALIDATE(){
if [ $1 -eq 0 ]
then
echo -e "$2 is ... $G SUCCESS $N" | tee -a $LOG_FILE
else
echo -e "$2 is ... $R FAILURE $N" | tee -a $LOG_FILE
exit 1
fi
}
cp mongo.repo /etc/yum.repos.d/mongodb.repo
VALIDATE $? "Copying MongoDB repo"
dnf install mongodb-org -y &>>$LOG_FILE
VALIDATE $? "Installing mongodb server"
systemctl enable mongod &>>$LOG_FILE
VALIDATE $? "Enabling MongoDB"
systemctl start mongod &>>$LOG_FILE
VALIDATE $? "Starting MongoDB"
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mongod.conf
VALIDATE $? "Editing mongodb conf file for remote connections"
systemctl restart mongod &>>$LOG_FILE
VALIDATE $? "restarting mongodb"