Skip to content
Snippets Groups Projects
Unverified Commit c88c1e9d authored by Peeter Aleksander Randla's avatar Peeter Aleksander Randla Committed by GitHub
Browse files

Install a SIGTERM handler in addition to SIGINT (#1246)

This allows cleanly terminating CMS by sending it SIGTERM, which is what
e.g. Docker or systemd do.
parent 7b0d4db6
No related branches found
No related tags found
No related merge requests found
...@@ -78,6 +78,7 @@ class Service: ...@@ -78,6 +78,7 @@ class Service:
def __init__(self, shard=0): def __init__(self, shard=0):
signal.signal(signal.SIGINT, lambda unused_x, unused_y: self.exit()) signal.signal(signal.SIGINT, lambda unused_x, unused_y: self.exit())
signal.signal(signal.SIGTERM, lambda unused_x, unused_y: self.exit())
self.name = self.__class__.__name__ self.name = self.__class__.__name__
self.shard = shard self.shard = shard
......
...@@ -24,6 +24,7 @@ import os ...@@ -24,6 +24,7 @@ import os
import pprint import pprint
import re import re
import shutil import shutil
import signal
import time import time
from datetime import datetime from datetime import datetime
...@@ -622,6 +623,10 @@ def main(): ...@@ -622,6 +623,10 @@ def main():
certfile=config.https_certfile, keyfile=config.https_keyfile) certfile=config.https_certfile, keyfile=config.https_keyfile)
servers.append(https_server) servers.append(https_server)
def sigterm_handler(*_):
raise KeyboardInterrupt
signal.signal(signal.SIGTERM, sigterm_handler)
try: try:
gevent.joinall(list(gevent.spawn(s.serve_forever) for s in servers)) gevent.joinall(list(gevent.spawn(s.serve_forever) for s in servers))
except KeyboardInterrupt: except KeyboardInterrupt:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment