Skip to content

Commit 2c4afd4

Browse files
author
Chad Young
committed
updated to version 3
Signed-off-by: Chad Young <[email protected]>
1 parent f2f471c commit 2c4afd4

File tree

1 file changed

+43
-28
lines changed

1 file changed

+43
-28
lines changed

linux_setup.sh

+43-28
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,31 @@
1414
# or implied. See the License for the specific language governing permissions and limitations under
1515
# the License.
1616
#
17+
# Version 3
1718
#################################################################################
1819

20+
clear
21+
echo "Shutting down any running MongoDB"
22+
# Verify all the processes of Mongo are stopped
23+
killpid=`sudo netstat -ntlp | grep mongod | awk '{print $7}' | sed 's/\/.*//'`
24+
#echo This is the pid that needs to die: $killpid
25+
sudo kill -9 $killpid
26+
sudo netstat -tulnp | grep mongod
27+
echo "Stopped MongoDB and pausing for 5 seconds"
28+
sleep 5s
29+
clear
30+
1931
# The user must define this path
2032
# Full path
2133
dbpath="/home/tester/edgex/db"
2234
# Short path - no"/db/"
2335
dirname="/home/tester/edgex"
2436

25-
26-
clear
2737
echo
2838
echo "This script will do the following:"
2939
echo "-- Ask you to supply a user name (consider \"<user>\" in /home/<user>) "
30-
echo "---- The username is needed to set folder ownership."
40+
echo "-- Ask you to supply a password"
41+
echo "---- The username and password are needed to set folder ownership."
3142
echo "---- This username will not be the same username used for mongodb."
3243
echo "---- The mongodb username will be supplied in the init_mongo.js file."
3344
echo "-- Create folders, if necessary, for the database."
@@ -58,8 +69,16 @@ echo
5869
read name
5970
echo
6071

72+
# Ask for a user name
73+
echo
74+
echo "What is the non-root user name who will own the folders where the database will be stored:"
75+
echo
76+
77+
# read the non-root user name password
78+
read passwd
79+
6180
# Confirm the user name
62-
echo "Is this what you meant to write: $name "
81+
echo "Is this what you meant to write: $name and $passwd "
6382
echo
6483
echo "Choose a number for your answer"
6584
select yn in "Yes" "No"; do
@@ -85,24 +104,11 @@ then
85104
echo "Folder created"
86105
echo
87106

88-
# DEBUG
89-
# echo "Who is the owner of the folder"
90-
# OWNS=$(stat -c '%U' $dbpath)
91-
# echo $OWNS
92-
# echo
93-
94107
echo "Changing the file owner to $name"
95108
sudo chown -R $name:$name $dirname
96109
echo
97110
echo "File owner changed"
98111
echo
99-
100-
# DEBUG
101-
# echo "Who is the owner of the folder"
102-
# OWNS=$(stat -c '%U' $dbpath)
103-
# echo $OWNS
104-
# echo
105-
106112
echo "Folder creation is complete, moving to next step"
107113
echo
108114

@@ -111,23 +117,32 @@ else
111117
echo
112118
fi
113119

120+
echo "Starting MongoDB with no auth"
114121
# Start the database creation (without --auth)
115-
sudo mongod --dbpath $dbpath
122+
gnome-terminal -x bash -c "sudo nohup mongod --dbpath $dbpath"
116123
echo
124+
echo "Sleeping for 30 seconds"
125+
sleep 30s
117126

118127
# Initialize the database for edgex
119-
sudo mongo < init_mongo.js
128+
gnome-terminal -x bash -c "sudo nohup mongo < init_mongo.js"
120129
echo
130+
echo "Initialize the database and sleep for 10 seconds"
131+
sleep 10s
121132

122133
# Shutdown the database
123-
sudo mongod --dbpath $dbpath --shutdown
124-
echo
134+
gnome-terminal -x bash -c "sudo nohup mongod --dbpath $dbpath --shutdown "
135+
#echo
136+
echo "Shutting down the database and sleep for 10 seconds"
137+
sleep 10s
125138

126-
# Verify all the processes of Mongo are stopped
127-
killpid=`sudo netstat -ntlp | grep mongod | awk '{print $7}' | sed 's/\/.*//'`
128-
#echo This is the pid that needs to die: $killpid
129-
sudo kill -9 $killpid
130-
sudo netstat -tulnp | grep mongod
139+
# Change the oener of the DB dir
140+
sudo chown -R mongodb:mongodb $dirname
141+
142+
# Make changes to the DB
143+
sudo sed -i 's/dbpath=\/var\/lib\/mongodb/dbpath=\/home\/tester\/edgex\/db/' /etc/mongodb.conf
144+
145+
# Turn on authentication
146+
sudo sed -i 's/\#auth/auth/' /etc/mongodb.conf
131147

132-
# Start the database (using --auth)
133-
sudo mongod --dbpath $dbpath --auth
148+
echo "Setup is complete - PLEASE REBOOT THE SYSTEM"

0 commit comments

Comments
 (0)