-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdaemon.py
More file actions
executable file
·29 lines (22 loc) · 784 Bytes
/
daemon.py
File metadata and controls
executable file
·29 lines (22 loc) · 784 Bytes
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
#!/usr/bin/env python3
from http.server import BaseHTTPRequestHandler, HTTPServer
import json, subprocess, time
class RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
print("incoming http: ", self.path)
content_length = int(self.headers['Content-Length'])
content = self.rfile.read(content_length)
self.send_response(200)
json_content = json.loads(content)
subprocess.run(
["/root/update.sh", json_content['package_name'], json_content['version']],
stdout=subprocess.PIPE
)
httpd = HTTPServer(('', 80), RequestHandler)
print(time.asctime(), "Server Starts")
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print(time.asctime(), "Server Stops")