14
14
# or implied. See the License for the specific language governing permissions and limitations under
15
15
# the License.
16
16
#
17
+ # Version 3
17
18
# ################################################################################
18
19
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
+
19
31
# The user must define this path
20
32
# Full path
21
33
dbpath=" /home/tester/edgex/db"
22
34
# Short path - no"/db/"
23
35
dirname=" /home/tester/edgex"
24
36
25
-
26
- clear
27
37
echo
28
38
echo " This script will do the following:"
29
39
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."
31
42
echo " ---- This username will not be the same username used for mongodb."
32
43
echo " ---- The mongodb username will be supplied in the init_mongo.js file."
33
44
echo " -- Create folders, if necessary, for the database."
58
69
read name
59
70
echo
60
71
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
+
61
80
# 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 "
63
82
echo
64
83
echo " Choose a number for your answer"
65
84
select yn in " Yes" " No" ; do
@@ -85,24 +104,11 @@ then
85
104
echo " Folder created"
86
105
echo
87
106
88
- # DEBUG
89
- # echo "Who is the owner of the folder"
90
- # OWNS=$(stat -c '%U' $dbpath)
91
- # echo $OWNS
92
- # echo
93
-
94
107
echo " Changing the file owner to $name "
95
108
sudo chown -R $name :$name $dirname
96
109
echo
97
110
echo " File owner changed"
98
111
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
-
106
112
echo " Folder creation is complete, moving to next step"
107
113
echo
108
114
@@ -111,23 +117,32 @@ else
111
117
echo
112
118
fi
113
119
120
+ echo " Starting MongoDB with no auth"
114
121
# Start the database creation (without --auth)
115
- sudo mongod --dbpath $dbpath
122
+ gnome-terminal -x bash -c " sudo nohup mongod --dbpath $dbpath "
116
123
echo
124
+ echo " Sleeping for 30 seconds"
125
+ sleep 30s
117
126
118
127
# Initialize the database for edgex
119
- sudo mongo < init_mongo.js
128
+ gnome-terminal -x bash -c " sudo nohup mongo < init_mongo.js"
120
129
echo
130
+ echo " Initialize the database and sleep for 10 seconds"
131
+ sleep 10s
121
132
122
133
# 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
125
138
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
131
147
132
- # Start the database (using --auth)
133
- sudo mongod --dbpath $dbpath --auth
148
+ echo " Setup is complete - PLEASE REBOOT THE SYSTEM"
0 commit comments