linKNX ist eine bewährte Logik-Engine, hat aber den Nachteil, dass die Konfigurationsdatei (linknx.xml) mit der Zeit sehr groß und unübersichtlich wird.
Wie hier schon im Forum diskutiert, gibt es bei linKNX kein Problem, wenn es mehrfach gestartet wird. Es muss nur für jede Instanz eine Konfigurationsdatei erzeugt und beim Aufruf angegeben werden. Der Nachteil ist, dass z.B. zentrale Objekte mehrfach (in jeder Konfigurationsdatei) gepflegt werden müssen.
Das folgende kleine Skript nimmt sich dieser Problematik an und startet automatisch für jede in einem Verzeichnis vorhandene Konfigurationsdatei eine linKNX Instanz.
Zusätzlich werden zentrale Konfigurationsdateien (Beginnen immer mit einem Unterstrich (_) und enden mit .xml) in die "Hauptkonfigurationen" eingebunden.
Das Einbinden der zentralen Konfigurationen geschieht genau dort, wo in der Hauptkonfiguration folgende Zeile steht (_xyz.xml ist durch den Dateinamen der Konfigurationsdatei zu ersetzen):
Die Pfad-Angaben im folgenden Skript verwende ich so auf meinem Wiregate und müssen entsprechend angepasst werden.
Dies ist die erste (veraltete) Version des Skripts:
Im Anhang ist ein Beispiel für drei linKNX-Instanzen (lights, multiroom, misc) und zwei zentralen Konfigurationen (_objects.xml und _services.xml), die in die drei eingebunden werden, angehängt. Bei mir habe ich die Dateien unter /etc/linknx gespeichert.
Das obige Skript muss ausführbar gespeichert und z.B. von einem Startskript aufgerufen werden. Getestet und im Einsatz habe ich es nur auf meinem Wiregate.
Wie hier schon im Forum diskutiert, gibt es bei linKNX kein Problem, wenn es mehrfach gestartet wird. Es muss nur für jede Instanz eine Konfigurationsdatei erzeugt und beim Aufruf angegeben werden. Der Nachteil ist, dass z.B. zentrale Objekte mehrfach (in jeder Konfigurationsdatei) gepflegt werden müssen.
Das folgende kleine Skript nimmt sich dieser Problematik an und startet automatisch für jede in einem Verzeichnis vorhandene Konfigurationsdatei eine linKNX Instanz.
Zusätzlich werden zentrale Konfigurationsdateien (Beginnen immer mit einem Unterstrich (_) und enden mit .xml) in die "Hauptkonfigurationen" eingebunden.
Das Einbinden der zentralen Konfigurationen geschieht genau dort, wo in der Hauptkonfiguration folgende Zeile steht (_xyz.xml ist durch den Dateinamen der Konfigurationsdatei zu ersetzen):
Code:
<!-- replace _xyz.xml -->
Dies ist die erste (veraltete) Version des Skripts:
Code:
#!/bin/bash # Some configuration variables # # (Temp-)Path to the combined linknx configuration files OUTPUT_PATH=/etc/linknx/tmp # Path to the configuration file which should be combined (see important info) CONFIG_PATH=/etc/linknx # Path to linKNX LINKNX=/usr/bin/linknx PID_PATH=/var/run # Important info: # Confguration files that should be insert in an other file (called central configs), # must beginn with an underline (_) and end with .xml # The Place in the main configuration-file should be marked in # an new line and with the following text: <!-- replace _xxx.xml --> # _xxx.xml is the name of the file which should be insert # Configuration end # Combine the configuration files # find all configuartion files (not the central files with _-prefix) for FILE in `find $CONFIG_PATH -type f \( -iname "*.xml" ! -iname "_*" \) -printf "%f\n"` do # copy xml-file to start with a clean configuration cp -f $CONFIG_PATH/$FILE $OUTPUT_PATH # find line with <!-- replace _xxx.xml --> while read line; do [[ $line =~ \<!--.replace.(_.*\.xml).--\> ]] || continue # get content to insert INSERT_CONTENT=`cat "$CONFIG_PATH/$(echo "$line" | sed -e 's|.*\(_.*\.xml\) .*|\1|')"` # get the content before and after the found line with config _xxx.xml FIRST_LINES=`cat "$OUTPUT_PATH/$FILE" | sed -e '/'"$line"'/,$d'` LAST_LINES=`cat "$OUTPUT_PATH/$FILE" | sed -e '1,/'"$line"'/d'` # Make a new file with the three parts echo "$FIRST_LINES" > "$OUTPUT_PATH/$FILE" echo "$INSERT_CONTENT" >> "$OUTPUT_PATH/$FILE" echo "$LAST_LINES" >> "$OUTPUT_PATH/$FILE" done < $FILE done # Start a linKNX-instance for every configuration file for FILE in `find $OUTPUT_PATH -type f \( -iname "*.xml" ! -iname "_*" \)` do INSTANCE_NAME=`echo "$FILE" | sed -e 's|.*\/\(.*\)\.xml|\1|'` # kill a runnung linknx instance if [ -f "$PID_PATH/linknx-$INSTANCE_NAME.pid" ]; then kill `cat "$PID_PATH/linknx-$INSTANCE_NAME.pid"`; fi # Start linKNX-Instance echo "Starting $LINKNX -c$FILE -p$PID_PATH/linknx-$INSTANCE_NAME.pid -d -w" `$LINKNX -c$FILE -p$PID_PATH/linknx-$INSTANCE_NAME.pid -d -w` done
Das obige Skript muss ausführbar gespeichert und z.B. von einem Startskript aufgerufen werden. Getestet und im Einsatz habe ich es nur auf meinem Wiregate.
Kommentar