diff --git a/NEWS b/NEWS index fc2be9b0..197d7708 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +1.4.5 - ??? ?? ???? +=================== +Changed: +* check config before reload/start will be done (#364) (ccztux) + + 1.4.4 - Jun 03 2025 =================== Features: diff --git a/daemon-init.in b/daemon-init.in index 1f49acb0..fb120f4c 100644 --- a/daemon-init.in +++ b/daemon-init.in @@ -64,6 +64,7 @@ status() { } start() { + check_config test -x $exec || exit 5 test -f $config || exit 6 echo -n "Starting $prog: " @@ -118,6 +119,7 @@ restart() { } reload() { + check_config echo -n "Reloading $prog: " if [ -e $pidfile ]; then PID=`cat $pidfile`; @@ -133,6 +135,27 @@ force_reload() { restart } +check_config() { + echo -n "Running configuration check... " + + if type runuser >/dev/null 2>&1; then + runuser -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config" >/dev/null 2>&1; + else + /bin/su - -s /bin/sh $user -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config" >/dev/null 2>&1; + fi + + retval=$? + + if [ $retval == 0 ] ;then + echo "OK" + return $retval + else + echo "CONFIG ERROR!" + echo "Reload/start aborted. Check your Naemon configuration." + exit $retval + fi +} + case "$1" in start) $1 @@ -168,6 +191,7 @@ case "$1" in restart ;; configtest|check|checkconfig) + check_config if command -v runuser >/dev/null 2>&1; then runuser -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config" else diff --git a/daemon-systemd.in b/daemon-systemd.in index 657a5f52..f3ccdf03 100644 --- a/daemon-systemd.in +++ b/daemon-systemd.in @@ -10,6 +10,7 @@ PIDFile=@lockfile@ PermissionsStartOnly=true ExecStartPre=/bin/su naemon --login --shell=/bin/sh "--command=@bindir@/naemon --verify-config @pkgconfdir@/naemon.cfg" ExecStart=@bindir@/naemon --daemon @pkgconfdir@/naemon.cfg +ExecReload=/bin/su naemon --login --shell=/bin/sh "--command=@bindir@/naemon --verify-config @pkgconfdir@/naemon.cfg" ExecReload=/bin/kill -HUP $MAINPID User=naemon Group=naemon