[svn-commits] tzafrir: tools/trunk r7335 - in /tools/trunk: ./ xpp/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Oct 4 08:53:12 CDT 2009


Author: tzafrir
Date: Sun Oct  4 08:53:01 2009
New Revision: 7335

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=7335
Log:
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')

Modified:
    tools/trunk/dahdi.init
    tools/trunk/init.conf.sample
    tools/trunk/xpp/astribank_hook
    tools/trunk/xpp/twinstar_hook

Modified: tools/trunk/dahdi.init
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/dahdi.init?view=diff&rev=7335&r1=7334&r2=7335
==============================================================================
--- tools/trunk/dahdi.init (original)
+++ tools/trunk/dahdi.init Sun Oct  4 08:53:01 2009
@@ -86,10 +86,33 @@
 	rmmod $module
 }
 
+# In (xpp) hotplug mode, if we're called from udev, skip loading
+# modules:
+hotplug_skip_modprobe() {
+	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.
+# Make sure that this is only called if there is an Astribank on the
+# system, which will call the rest of the script from the
+# astribank_hook.
+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.
@@ -184,7 +207,9 @@
 # See how we were called.
 case "$1" in
   start)
-  	load_modules
+  	if ! hotplug_skip_modprobe; then
+		load_modules
+	fi
 
 	TMOUT=$DAHDI_DEV_TIMEOUT # max secs to wait
 

Modified: tools/trunk/init.conf.sample
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/init.conf.sample?view=diff&rev=7335&r1=7334&r2=7335
==============================================================================
--- tools/trunk/init.conf.sample (original)
+++ tools/trunk/init.conf.sample Sun Oct  4 08:53:01 2009
@@ -11,3 +11,4 @@
 # Override settings for xpp_fxloader
 #XPP_FIRMWARE_DIR=/usr/share/dahdi
 #XPP_HOTPLUG_DISABLED=yes
+#XPP_HOTPLUG_DAHDI=yes

Modified: tools/trunk/xpp/astribank_hook
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/astribank_hook?view=diff&rev=7335&r1=7334&r2=7335
==============================================================================
--- tools/trunk/xpp/astribank_hook (original)
+++ tools/trunk/xpp/astribank_hook Sun Oct  4 08:53:01 2009
@@ -11,11 +11,69 @@
 ## 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 @@
 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
 	;;
 *)

Modified: tools/trunk/xpp/twinstar_hook
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/twinstar_hook?view=diff&rev=7335&r1=7334&r2=7335
==============================================================================
--- tools/trunk/xpp/twinstar_hook (original)
+++ tools/trunk/xpp/twinstar_hook Sun Oct  4 08:53:01 2009
@@ -49,74 +49,25 @@
 
 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
+	echo "$ACTION($XBUS_NAME): " | $LOGGER
+	twinstar enable-wd
+	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
-	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
-	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
-	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




More information about the svn-commits mailing list