forked from ttimasdf/docker-cve-search
-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-entrypoint.sh
executable file
·132 lines (118 loc) · 2.59 KB
/
docker-entrypoint.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
#!/bin/bash
# Small script to control container behavior.
cd $CVE_BASE
function show_help {
printf "Used to launch CVE database.\n \
\t-h|--help: this help menu\n\
\t-i|--initialize: initialize database for the first time\n\
\t-u|--update: update database\n\
\t-r|--repopulate: repopulate database\n"
}
function log {
echo "==================== $1 ===================="
}
function update_repo {
log "Updating repo"
curl -sL https://github.com/cve-search/cve-search/archive/master.tar.gz | \
tar xz -C ${CVE_BASE} --strip-components 1 --keep-newer-files
pip3 install -r requirements.txt
}
function start_mongodb {
if ! pidof -x "mongod" >/dev/null; then
log "Starting mongodb server"
if [ -d /persist ]; then
log "Recovering persisted data"
shopt -s dotglob
mv /persist/db/* /data/db/
mv /persist/configdb/* /data/configdb/
rm -R /persist
fi
mongo-entrypoint.sh mongod --logpath /var/log/mongodb/mongod.log &
sleep 5
fi
}
function stop_mongodb {
if pidof -x "mongod" >/dev/null; then
log "Restarting mongodb server"
kill $(pidof -x "mongod")
sleep 5
fi
}
function start_redis {
if ! pidof -x "redis-server" >/dev/null; then
log "Starting redis server"
/etc/init.d/redis-server start
sleep 2
fi
}
function stop_redis {
if pidof -x "redis-server" >/dev/null; then
log "Restarting redis server"
/etc/init.d/redis-server stop
sleep 5
fi
}
function populate_database {
log "Populating database"
./sbin/db_mgmt.py -p
log "db_mgmt_cpe_dictionary"
./sbin/db_mgmt_cpe_dictionary.py
log "db_updater -c"
./sbin/db_updater.py -c
log "db_mgmt_ref"
./sbin/db_mgmt_ref.py
}
function update_database {
log "Updating database"
./sbin/db_updater.py -v
}
function repopulate_database {
log "REPOPULATING database"
./sbin/db_updater.py -v -f
}
# Validate number of arguments
if [ $# -eq 0 ]
then
show_help
exit 0
fi
# Parse arguments
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
show_help
;;
-i|--initialize)
update_repo
start_mongodb
start_redis
populate_database
stop_mongodb
stop_redis
;;
-u|--update)
update_repo
start_mongodb
start_redis
update_database
;;
-r|--repopulate)
update_repo
start_mongodb
start_redis
repopulate_database
;;
-w|--web)
start_mongodb
start_redis
log "Starting web app"
python3 ./web/index.py
;;
*)
show_help
;;
esac
shift
done