Skip to content

Commit

Permalink
Install a SIGTERM handler in addition to SIGINT (#1246)
Browse files Browse the repository at this point in the history
This allows cleanly terminating CMS by sending it SIGTERM, which is what
e.g. Docker or systemd do.
  • Loading branch information
prandla authored Jan 18, 2024
1 parent 7b0d4db commit c88c1e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions cms/io/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Service:

def __init__(self, shard=0):
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.shard = shard
Expand Down
5 changes: 5 additions & 0 deletions cmsranking/RankingWebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import pprint
import re
import shutil
import signal
import time
from datetime import datetime

Expand Down Expand Up @@ -622,6 +623,10 @@ def main():
certfile=config.https_certfile, keyfile=config.https_keyfile)
servers.append(https_server)

def sigterm_handler(*_):
raise KeyboardInterrupt
signal.signal(signal.SIGTERM, sigterm_handler)

try:
gevent.joinall(list(gevent.spawn(s.serve_forever) for s in servers))
except KeyboardInterrupt:
Expand Down

0 comments on commit c88c1e9

Please sign in to comment.