Skip to content

Commit

Permalink
Merge pull request #166 from jasper-vdhoven/improved-startup-handling
Browse files Browse the repository at this point in the history
Added check and cleanup for stale Suricata PID file upon service startup
  • Loading branch information
cccs-rs authored Nov 26, 2024
2 parents 663fb9a + 2016e67 commit 30782a0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions suricata_/suricata_.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import pathlib
import subprocess
import sys
import time
Expand Down Expand Up @@ -192,6 +193,19 @@ def suricata_running_retry(self):

# Launch Suricata using a UID socket
def launch_or_load_suricata(self):
self.log.info("Checking whether a stale Suricata PID file already exists")
"""
Check whether a PID file already exists; if it does, this might be a restart
and we should remove it as there likely isn't a running Suricata instance.
"""
pid_path = pathlib.Path(self.run_dir, "suricata.pid")
if pid_path.exists():
self.log.warning("Attempting to remove stale Suricata PID file")
try:
pid_path.unlink()
except PermissionError:
raise PermissionError("Could not delete stale Suricata PID file")

self.suricata_socket = os.path.join(self.run_dir, "suricata.socket")

if not os.path.exists(self.suricata_socket):
Expand Down

0 comments on commit 30782a0

Please sign in to comment.