-
Notifications
You must be signed in to change notification settings - Fork 10
/
mirror.py
40 lines (32 loc) · 971 Bytes
/
mirror.py
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
from cvdupdate.cvdupdate import CVDUpdate
import threading
import logging
import os
import time
import http.server
import socketserver
# Update the mirror every N hours
EVERY_N_HOURS = 4
def update():
m = CVDUpdate(config='', verbose=False)
errors = m.db_update()
if errors > 0:
# TODO: handle errors
pass
def keep_updating():
while True:
logging.info("Performing update!")
update()
time.sleep(60 * 60 * EVERY_N_HOURS)
if __name__ == "__main__":
logging.info("Performing initial update")
t = threading.Thread(target=keep_updating)
t.start()
logging.info("Starting web server")
try:
os.chdir('/clamav')
with socketserver.TCPServer(("", 80), http.server.SimpleHTTPRequestHandler) as httpd:
logging.info("Now serving at port TCP 80")
httpd.serve_forever()
except Exception as e:
logging.error("Failed bringing up the web server. %s" % e)