Hey folks,
after changes in the OpenNMS config, I get always a little confused when
I did typo :-). In such a case there are messages like this in output.log:

---8<---
Caused by: org.exolab.castor.xml.MarshalException: Element type
"definition" must be followed by either attribute specifications, ">" or
"/>".{File: [not available]; line: 51; column: 5
---8<---

As the message is a little unspecific in naming the offending file, I
added a validity-check for the .xml files in the Debian init script. If
an invalid .xml file is found, the script exits with status 1. You need
the package xmlstarlet be installed in order to make that work (apt-get
install xmlstarlet). If the patch will be adopted, the Debian control
file should list xmlstarlet as a "recommends".

Currently it only check for well-formed XML, but xmlstartet also offers
DTD/XSD/RelaxNG support, so there is room for further improvement ;)

An example output, if an invalid file is found:
---8<---
opennms:/etc/opennms# /etc/init.d/opennms start
Preflight-Check...
/etc/opennms/test.xml is invalid.
Invalid config. Check /var/log/opennms/daemon/initscript.log for details.
---8<---


Rgds,
Andreas


---
opennms:/etc/opennms# diff -u
/usr/local/src/opennms-1.6.1-1/source/debian/opennms-server.opennms.init
/etc/init.d/opennms
---
/usr/local/src/opennms-1.6.1-1/source/debian/opennms-server.opennms.init
   2008-11-13 20:10:05.000000000 +0100
+++ /etc/init.d/opennms 2009-01-04 12:27:30.000000000 +0100
@@ -30,6 +30,27 @@

 set -e

+preflight_check() {
+       # XML vaild?
+       if [ -e /usr/bin/xmlstarlet ]; then
+       echo -n "Preflight-Check..."
+               echo "Preflight-Check $(date)" >>
/var/log/opennms/daemon/initscript.log
+               STARTMEUP=1
+               for i in $(find /etc/opennms -name "*.xml"); do
+                       if ! ( /usr/bin/xmlstarlet val -q $i 2>>
/var/log/opennms/daemon/initscript.log ); then
+                               echo -e "\n$i is invalid."
+                               STARTMEUP=0
+                       fi
+               done
+               if [ ${STARTMEUP} = 1 ]; then
+                       echo "OK"
+               else
+                       echo "Invalid config. Check
/var/log/opennms/daemon/initscript.log for details."
+                       exit 1
+               fi
+       fi
+}
+
 # read in settings from default file
 if [ -f /etc/default/$NAME ]; then
        . /etc/default/$NAME
@@ -53,6 +74,7 @@

 case "$1" in
   start)
+       preflight_check
        echo -n "Starting $DESC: $NAME"
        $DAEMON start > /dev/null
        echo "."
@@ -64,6 +86,7 @@
        echo "."
        ;;
   restart|force-reload)
+       preflight_check
        $0 stop
        sleep 2
        $0 start



------------------------------------------------------------------------------
_______________________________________________
Please read the OpenNMS Mailing List FAQ:
http://www.opennms.org/index.php/Mailing_List_FAQ

opennms-devel mailing list

To *unsubscribe* or change your subscription options, see the bottom of this 
page:
https://lists.sourceforge.net/lists/listinfo/opennms-devel

Reply via email to