Created
July 10, 2023 11:29
-
-
Save syuu1228/7bd857a49eea54071a0e4dcb06ddf260 to your computer and use it in GitHub Desktop.
coredumptest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import signal | |
import socket | |
import time | |
from selectors import DefaultSelector, EVENT_READ | |
from http.server import HTTPServer, SimpleHTTPRequestHandler | |
interrupt_read, interrupt_write = socket.socketpair() | |
def handler(signum, frame): | |
print('Signal handler called with signal', signum) | |
interrupt_write.send(b'\0') | |
signal.signal(signal.SIGTERM, handler) | |
def serve_forever(httpd): | |
sel = DefaultSelector() | |
sel.register(interrupt_read, EVENT_READ) | |
sel.register(httpd, EVENT_READ) | |
while True: | |
for key, _ in sel.select(): | |
if key.fileobj == interrupt_read: | |
interrupt_read.recv(1) | |
return | |
if key.fileobj == httpd: | |
httpd.handle_request() | |
print("Serving on port 8000") | |
httpd = HTTPServer(('', 8000), SimpleHTTPRequestHandler) | |
serve_forever(httpd) | |
time.sleep(100) | |
os.kill(os.getpid(), signal.SIGSEGV) | |
print("Shutdown...") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=coredumptest | |
[Service] | |
ExecStart=/usr/local/bin/coredumptest.py | |
TimeoutStopSec=900 | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment