-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathstartdb.sh
executable file
·255 lines (216 loc) · 6.41 KB
/
startdb.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/bash
which=$1
FN=$2
DBFOLDER=${3-`pwd`/databases}
sudo bash -c "
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo 1 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
"
ulimit -n 60000
WATCHER_PID=/tmp/watcher.pid
# comm cputime etimes rss pcpu
export AWKCMD='{a[$1] = $1; b[$1] = $2; c[$1] = $3; d[$1] = $4; e[$1] = $5} END {for (i in a) printf "%s; %s; %s; %0.1f; %0.1f\n", a[i], b[i], c[i], d[i], e[i]}'
killPIDFile() {
PID_FN=$1
if test -f ${PID_FN}; then
PID=`cat ${PID_FN}`
kill ${PID} 2> /dev/null
count=0
while test -d /proc/${PID}; do
echo "."
sleep 1
count=$((${count} + 1))
if test "${count}" -gt 60; then
kill -9 ${PID}
fi
done
rm -f ${PID_FN}
fi
}
stop_ArangoDB() {
killPIDFile "/tmp/arangodb.pid"
}
start_ArangoDB_mmfiles() {
ADB=${DBFOLDER}/arangodb
cd ${ADB}
${ADB}/usr/sbin/arangod \
${ADB}/pokec-mmfiles \
--pid-file /tmp/arangodb.pid \
--log.file /var/tmp/arangodb.log \
--temp.path `pwd` \
--working-directory `pwd` \
--daemon \
--configuration ${ADB}/etc/arangodb3/arangod.conf \
--server.authentication false \
--javascript.app-path ${ADB}/apps \
--javascript.startup-directory ${ADB}/usr/share/arangodb3/js \
--server.storage-engine mmfiles || (echo "failed" && exit 1)
while ! curl http://127.0.0.1:8529/_api/version -fs ; do sleep 1 ; done
nohup bash -c "
while true; do
sleep 1
echo -n \"`date`; \"
ps -p `cat /tmp/arangodb.pid` -o 'comm cputime etimes rss pcpu' --no-headers | \
awk '${AWKCMD}'
done > $FN 2>&1" > /dev/null 2>&1 &
echo "$!" > "${WATCHER_PID}"
}
start_ArangoDB() {
ADB=${DBFOLDER}/arangodb
cd ${ADB}
${ADB}/usr/sbin/arangod \
${ADB}/pokec-rocksdb \
--pid-file /tmp/arangodb.pid \
--log.file /var/tmp/arangodb.log \
--temp.path `pwd` \
--working-directory `pwd` \
--daemon \
--wal.sync-interval 1000 \
--configuration ${ADB}/etc/arangodb3/arangod.conf \
--server.authentication false \
--javascript.app-path ${ADB}/apps \
--javascript.startup-directory ${ADB}/usr/share/arangodb3/js \
--server.storage-engine rocksdb || (echo "failed" && exit 1)
while ! curl http://127.0.0.1:8529/_api/version -fs ; do sleep 1 ; done
nohup bash -c "
while true; do
sleep 1
echo -n \"`date`; \"
ps -p `cat /tmp/arangodb.pid` -o 'comm cputime etimes rss pcpu' --no-headers | \
awk '${AWKCMD}'
done > $FN 2>&1" > /dev/null 2>&1 &
echo "$!" > "${WATCHER_PID}"
}
stop_MongoDB() {
killPIDFile "/var/tmp/mongodb.pid"
}
start_MongoDB() {
numactl --interleave=all \
${DBFOLDER}/mongodb/bin/mongod \
--bind_ip 0.0.0.0 \
--fork \
--logpath /var/tmp/mongodb.log \
--pidfilepath /var/tmp/mongodb.pid \
--storageEngine wiredTiger \
--dbpath ${DBFOLDER}/mongodb/pokec
nohup bash -c "
while true; do
sleep 1
echo -n \"`date`; \"
ps -C mongod -o 'comm cputime etimes rss pcpu' --no-headers | \
awk '${AWKCMD}'
done > $FN 2>&1 " > /dev/null 2>&1 &
echo "$!" > "${WATCHER_PID}"
}
stop_OrientDB() {
cd ${DBFOLDER}/orientdb
./bin/shutdown.sh > /dev/null 2>&1
}
start_OrientDB() {
cd ${DBFOLDER}/orientdb
./bin/server.sh -Xmx28G -Dstorage.wal.maxSize=28000 > /var/tmp/orientdb.log 2>&1 &
sleep 3
ORIENTDB_PID=`pidof java`
nohup bash -c "
while true; do
sleep 1
echo -n \"`date`; \"
ps -p $ORIENTDB_PID -o 'comm cputime etimes rss pcpu' --no-headers | \
awk '${AWKCMD}'
done > $FN 2>&1 " > /dev/null 2>&1 &
echo "$!" > "${WATCHER_PID}"
}
stop_Neo4j() {
${DBFOLDER}/neo4j/bin/neo4j stop
}
start_Neo4j() {
cd ${DBFOLDER}/neo4j
./bin/neo4j start
NEO4J_PID=`pidof java`
nohup bash -c "
while true; do
sleep 1
echo -n \"`date`; \"
ps -p $NEO4J_PID -o 'comm cputime etimes rss pcpu' --no-headers | \
awk '${AWKCMD}'
done > $FN 2>&1 " > /dev/null 2>&1 &
echo "$!" > "${WATCHER_PID}"
sleep 60
}
stop_Postgresql() {
sudo -u postgres ${DBFOLDER}/postgresql/bin/pg_ctl stop -D ${DBFOLDER}/postgresql/pokec_json
sudo -u postgres ${DBFOLDER}/postgresql/bin/pg_ctl stop -D ${DBFOLDER}/postgresql/pokec_tabular
sudo service collectd stop
}
start_Postgresql_tabular() {
sudo service collectd start
sudo -u postgres ${DBFOLDER}/postgresql/bin/pg_ctl start \
-D ${DBFOLDER}/postgresql/pokec_tabular/ > /var/tmp/postgresql_tabular.log 2>&1 &
nohup bash -c "
while true; do
sleep 1
echo -n \"`date`; \"
ps -C postgres -o 'comm cputime etimes rss pcpu' --no-headers | \
awk '${AWKCMD}'
done > $FN 2>&1 " > /dev/null 2>&1 &
echo "$!" > "${WATCHER_PID}"
}
start_Postgresql_jsonb() {
sudo service collectd start
sudo -u postgres ${DBFOLDER}/postgresql/bin/pg_ctl start \
-D ${DBFOLDER}/postgresql/pokec_json/ > /var/tmp/postgresql_json.log 2>&1 &
nohup bash -c "
while true; do
sleep 1
echo -n \"`date`; \"
ps -C postgres -o 'comm cputime etimes rss pcpu' --no-headers | \
awk '${AWKCMD}'
done > $FN 2>&1 " > /dev/null 2>&1 &
echo "$!" > "${WATCHER_PID}"
}
echo "================================================================================"
echo "* stopping databases"
echo "================================================================================"
stop_ArangoDB
stop_MongoDB
stop_OrientDB
stop_Neo4j
stop_Postgresql
killPIDFile "${WATCHER_PID}"
echo "================================================================================"
echo "* starting: $which $version"
echo "================================================================================"
case "$which" in
arangodb_mmfiles)
start_ArangoDB_mmfiles
;;
arangodb)
start_ArangoDB
;;
mongodb)
start_MongoDB
;;
rethinkdb)
start_RethinkDB
;;
orientdb)
start_OrientDB
;;
neo4j)
start_Neo4j
;;
postgresql_tabular)
start_Postgresql_tabular
;;
postgresql_jsonb)
start_Postgresql_jsonb
;;
*)
echo "unsupported database: [$which]"
echo "I know: ArangoDB, ArangoDB_mmfiles, MongoDB, OrientDB, Neo4j, Postgresql_tabular, Postgresql_jsonb"
exit 1
;;
esac