diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-10-04 13:53:01 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-10-04 13:53:01 +0000 |
commit | 55b5a9cc5ea6f7f634a3b6b667c39b7c5cb02a8f (patch) | |
tree | cc9d34e3b8d8f4b00750c9ed8f144b0345e57158 /xpp/astribank_hook | |
parent | 6815e5932f1a6aa0d7301f728351fd9b85f2a854 (diff) |
Add XPP_HOTPLUG_DAHDI mode: cfg initiated mostly from hotplug
If XPP_HOTPLUG_DAHDI=yes is set in /etc/dahdi/init.conf (which is not
the default), the normal run of the 'start' operation of the dahdi init
script will only be responsible for loading modules. The rest will be
done (if there are indeed Astribanks on the system) by a second call to
the init script once all of them have connected.
The astribank_hook has also been mostly rewritten. Most of the
functionality of twinstar_hook moved to it. The current twinstar_hook is
a simple example script.
XPP_HOTPLUG_DAHDI mode assumes that all Astribanks on the system are
listed in /etc/dahdi/xpp_order (which can be generated using, e.g.
'dahdi_genconf xpporder')
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@7335 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/astribank_hook')
-rwxr-xr-x | xpp/astribank_hook | 75 |
1 files changed, 70 insertions, 5 deletions
diff --git a/xpp/astribank_hook b/xpp/astribank_hook index 9510f7b..8c5bea8 100755 --- a/xpp/astribank_hook +++ b/xpp/astribank_hook @@ -11,11 +11,69 @@ LOGGER="logger -i -t '$me'" ## If you wish to trace this script: #exec 2> "/tmp/${me}_$XBUS_NAME" 1>&2 +# Our directory in the beginning, so we can use local lab setup PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin" set -e -echo "starting($ACTION): '$*'" | $LOGGER +[ -r /etc/dahdi/init.conf ] && . /etc/dahdi/init.conf + +# For lab testing +liveconf="$dir/liveconf/dahdi" + +if [ -d "$liveconf" ]; then + dahdi_conf="$liveconf" +else + dahdi_conf="/etc/dahdi" +fi + +export XPPORDER_CONF="$dahdi_conf/xpp_order" +if [ ! -r "$XPPORDER_CONF" ]; then + echo "Skip($ACTION): No '$XPPORDER_CONF'" | $LOGGER + exit 0 +fi +export DAHDI_CFG_CMD="dahdi_cfg -c $dahdi_conf/system.conf" +export CALLED_FROM_ATRIBANK_HOOK=yes + +clean_lines() { + sed -e 's/#.*//' -e 'y/\t/ /' -e 's/^ *//' -e 's/ *$//' "$XPPORDER_CONF" +} + +matched_devices() { + ready=`grep -H READY /sys/bus/astribanks/devices/*/xbus_state | sed 's,/xbus_state.*,,'` + for dev in $ready + do + label=`cat "$dev/label"` + connector=`cat "$dev/connector"` + xbus=`echo "$dev" | sed 's,.*/,,'` + lineno=`clean_lines | egrep -n "^${label}$|^@${connector}$" | cut -d: -f1` + if [ "$lineno" != "" ]; then + #echo "$xbus: $XPPORDER_CONF:$lineno -- Match ${label} @${connector}" | $LOGGER + echo -e "${xbus}\t${label}" + else + echo "${xbus}: ${label} @${connector} not found in $XPPORDER_CONF: Ignore($ACTION)" | $LOGGER + fi + done +} + +NUM_WANTED=`clean_lines | sed '/^$/d' | wc -l` +NUM_GOOD=`matched_devices | wc -l` + +start_dahdi() { + script=/etc/init.d/dahdi + if [ "$XPP_HOTPLUG_DAHDI" = yes ]; then + echo "Starting $script." + "$script" start | logger -i -t "$script" + status=$? + echo "Status($script): $status" + else + echo "$0: Skip($script): No XPP_HOTPLUG_DAHDI=yes in /etc/dahdi/init.conf" + exit 0 + fi + if [ -x "$dir/twinstar_hook" ]; then + "$dir/twinstar_hook" + fi +} case "$ACTION" in add) @@ -23,13 +81,20 @@ add) remove) ;; online) - if [ -x "$dir/twinstar_hook" ]; then - "$dir/twinstar_hook" + echo "$ACTION($XBUS_NAME): $NUM_GOOD/$NUM_WANTED from $XPPORDER_CONF" | $LOGGER + if [ "$NUM_GOOD" -eq "$NUM_WANTED" ]; then + echo "START-DAHDI: Total $NUM_GOOD online." | $LOGGER + # Fork services + start_dahdi < /dev/null 2>&1 | $LOGGER & fi ;; offline) - if [ -x "$dir/twinstar_hook" ]; then - "$dir/twinstar_hook" + echo "$ACTION($XBUS_NAME): $NUM_GOOD/$NUM_WANTED from $XPPORDER_CONF" | $LOGGER + if [ "$NUM_GOOD" -eq 0 ]; then + echo "All Astribanks offline" | $LOGGER + if [ -x "$dir/twinstar_hook" ]; then + "$dir/twinstar_hook" + fi fi ;; *) |