commit 8b23e851af0dc5dc6aa125a8097f729b5fe9e4cf
Author: Elan Ruusamäe <[email protected]>
Date:   Sun Mar 6 10:02:46 2016 +0200

    add checkconfig support

 opensmtpd.init | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
---
diff --git a/opensmtpd.init b/opensmtpd.init
index 4ef1261..f5bf3bb 100755
--- a/opensmtpd.init
+++ b/opensmtpd.init
@@ -31,6 +31,43 @@ fi
 
 pidfile="/var/run/smtpd.pid"
 
+# configtest itself
+# must return non-zero if check failed
+# output is discarded if checkconfig is ran without details
+configtest() {
+       /usr/sbin/smtpd -n
+       return $?
+}
+
+# wrapper for configtest
+checkconfig() {
+       local details=${1:-0}
+
+       if [ $details = 1 ]; then
+               # run config test and display report (status action)
+               show "Checking %s configuration" "OpenSMTPd"; busy
+               local out
+               out=$(configtest 2>&1)
+               RETVAL=$?
+               if [ $RETVAL = 0 ]; then
+                       ok
+               else
+                       fail
+               fi
+               [ "$out" ] && echo >&2 "$out"
+       else
+               # run config test and abort with nice message if failed
+               # (for actions checking status before action).
+               configtest >/dev/null 2>&1
+               RETVAL=$?
+               if [ $RETVAL != 0 ]; then
+                       show "Checking %s configuration" "OpenSMTPd"; fail
+                       nls 'Configuration test failed. See details with %s 
"checkconfig"' $0
+                       exit $RETVAL
+               fi
+       fi
+}
+
 start() {
        # Check if the service is already running?
        if [ -f /var/lock/subsys/opensmtpd ]; then
@@ -38,6 +75,7 @@ start() {
                return
        fi
 
+       checkconfig
        msg_starting "OpenSMTPd"
        daemon /usr/sbin/smtpd
        RETVAL=$?
@@ -63,6 +101,7 @@ condrestart() {
                return
        fi
 
+       checkconfig
        stop
        start
 }
@@ -86,12 +125,15 @@ case "$1" in
   force-reload)
        condrestart 7
        ;;
+  checkconfig|configtest)
+       checkconfig 1
+       ;;
   status)
        status --pidfile $pidfile smtpd
        RETVAL=$?
        ;;
   *)
-       msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
+       msg_usage "$0 
{start|stop|restart|try-restart|force-reload|checkconfig|status}"
        exit 3
 esac
 
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/opensmtpd.git/commitdiff/94d27daefdb8ba9bc60fa6a3da49143c3ce1d31f

_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to