Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check and cleanup for stale Suricata PID file upon service startup #166

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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