summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2009-11-04 20:32:25 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2009-11-04 20:32:25 +0000
commit9e682ffd0f98e23b83a2cb1dcfc4163a512111bb (patch)
tree21a96107d6bb45abbbadf03604d68fb15e9f400b
parentef4399ff222f532ef427255e30ec9016b9e25c1e (diff)
Add optional "hotplug mode" to init scripts
The hotplug mode is only used in XPP_HOTPLUG_DAHDI=yes is set in /etc/dahdi/init.conf . If it is set and the system actually has Astribanks, most of the init script will actually be run from the context of a udev event. Merged revisions 6987,7014,7334-7335,7409,7476 via svnmerge from https://origsvn.digium.com/svn/dahdi/tools/trunk ........ r6987 | tzafrir | 2009-08-13 18:15:49 +0300 (Thu, 13 Aug 2009) | 9 lines xpp: Add astribank_is_starting: astribank_is_running is used to tell when we may have an Astribank that is initializing (and may be re-enumerating and thus not listed as a device). It uses a semaphore as we can always write to one and we can't always write to a file. ........ r7014 | tzafrir | 2009-08-16 19:05:11 +0300 (Sun, 16 Aug 2009) | 4 lines xpp: A man page for astribank_is_starting xpp rev: 7321 ........ r7334 | tzafrir | 2009-10-04 15:35:51 +0200 (Sun, 04 Oct 2009) | 7 lines dahdi.init: move module loading to a separate function Move the module loading parts of the dahdi init script to a seperate function - load_modules. To be used by a later commit. There is not functional change here (but the diff is confusing). ........ r7335 | tzafrir | 2009-10-04 15:53:01 +0200 (Sun, 04 Oct 2009) | 16 lines 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') ........ r7409 | tzafrir | 2009-10-21 16:30:32 +0200 (Wed, 21 Oct 2009) | 21 lines Fix XPP_HOTPLUG_DAHDI: logic; end of init.d script 'Hotplug mode' was introduced in r7335. * The logic in the script was broken. - Negative logic is not such a grand idea to start with. * Interactive invocation of init.d ends when expected and not sooner. This change makes waitfor_xpds wait longer. Rather than waiting for all the Astribanks to load, it will now wait until the initialization of dahdi from the Astribanks hook script is run. This allows running e.g.: /etc/init.d/dahdi start; /etc/init.d/asterisk start It also means that 'astribank_is_starting' is actually used as a semaphore and not only as stamp file. As before, those changes have no effect if hotplug mode is not explicitly enabled (setting 'XPP_HOTPLUG_DAHDI=yes' in init.conf). ........ r7476 | tzafrir | 2009-11-04 22:12:35 +0200 (Wed, 04 Nov 2009) | 6 lines xpp: make astribank_is_starting build without warnings. autoconfig.h is needed as semtimedop() requires _GNU_SOURCE. xpp rev: 7471 ........ git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/branches/2.2@7477 a0bf4364-ded3-4de4-8d8a-66a801d63aff
-rwxr-xr-xdahdi.init65
-rw-r--r--init.conf.sample1
-rw-r--r--xpp/Makefile6
-rwxr-xr-xxpp/astribank_hook82
-rw-r--r--xpp/astribank_is_starting.8100
-rw-r--r--xpp/astribank_is_starting.c190
-rwxr-xr-xxpp/twinstar_hook71
-rwxr-xr-xxpp/waitfor_xpds24
-rw-r--r--xpp/xpp_fxloader3
9 files changed, 459 insertions, 83 deletions
diff --git a/dahdi.init b/dahdi.init
index 5c1a3f0..5730c3b 100755
--- a/dahdi.init
+++ b/dahdi.init
@@ -86,11 +86,40 @@ unload_module() {
rmmod $module
}
+# In (xpp) hotplug mode, the init script is also executed from the
+# hotplug hook. In that case it should not attempt to loade modules.
+#
+# This function only retunrs false (1) if we're in hotplug mode and
+# coming from the hotplug hook script.
+hotplug_should_load_modules() {
+ if [ "$XPP_HOTPLUG_DAHDI" = yes -a "$CALLED_FROM_ATRIBANK_HOOK" != '' ]
+ then
+ return 1
+ fi
+ return 0
+}
+
+# In (xpp) hotplug mode: quit after we loaded modules.
+#
+# In hotplug mode, the main run should end here, whereas the rest of the
+# script should be finished by the instance running from the hook.
+# Note that we only get here if there are actually Astribanks on the
+# system (otherwise noone will trigger the run of the hotplug hook
+# script).
+hotplug_exit_after_load() {
+ if [ "$XPP_HOTPLUG_DAHDI" = yes -a "$CALLED_FROM_ATRIBANK_HOOK" = '' ]
+ then
+ exit 0
+ fi
+}
+
# Initialize the Xorcom Astribank (xpp/) using perl utiliites:
xpp_startup() {
# do nothing if there are no astribank devices:
if ! /usr/share/dahdi/waitfor_xpds; then return 0; fi
+ hotplug_exit_after_load
+
# overriding locales for the above two, as perl can be noisy
# when locales are missing.
# No register all the devices if they didn't auto-register:
@@ -144,21 +173,7 @@ shutdown_dynamic() {
$DAHDI_CFG_CMD -s
}
-if [ ! -x "$DAHDI_CFG" ]; then
- echo "dahdi_cfg not executable"
- exit 0
-fi
-
-if [ ! -f /etc/dahdi/system.conf ]; then
- echo "/etc/dahdi/system.conf not found. Nothing to do."
- exit 0
-fi
-
-RETVAL=0
-
-# See how we were called.
-case "$1" in
- start)
+load_modules() {
# Some systems, e.g. Debian Lenny, add here -b, which will break
# loading of modules blacklisted in modprobe.d/*
unset MODPROBE_OPTIONS
@@ -181,6 +196,26 @@ case "$1" in
fi
done
echo ""
+}
+
+if [ ! -x "$DAHDI_CFG" ]; then
+ echo "dahdi_cfg not executable"
+ exit 0
+fi
+
+if [ ! -f /etc/dahdi/system.conf ]; then
+ echo "/etc/dahdi/system.conf not found. Nothing to do."
+ exit 0
+fi
+
+RETVAL=0
+
+# See how we were called.
+case "$1" in
+ start)
+ if hotplug_should_load_modules; then
+ load_modules
+ fi
TMOUT=$DAHDI_DEV_TIMEOUT # max secs to wait
diff --git a/init.conf.sample b/init.conf.sample
index 78ca86e..9fb6393 100644
--- a/init.conf.sample
+++ b/init.conf.sample
@@ -11,3 +11,4 @@
# Override settings for xpp_fxloader
#XPP_FIRMWARE_DIR=/usr/share/dahdi
#XPP_HOTPLUG_DISABLED=yes
+#XPP_HOTPLUG_DAHDI=yes
diff --git a/xpp/Makefile b/xpp/Makefile
index 9409e97..13d8e21 100644
--- a/xpp/Makefile
+++ b/xpp/Makefile
@@ -65,8 +65,9 @@ TARGETS += fpga_load \
astribank_tool \
astribank_hexload \
astribank_allow \
+ astribank_is_starting \
test_parse
-PROG_INSTALL += fpga_load astribank_tool astribank_hexload astribank_allow
+PROG_INSTALL += fpga_load astribank_tool astribank_hexload astribank_allow astribank_is_starting
endif
ifneq (,$(PERLLIBDIR))
PROG_INSTALL += $(PERL_SCRIPTS)
@@ -113,6 +114,9 @@ astribank_tool: $(ABTOOL_OBJS)
astribank_allow: $(ABALLOW_OBJS)
$(CC) -L. -o $@ $(ABALLOW_OBJS) $(EXTRA_LIBS) -lusb
+astribank_is_starting: astribank_is_starting.o
+ $(CC) -L. -o $@ $^ $(EXTRA_LIBS)
+
fpga_load.o: CFLAGS+=-D_GNU_SOURCE # We use memrchr()
test_parse: test_parse.o hexfile.o
diff --git a/xpp/astribank_hook b/xpp/astribank_hook
index 9510f7b..dc55d14 100755
--- a/xpp/astribank_hook
+++ b/xpp/astribank_hook
@@ -11,11 +11,76 @@ 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'"
+ echo "Removing uneeded startup semaphore"
+ astribank_is_starting -v -r 2>&1
+ ) 2>&1 | $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
+ # Finished astribanks
+ echo "Removing semaphore"
+ astribank_is_starting -v -r
+}
case "$ACTION" in
add)
@@ -23,13 +88,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
;;
*)
diff --git a/xpp/astribank_is_starting.8 b/xpp/astribank_is_starting.8
new file mode 100644
index 0000000..55db6f6
--- /dev/null
+++ b/xpp/astribank_is_starting.8
@@ -0,0 +1,100 @@
+.TH "ASTRIBANK_IS_STARTING" "8" "16 August 2009" "" ""
+
+.SH NAME
+astribank_is_starting \- Mark / check is a Xorcom Astribank (xpp) is starting
+.SH SYNOPSIS
+.B astribank_is_starting [-d] [-v] [-t \fItimeout\fB] <-a|-r|-w>
+
+.B astribank_is_starting [-d] [-v]
+
+.B astribank_is_starting -h
+
+.SH DESCRIPTION
+.B astribank_is_starting
+is an internal tool used by various xpp scripts to mark that there may
+be an Astribank device currently initializing, and to check for that mark.
+
+Technically the mark is a SysV semaphore.
+
+.SH OPTIONS
+.B -a
+.RS
+.B Add.
+Set the mark. Should return 0 unless there's an error.
+.RE
+
+.B -r
+.RS
+.B Remove.
+Reset the mark. Should return 0 unless there's an error.
+.RE
+
+.BI -t timeout
+.RS
+.B Timeout.
+Set the timeout value for the \fB-w\fR option. Default is 60 seconds.
+.RE
+
+.B -w
+.RS
+.B Wait.
+Wait for mark to be reset. Should return 0 unless there's an error.
+.RE
+
+Without -a or -r: return 0 if the mark has been set, or a non-zero value
+otherwise.
+
+.B -d
+.RS
+Print debug information to stderr.
+.RE
+
+.B -v
+.RS
+Verbose execution.
+.RE
+
+.B -h
+.RS
+Displays usage message.
+.RE
+
+.SH FILES
+.B /proc/sysvipc/sem
+.RS
+If set, the astribank should appear there with the ID 11211168 (0xAB11A0).
+Naturally the ID (or rather, the usage of a semaphore in the first place)
+is an implementation detail that may change.
+.RE
+
+.SH NOTES
+.B astribank_is_starting
+is used to mark the fact that an Astribank may be currently reenumerating
+(technically: distonnecting and connecting as a new USB device) after
+loading the firmware. Thus the script that loads the firmware
+(/usr/share/dahdi/xpp_fxloader) uses this utility to set the mark.
+
+The mark is reset by /usr/share/dahdi/waitfor_xpds , which is typically
+run by the DAHDI init script and waits for all Astribanks to finish
+loading.
+
+Q: Why do you use a semaphore?
+
+A: because, unlike the filesystem, it is writable at any given time.
+
+.SH BUGS
+Option ordering matter. The \fB-v\fR and \fB-d\fR options should preceed
+the actions (\fB-a\fR, \fB-r\fR and \fB-w\fR).
+The \fB-t\fItimeout\fR option should preceed the \fB-w\fR option.
+
+.SH SEE ALSO
+semctl(3)
+
+.SH AUTHOR
+This manual page was written by Tzafrir Cohen <tzafrir.cohen@xorcom.com> .
+Permission is granted to copy, distribute and/or modify this document under
+the terms of the GNU General Public License, Version 2 any
+later version published by the Free Software Foundation.
+
+On Debian systems, the complete text of the GNU General Public
+License can be found in /usr/share/common-licenses/GPL.
diff --git a/xpp/astribank_is_starting.c b/xpp/astribank_is_starting.c
new file mode 100644
index 0000000..578ea9b
--- /dev/null
+++ b/xpp/astribank_is_starting.c
@@ -0,0 +1,190 @@
+#define _GNU_SOURCE /* 2.3 and later will define this from autoconfig.h */
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <errno.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+static char *progname;
+static const key_t key_astribanks = 0xAB11A0;
+static int debug;
+static int verbose;
+static int timeout_seconds = 60;
+
+
+static void usage(void)
+{
+ fprintf(stderr, "Usage: %s [-d] [-t <seconds>] [-a|-r|-w]\n", progname);
+ exit(1);
+}
+
+static int absem_get(int createit)
+{
+ int flags = (createit) ? IPC_CREAT | 0644 : 0;
+ int absem;
+
+ if((absem = semget(key_astribanks, 1, flags)) < 0)
+ absem = -errno;
+ return absem;
+}
+
+static int absem_touch(void)
+{
+ int absem;
+
+ if((absem = absem_get(1)) < 0) {
+ perror(__FUNCTION__);
+ return absem;
+ }
+ if(semctl(absem, 0, SETVAL, 0) < 0) {
+ perror("SETVAL");
+ return -errno;
+ }
+ if(debug)
+ fprintf(stderr, "%s: touched absem\n", progname);
+ if(verbose)
+ printf("Astribanks initialization is starting\n");
+ return 0;
+}
+
+static int absem_remove(void)
+{
+ int absem;
+
+ if((absem = absem_get(0)) < 0) {
+ if(absem == -ENOENT) {
+ if(debug)
+ fprintf(stderr, "%s: absem already removed\n", progname);
+ return 0;
+ }
+ perror(__FUNCTION__);
+ return absem;
+ }
+ if(semctl(absem, 0, IPC_RMID, 0) < 0) {
+ perror("RMID");
+ return -errno;
+ }
+ if(debug)
+ fprintf(stderr, "%s: removed absem\n", progname);
+ if(verbose)
+ printf("Astribanks initialization is done\n");
+ return 0;
+}
+
+static int absem_wait(void)
+{
+ int absem;
+ struct sembuf sops;
+ long now;
+ long start_wait;
+ struct timespec timeout;
+
+ if((absem = absem_get(0)) < 0) {
+ perror(__FUNCTION__);
+ return absem;
+ }
+ sops.sem_num = 0;
+ sops.sem_op = -1;
+ sops.sem_flg = 0;
+ start_wait = time(NULL);
+ timeout.tv_sec = timeout_seconds;
+ timeout.tv_nsec = 0;
+ if(semtimedop(absem, &sops, 1, &timeout) < 0) {
+ switch(errno) {
+ case EIDRM: /* Removed -- OK */
+ break;
+ case EAGAIN: /* Timeout -- Report */
+ fprintf(stderr, "Astribanks waiting timed out\n");
+ return -errno;
+ default: /* Unexpected errors */
+ perror("semop");
+ return -errno;
+ }
+ /* fall-thgough */
+ }
+ now = time(NULL);
+ if(debug)
+ fprintf(stderr, "%s: waited on absem %ld seconds\n", progname, now - start_wait);
+ if(verbose)
+ printf("Finished after %ld seconds\n", now - start_wait);
+ return 0;
+}
+
+static int absem_detected(void)
+{
+ int absem;
+
+ if((absem = absem_get(0)) < 0) {
+ if(debug)
+ fprintf(stderr, "%s: absem does not exist\n", progname);
+ return absem;
+ }
+ if(debug)
+ fprintf(stderr, "%s: absem exists\n", progname);
+ if(verbose)
+ printf("Astribanks are initializing...\n");
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ const char options[] = "dvarwt:h";
+ int val;
+
+ progname = argv[0];
+ while (1) {
+ int c;
+ int t;
+
+ c = getopt (argc, argv, options);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'd':
+ debug++;
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case 't':
+ t = atoi(optarg);
+ if(t <= 0) {
+ fprintf(stderr,
+ "%s: -t expect a positive number of seconds: '%s'\n",
+ progname, optarg);
+ usage();
+ }
+ timeout_seconds = t;
+ break;
+ case 'a':
+ if((val = absem_touch()) < 0) {
+ fprintf(stderr, "%s: Add failed: %d\n", progname, val);
+ return 1;
+ }
+ return 0;
+ case 'r':
+ if((val = absem_remove()) < 0) {
+ fprintf(stderr, "%s: Remove failed: %d\n", progname, val);
+ return 1;
+ }
+ return 0;
+ case 'w':
+ if((val = absem_wait()) < 0) {
+ fprintf(stderr, "%s: Wait failed: %d\n", progname, val);
+ return 1;
+ }
+ return 0;
+ case 'h':
+ default:
+ fprintf(stderr, "Unknown option '%c'\n", c);
+ usage();
+ }
+ }
+ val = absem_detected();
+ return (val == 0) ? 0 : 1;
+}
diff --git a/xpp/twinstar_hook b/xpp/twinstar_hook
index e463218..6818c85 100755
--- a/xpp/twinstar_hook
+++ b/xpp/twinstar_hook
@@ -49,74 +49,25 @@ PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
set -e
-# 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
-SYSTEMCONF="$dahdi_conf/system.conf"
-
-TWS_DIR="/var/tmp"
-TWS_PREFIX="$TWS_DIR/twinstar-"
-LABELFILE="/sys/$DEVPATH/label"
export XBUS_SORT='SORT_LABEL'
-echo "starting($ACTION): setup from $XPPORDER_CONF" | $LOGGER
-STAMP="${TWS_PREFIX}${XBUS_NAME}"
-TWS_TOTAL=`sed -e 's/#.*//' -e '/^[ ]*$/d' -e 'y/\t/ /' "$XPPORDER_CONF" | wc -l`
-
case "$ACTION" in
online)
- if [ ! -f "$LABELFILE" ]; then
- echo "Missing labelfile '$LABELFILE'" | $LOGGER
- exit 1
- fi
- LABEL=`cat $LABELFILE`
- TWS_LINE=`awk "/^$LABEL/" $XPPORDER_CONF`
- if [ "$TWS_LINE" = "" ]; then
- echo "online($XBUS_NAME): '$LABEL' is not in '$XPPORDER_CONF'" | $LOGGER
- exit 1
- fi
- echo "$LABEL" > "$STAMP"
- HOW_MANY=`ls ${TWS_PREFIX}* | wc -l`
- echo "online($XBUS_NAME): $LABEL (${HOW_MANY}/${TWS_TOTAL})" | $LOGGER
+ echo "$ACTION($XBUS_NAME): " | $LOGGER
twinstar enable-wd
- if [ "$HOW_MANY" -eq "$TWS_TOTAL" ]; then
- echo "online: GOT ALL $TWS_TOTAL" | $LOGGER
- dahdi_registration on
- dahdi_registration 2>&1 | tr '\t' ' ' | $LOGGER
- echo "Using '$SYSTEMCONF'" 2>&1 | $LOGGER
- dahdi_cfg -v -c "$SYSTEMCONF" 2>&1 | $LOGGER
- sleep 1 # Just for visual effect
- asterisk -rx 'module load chan_dahdi.so' 2>&1 | $LOGGER
- xpp_blink bzzt xpd "$XBUS_NUM"
- ports=`twinstar ports`
- if [ "$ports" = 0 ]; then
- play /usr/share/dahdi/primary-pbx-is-ready.wav || :
- elif [ "$ports" = 1 ]; then
- play /usr/share/dahdi/backup-pbx-is-ready.wav || :
- fi
- echo "online: READY" | $LOGGER
+ sleep 1 # Just for visual effect
+ asterisk -rx 'module load chan_dahdi.so' 2>&1 | $LOGGER
+ xpp_blink bzzt xpd "$XBUS_NUM"
+ ports=`twinstar ports`
+ if [ "$ports" = 0 ]; then
+ play /usr/share/dahdi/primary-pbx-is-ready.wav || :
+ elif [ "$ports" = 1 ]; then
+ play /usr/share/dahdi/backup-pbx-is-ready.wav || :
fi
+ echo "online: READY" | $LOGGER
;;
offline)
- LABEL=`cat $STAMP`
- TWS_LINE=`awk "/^$LABEL/" $XPPORDER_CONF`
- rm -f "$STAMP"
- if [ "$TWS_LINE" = "" ]; then
- echo "offline($XBUS_NAME): $LABEL is not in $XPPORDER_CONF" | $LOGGER
- exit 1
- fi
- echo "offline($XBUS_NAME): $LABEL" | $LOGGER
+ echo "$ACTION($XBUS_NAME): " | $LOGGER
twinstar disable-wd
# If we want to disconnect everybody
twinstar jump
diff --git a/xpp/waitfor_xpds b/xpp/waitfor_xpds
index 71b7dfc..6bee5f2 100755
--- a/xpp/waitfor_xpds
+++ b/xpp/waitfor_xpds
@@ -29,6 +29,8 @@ set -e
mydir=`dirname $0`
PATH="${mydir}:${PATH}"
+[ -r /etc/dahdi/init.conf ] && . /etc/dahdi/init.conf
+
ab_list() {
# Only check /sys info (don't use /proc anymore).
ab=`find /sys/bus/astribanks/devices/xbus-*/ -name waitfor_xpds 2> /dev/null || :`
@@ -40,7 +42,14 @@ if ! dahdi_hardware="`which dahdi_hardware 2>/dev/null`"; then
echo >&2 "$0: Missing dahdi_hardware"
exit 0
fi
-if [ "`$dahdi_hardware | grep xpp_usb`" = "" ]; then
+if ! astribank_is_starting="`which astribank_is_starting 2>/dev/null`"; then
+ echo >&2 "$0: Missing astribank_is_starting"
+ exit 0
+fi
+if [ "`$dahdi_hardware | grep xpp_usb`" != "" ]; then
+ astribank_is_starting -v -a
+fi
+if ! astribank_is_starting; then
exit 0
fi
@@ -60,7 +69,7 @@ done
echo ""
# Wait for device to stabilize and XPD's to finish initalizations
-echo 1>&2 "Astribanks initalization "
+echo 1>&2 "Astribanks initializing spans"
while
if ! ab=`ab_list`; then
exit 1
@@ -70,3 +79,14 @@ do
oldab="$ab"
cat $ab
done
+
+if [ "$XPP_HOTPLUG_DAHDI" = yes ]; then
+ if [ "$CALLED_FROM_ATRIBANK_HOOK" = '' ]; then
+ # Now we can wait until the hotplug run would remove the semaphore
+ echo -n 1>&2 "Other DAHDI initializations... "
+ astribank_is_starting -v -w 1>&2
+ fi
+else
+ # Non-hotplug -- Sequential initialization, remove semaphore
+ astribank_is_starting -v -r 1>&2
+fi
diff --git a/xpp/xpp_fxloader b/xpp/xpp_fxloader
index 2f42126..790b0fd 100644
--- a/xpp/xpp_fxloader
+++ b/xpp/xpp_fxloader
@@ -262,6 +262,9 @@ usage() {
echo "$0 help : this text."
}
+# We have a potential astribank
+astribank_is_starting -a
+
#########################
##
## Manual run