Skip to content

Commit

Permalink
Implemented: Adding configuration for start and reload (naemon#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
zet committed Nov 2, 2021
1 parent cae7c16 commit 72f1c9c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.2.5 - ??? ?? ????
===================
Changed:
* check config before reload/start will be done (#364) (ccztux)


1.2.4 - Mar 03 2021
===================
Features:
Expand Down
29 changes: 24 additions & 5 deletions daemon-init.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ status() {
}

start() {
check_config
test -x $exec || exit 5
test -f $config || exit 6
echo -n "Starting $prog: "
Expand Down Expand Up @@ -118,6 +119,7 @@ restart() {
}

reload() {
check_config
echo -n "Reloading $prog: "
if [ -e $pidfile ]; then
PID=`cat $pidfile`;
Expand All @@ -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
Expand Down Expand Up @@ -168,11 +191,7 @@ case "$1" in
restart
;;
configtest|check|checkconfig)
if type runuser >/dev/null 2>&1; then
runuser -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config"
else
/bin/su - -s /bin/sh $user -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config"
fi
check_config
retval=$?
;;
*)
Expand Down
1 change: 1 addition & 0 deletions daemon-systemd.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ExecStartPre=-/usr/bin/mkdir -p /var/run/naemon
ExecStartPre=/usr/bin/chown -R naemon:naemon /var/run/naemon/
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
Expand Down

0 comments on commit 72f1c9c

Please sign in to comment.