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>]
5 # Get command-line arguments.
10 if [ -z "$home_domain" ] ; then
11 echo "Usage: reconfigure-aio <home-domain> [<base-number> <number-count>]"
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
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
27 # Restart clearwater-infrastructure to propagate changes to other configuration files.
28 service clearwater-infrastructure restart
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
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.
41 # Restart all the processes.
42 for X in /usr/share/clearwater/infrastructure/scripts/restart/* ; do $X ; done
44 # Kick monit to wake up and sleep for 10 seconds to make sure it has an accurate view of the system.
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...
54 echo All processes running - configuration complete!