diff --git a/PythonServer/pos-python-server.py b/PythonServer/pos-python-server.py
index 42c6e51cfe600bd7a85d67fe91c94548d8a891c2..a5b5af5618e893bba40f27876fa5763f4e455d0a 100755
--- a/PythonServer/pos-python-server.py
+++ b/PythonServer/pos-python-server.py
@@ -2,6 +2,7 @@ import epics
 import time
 import json
 import os
+import signal
 import matplotlib.pyplot as plt
 from io import BytesIO
 from git import Repo
@@ -484,6 +485,14 @@ class myHandler(BaseHTTPRequestHandler):
         self.wfile.write(bytes('The server is running', "utf-8"))
         return
 
+
+def on_exit(signum, frame):
+    print(f'Signal handler called with signal {signum}')
+    raise SystemExit("Exiting")
+
+
+signal.signal(signal.SIGTERM, on_exit)
+
 try:
     epicsThread = epicsQuery(stop_signal)
     epicsThread.start()
@@ -491,7 +500,7 @@ try:
     print ('Started httpserver on port ' , PORT_NUMBER)
     server.serve_forever()
 
-except KeyboardInterrupt:
+except (KeyboardInterrupt, SystemExit):
     print ('\n^C received, shutting down the web server')
     server.socket.close()
     stop_signal.set()