]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/initscripts/system/functions
suricata: Change midstream policy to "pass-flow"
[ipfire-2.x.git] / src / initscripts / system / functions
index 30119918cadbe9245ef0db60ac30f1326a493caf..5a26aef45f843b55b95e628dbc93111a412b425f 100644 (file)
@@ -1,17 +1,23 @@
 #!/bin/sh
-########################################################################
-# Begin $rc_base/init.d/functions
-#
-# Description : Run Level Control Functions
-#
-# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
-#
-# Version     : 00.00
-#
-# Notes       : With code based on Matthias Benkmann's simpleinit-msb
-#              http://winterdrache.de/linux/newboot/index.html
-#
-########################################################################
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007-2022  IPFire Team  <info@ipfire.org>                     #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 ## Environmental setup
 # Setup default values for environment
@@ -401,7 +407,7 @@ pidofproc()
 # This will ensure compatibility with previous LFS Bootscripts
 getpids()
 {
-       if [ -z "${PIDFILE}" ]; then
+       if [ -n "${PIDFILE}" ]; then
                pidofproc -s -p "${PIDFILE}" $@
        else
                pidofproc -s $@
@@ -436,9 +442,11 @@ getpids()
 #*******************************************************************************
 loadproc()
 {
+       local background=""
        local pidfile=""
        local forcestart=""
        local nicelevel=""
+       local pid
 
 # This will ensure compatibility with previous LFS Bootscripts
        if [ -n "${PIDFILE}" ]; then
@@ -448,6 +456,10 @@ loadproc()
   while true
        do
                case "${1}" in
+                       -b)
+                               background="1"
+                               shift 1
+                               ;;
                        -f)
                                forcestart="1"
                                shift 1
@@ -506,8 +518,23 @@ loadproc()
                cmd="nice -n "${nicelevel}" ${cmd}"
        fi
 
-       ${cmd}
-       evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
+       if [ -n "${background}" ]; then
+               (
+                       ${cmd} &>/dev/null
+               ) &
+               pid="$!"
+               evaluate_retval
+       else
+               ${cmd}
+               pid="$!"
+               evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
+       fi
+
+       # Write the pidfile
+       if [ -n "${pid}" -a -n "${pidfile}" ]; then
+               echo "${pid}" > "${pidfile}"
+       fi
+
        return 0
 }
 
@@ -784,21 +811,22 @@ umount_ramdisk() {
        rm -rf "${path_tmpfs}"
 }
 
+# Returns true when this system running in a virtual environment
+running_on_hypervisor() {
+       grep -qE "^flags\s+:.*hypervisor" /proc/cpuinfo
+}
+
 # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html
 running_on_ec2() {
        local uuid
 
-       # Check if the hypervisor UUID starts with ec2
-       if [ -r "/sys/hypervisor/uuid" ]; then
-               uuid=$(</sys/hypervisor/uuid)
-
-               [ "${uuid:0:3}" = "ec2" ] && return 0
-       fi
-
        # Check if the DMI product UUID starts with EC2
        if [ -r "/sys/devices/virtual/dmi/id/product_uuid" ]; then
                uuid=$(</sys/devices/virtual/dmi/id/product_uuid)
 
+               # Convert the UUID as uppercase
+               uuid="${uuid^^}"
+
                [ "${uuid:0:3}" = "EC2" ] && return 0
        fi
 
@@ -822,6 +850,17 @@ running_on_azure() {
        return 1
 }
 
+running_on_exoscale() {
+       if [ -r "/sys/devices/virtual/dmi/id/sys_vendor" ]; then
+               local sys_vendor="$(</sys/devices/virtual/dmi/id/sys_vendor)"
+
+               [ "${sys_vendor}" = "Exoscale" ] && return 0
+       fi
+
+       # We are not running on Exoscale
+       return 1
+}
+
 running_on_gcp() {
        # Check if the BIOS vendor is "Google"
        if [ -r "/sys/devices/virtual/dmi/id/bios_vendor" ]; then
@@ -844,5 +883,3 @@ running_on_oci() {
        # We are not running on OCI
        return 1
 }
-
-# End $rc_base/init.d/functions