a7cad9091640baa2f66ba6920423a52ac0b2a35d
[osm/riftware.git] /
1 #!/bin/bash
2 # Reconfigures an all-in-one image to use a new home domain and number range.
3 # Usage: reconfigure-aio <home-domain> [<base-number> <number-count>]
4
5 # Get command-line arguments.
6 home_domain=$1
7 base_number=$2
8 number_count=$3
9
10 if [ -z "$home_domain" ] ; then
11   echo "Usage: reconfigure-aio <home-domain> [<base-number> <number-count>]"
12 fi
13
14 # Remove all old numbers from the database, unless they're currently assigned.
15 # We do this even if the home domain hasn't changed, because the number range might have done (and
16 # it's hard to tell if that's happened, and cheap/low-impact to just do the reprovisioning).
17 old_home_domain=$(. /etc/clearwater/config ; echo $home_domain)
18 echo "DELETE FROM ellis.numbers WHERE number LIKE '%@$old_home_domain' AND owner_id IS NULL ;" | mysql
19
20 # Update /etc/clearwater/shared_config, if the home domain has changed.
21 if [ "$home_domain" != "$old_home_domain" ] ; then
22   function escape { echo $1 | sed -e 's/\//\\\//g' ; }
23   sed -e 's/^home_domain=.*$/home_domain='$(escape $home_domain)'/g' \
24       </etc/clearwater/shared_config >/tmp/shared_config.$$
25   mv /tmp/shared_config.$$ /etc/clearwater/shared_config
26   
27   # Restart clearwater-infrastructure to propagate changes to other configuration files.
28   service clearwater-infrastructure restart
29 fi
30
31 # Create new numbers in the new domain, if we've been asked to.
32 if [ -n "$base_number" ] && [ -n "$number_count" ] ; then
33   /usr/share/clearwater/ellis/env/bin/python /usr/share/clearwater/ellis/src/metaswitch/ellis/tools/create_numbers.py --start $base_number --count $number_count
34 fi
35
36 # Restart all the components, if the home domain has changed.
37 if [ "$home_domain" != "$old_home_domain" ] ; then
38   # Work around https://github.com/Metaswitch/sprout/issues/1296.
39   service bono stop
40
41   # Restart all the processes.
42   for X in /usr/share/clearwater/infrastructure/scripts/restart/* ; do $X ; done
43
44   # Kick monit to wake up and sleep for 10 seconds to make sure it has an accurate view of the system.
45   monit
46   sleep 10
47
48   # Now wait until all the processes are back up and running (or at least "Uptime failed", which
49   # means the process is running, just hasn't been running for very long).
50   while monit summary | grep _process | egrep -v "(Running|Uptime failed)" ; do
51     echo Some processes still not running - waiting...
52     sleep 2
53   done
54   echo All processes running - configuration complete!
55 fi