Debian Codegraph @

xpp/twinstar_hook

raw
1 #! /bin/sh
2 #
3 # twinstar_hook: Example twinstar-specific hook script
4 # $Id$
5 #
6 # Written by Oron Peled <[email protected]>
7 # Copyright (C) 2009, Xorcom
8 #
9 # All rights reserved.
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #
25
26 #
27 # This is an experimental script to activate an Astribank TwinStar
28 # during failover.
29 #
30 # The script assume that there is an /etc/dahdi/xpp_order file
31 # specifying the Astribanks' labels according to the required
32 # registration order.
33 #
34 # This file can be easily generated by running:
35 # dahdi_genconf xpporder
36 # after the system is configured and working.
37 #
38
39 me=`basename $0`
40 dir=`dirname $0`
41 LOGGER="logger -i -t '$me'"
42
43 # Always redirect stderr somewhere, otherwise the shell script will die
44 # when it tries to do I/O related stuff on closed file descriptor.
45 # Our default is to throw it down the bit-bucket.
46 #exec 2> /dev/console
47 ## If you wish to trace this script:
48 #exec 2> "/tmp/${me}_$XBUS_NAME" 1>&2
49
50 # Our directory in the beginning, so we can use local lab setup
51 PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
52
53 set -e
54
55 export XBUS_SORT='SORT_LABEL'
56
57 case "$ACTION" in
58 online)
59 echo "$ACTION($XBUS_NAME): " | $LOGGER
60 twinstar enable-wd
61 sleep 1 # Just for visual effect
62 asterisk -rx 'module load chan_dahdi.so' 2>&1 | $LOGGER
63 xpp_blink bzzt xpd "$XBUS_NUM"
64 ports=`twinstar ports`
65 if [ "$ports" = 0 ]; then
66 play /usr/share/dahdi/primary-pbx-is-ready.wav || :
67 elif [ "$ports" = 1 ]; then
68 play /usr/share/dahdi/backup-pbx-is-ready.wav || :
69 fi
70 echo "online: READY" | $LOGGER
71 ;;
72 offline)
73 echo "$ACTION($XBUS_NAME): " | $LOGGER
74 twinstar disable-wd
75 # If we want to disconnect everybody
76 twinstar jump
77 asterisk -rx 'module unload chan_dahdi.so'
78 ;;
79 *)
80 echo "$0: Unknown ACTION='$ACTION'" | $LOGGER
81 echo "$0: ARGS='$*'" | $LOGGER
82 echo "$0: ENV:" | $LOGGER
83 env | $LOGGER
84 exit 1
85 esac
86