Inhaltsverzeichnis

openQRM - Plugins

Ein Plugin wird immer erst gestartet, nach dem das gewünschte "/"-Dateisystem (aus dem "Image") gemountet ist.

Soll eine Aktion vor dem mounten ausgeführt werden (also auch dann, wenn die "Appliance" gestoppt wurde), dann muss die Aktion über die entsprechenden HOOK's implementiert werden. Aber Vorsicht, die HOOK's gehören zum Basissystem und müssen mit allen möglichen Kombinationen der verschiedenen Plugins ohne Seiteneffekte zusammen arbeiten!

Will man ein eigenes Plugin für openQRM bauen, dann geht das wie folgt. In diesem Beispiel wird das TFTP-Plugin als Vorlage verwendet:

# /usr/share/openqrm/bin/openqrm-create-plugin <SOURCE_PLUGIN> <DESTINATION_PLUGIN>
# /usr/share/openqrm/bin/openqrm-create-plugin tftpd montag
# cd /usr/share/openqrm/plugins/montag/
# rm -f web/.running

wichtige Dateien

Diese Dateien sollte man sich auf jeden Fall ansehen und nach bedarf bearbeiten:

etc/init.d/openqrm-plugin-montag
etc/init.d/openqrm-plugin-montag.postinstall
etc/init.d/openqrm-plugin-montag.preremove
etc/openqrm-plugin-montag.conf
include/openqrm-plugin-montag-functions
web/img/plugin.png
web/menu.txt
web/openqrm-montag-resource-hook.php
web/montag-about.php

etc/init.d/openqrm-plugin-montag

Hier muss das größte Augenmerk auf die Funktion "function openqrm_plugin_montag_init()" gelegt werden, denn hier werden die eigentlichen Aktionen ausgeführt.

In unserem Fall genügt etwas in dieser Art:

function openqrm_plugin_montag_init() {
        echo "Initializing the openQRM montag-plugin"
        # linking the web dir
        ln -sf $OPENQRM_SERVER_BASE_DIR/openqrm/plugins/montag/web $OPENQRM_WEBSERVER_DOCUMENT_ROOT/openqrm/base/plugins/montag

        # link the boot-service
        ln -sf $OPENQRM_SERVER_BASE_DIR/openqrm/plugins/montag/web/boot-service-montag.tgz $OPENQRM_WEBSERVER_DOCUMENT_ROOT/openqrm/boot-service/boot-service-montag.tgz

        # Aktion starten
        echo "Das Super-Plugin montag..."
}

web/openqrm-montag-resource-hook.php

Um etwas vor dem Bootprozess auszuführen:

...

function openqrm_montag_resource($cmd, $resource_fields) {
        global $event;
        global $OPENQRM_SERVER_BASE_DIR;
        global $OPENQRM_SERVER_IP_ADDRESS;
        global $OPENQRM_EXEC_PORT;
        $resource_id=$resource_fields["resource_id"];
        $resource_ip=$resource_fields["resource_ip"];
        $resource_mac=$resource_fields["resource_mac"];
        $event->log("openqrm_new_resource", $_SERVER['REQUEST_TIME'], 5, "openqrm-montag-resource-hook.php", "Handling $cmd event $resource_id/$resource_ip/$resource_mac", "", "", 0, 0, $resource_id);

        $mycommand = $OPENQRM_SERVER_BASE_DIR."/openqrm/plugins/montag/bin/montag.sh ".$resource_id." ".$resource_ip." ".$resource_mac;

        $openqrmserver = new openqrm_server();
        $openqrmserver->send_command($mycommand);

}
?>

ergänzte Dateien

bin/montag.sh
etc/init.d/montag

bin/montag.sh

#!/bin/bash


ID=$1
IP=$2
MAC=$3


echo "NOTICE : This is the montag command $ID $IP $MAC" | logger

etc/init.d/montag

#!/bin/bash
# this is the boot-service init script for the montag resources
#
# This file is part of openQRM.
#
# openQRM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# openQRM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with openQRM.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2009, Matthias Rechenburg <matt@openqrm.com>
#

OPENQRM_SERVER_BASE_DIR=$(pushd $(dirname $0)/../../../../.. > /dev/null; echo $PWD; popd > /dev/null)
. $OPENQRM_SERVER_BASE_DIR/openqrm/include/openqrm-functions
. $OPENQRM_RESOURCE_PARAMETER_FILE
OPENQRM_SERVER_IP=$resource_openqrmserver
NETWORK_CONF="/tmp/montag-net.conf"
# define wget to use with https
if [ "$openqrm_web_protocol" == "https" ]; then
    WGET_NO_CERT_CHECK="--no-check-certificate"
fi


# start thise on the intitrd
if [ -f /etc/initrd-devices.conf ]; then
        echo "NOTICE: Starting the montag plugin"
        echo "NOTICE: Starting the montag plugin" | logger
fi


# start thise on the openQRM server itself
if [ -f $OPENQRM_SERVER_BASE_DIR/openqrm/etc/openqrm-server.conf ]; then
        exit 0
fi


function montag_start() {
        echo "Starting the openQRM montag-plugin"
        echo "Starting the openQRM montag-plugin" | logger
}


function montag_stop() {
        echo "Stopping the openQRM montag-plugin"
        echo "Stopping the openQRM montag-plugin" | logger
}





case "$1" in
        start)
              montag_start
              ;;
        stop)
              montag_stop
              ;;
        restart)
              montag_stop
              sleep 1
              montag_start
              ;;
        *)
              echo "Usage: $0 {start|stop|restart}"
              exit 1

esac
exit $?