]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
ids-functions.pl: Add function to check if the IDS is running
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 5 Aug 2018 12:23:45 +0000 (14:23 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 5 Aug 2018 12:23:45 +0000 (14:23 +0200)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ids-functions.pl

index acf097bb828ad73dd488b4eee385e7dc0f555ff8..ebbf61585ecead28ae9057d3893449955f836539 100644 (file)
@@ -41,6 +41,9 @@ our $rulespath = "/etc/suricata/rules";
 # (Sourcefire, Emergingthreads, etc..)
 our $rulesetsourcesfile = "$settingsdir/ruleset-sources";
 
+# The pidfile of the IDS.
+our $idspidfile = "/var/run/suricata.pid";
+
 #
 ## Function for checking if at least 300MB of free disk space are available
 ## on the "/var" partition.
@@ -290,4 +293,32 @@ sub get_available_network_zones () {
        return @network_zones;
 }
 
+#
+## Function to check if the IDS is running.
+#
+sub ids_is_running () {
+       if(-f $idspidfile) {
+               # Open PID file for reading.
+               open(PIDFILE, "$idspidfile") or die "Could not open $idspidfile. $!\n";
+
+               # Grab the process-id.
+               my $pid = <PIDFILE>;
+
+               # Close filehandle.
+               close(PIDFILE);
+
+               # Remove any newline.
+               chomp($pid);
+
+               # Check if a directory for the process-id exists in proc.
+               if(-d "/proc/$pid") {
+                       # The IDS daemon is running return the process id.
+                       return $pid;
+               }
+       }
+
+       # Return nothing - IDS is not running.
+       return;
+}
+
 1;