summaryrefslogtreecommitdiff
path: root/xpp/twinstar_hook
blob: 712d5722098a0b345265eeb1b93805df31515525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /bin/sh
#
# twinstar_hook: Example twinstar-specific hook script
# $Id$
#
# Written by Oron Peled <oron@actcom.co.il>
# Copyright (C) 2009, Xorcom
#
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

#
# This is an experimental script to activate an Astribank TwinStar
# during failover.
#
# The script assume that there is an /etc/dahdi/xpp_order file
# specifying the Astribanks' labels according to the required
# registration order.
#
# This file can be easily generated by running:
#    dahdi_genconf xpporder
# after the system is configured and working.
#

me=`basename $0`
dir=`dirname $0`
LOGGER="logger -i -t '$me'"

# Always redirect stderr somewhere, otherwise the shell script will die
# when it tries to do I/O related stuff on closed file descriptor.
# Our default is to throw it down the bit-bucket.
#exec 2> /dev/console
## 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

export XBUS_SORT='SORT_LABEL'

case "$ACTION" in
online)
	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
	echo "online: READY" | $LOGGER
	;;
offline)
	echo "$ACTION($XBUS_NAME): " | $LOGGER
	twinstar disable-wd
	# If we want to disconnect everybody
	twinstar jump
	asterisk -rx 'module unload chan_dahdi.so'
	;;
*)
	echo "$0: Unknown ACTION='$ACTION'" | $LOGGER
	echo "$0: ARGS='$*'" | $LOGGER
	echo "$0: ENV:" | $LOGGER
	env | $LOGGER
	exit 1
esac