Configure runsnappea to be rebooted every day

a way to limit memory leaks

also: deal with SIGTERM 'correctly' (i.e. as demanded by systemd)
This commit is contained in:
Klaas van Schelven
2024-05-22 12:44:58 +02:00
parent 9fcbfb9033
commit b09cfb21c3
2 changed files with 10 additions and 7 deletions

View File

@@ -197,6 +197,7 @@ Description=gunicorn daemon
After=network.target
[Service]
Restart=always
Type=notify
User=bugsink
Group=bugsink
@@ -205,7 +206,6 @@ Environment="PYTHONUNBUFFERED=1"
RuntimeDirectory=gunicorn
WorkingDirectory=/home/bugsink
ExecStart=/home/bugsink/venv/bin/gunicorn --bind="127.0.0.1:8000" --workers=5 --access-logfile - --capture-output --error-logfile - --max-requests=1000 --max-requests-jitter=100 bugsink.wsgi
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=5
@@ -410,20 +410,22 @@ We will set up Snappea to run as a systemd service.
Add a file `/etc/systemd/system/snappea.service` with the following contents:
```
```ini
[Unit]
Description=snappea daemon
[Service]
Restart=always
User=bugsink
Group=bugsink
Environment="PYTHONUNBUFFERED=1"
RuntimeDirectory=gunicorn
WorkingDirectory=/home/bugsink
ExecStart=/home/bugsink/venv/bin/bugsink-runsnappea
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=5
RuntimeMaxSec=1d
[Install]
WantedBy=multi-user.target

View File

@@ -72,7 +72,8 @@ class Foreman:
self.workers = Workers()
self.stopping = False
signal.signal(signal.SIGINT, self.handle_sigint)
signal.signal(signal.SIGINT, self.handle_signal)
signal.signal(signal.SIGTERM, self.handle_signal)
# We use inotify to wake up the Foreman when a new Task is created.
if not os.path.exists(self.settings.WAKEUP_CALLS_DIR):
@@ -147,11 +148,11 @@ class Foreman:
self.workers.start(task_id, worker_thread)
return worker_thread
def handle_sigint(self, signal, frame):
# We set a flag and release a semaphore. The advantage is that we don't have to think about e.g. handle_sigint
def handle_signal(self, sig, frame):
# We set a flag and release a semaphore. The advantage is that we don't have to think about e.g. handle_signal()
# being called while we're handling a previous call to it. The (slight) disadvantage is that we need to sprinkle
# calls to check_for_stopping() in more locations (at least after every semaphore is acquired)
logger.debug("Received SIGINT") # NOTE: calling logger in handle_xxx is probably a bad idea
logger.debug("Received %s signal", signal.strsignal(sig)) # NOTE: calling logger in handle_xxx is a bad idea
if not self.stopping: # without this if-statement, repeated signals would extend the deadline
self.stopping = True