Ivan Berezovskiy | c46e7c0 | 2018-10-29 18:22:09 +0400 | [diff] [blame] | 1 | #!/bin/sh -e |
| 2 | # |
| 3 | # rc.local |
| 4 | # |
| 5 | # This script is executed at the end of each multiuser runlevel. |
| 6 | # Make sure that the script will "exit 0" on success or any other |
| 7 | # value on error. |
| 8 | # |
| 9 | # In order to enable or disable this script just change the execution |
| 10 | # bits. |
| 11 | # |
| 12 | # By default this script does nothing. |
| 13 | |
Denis Egorenko | 88f1cf5 | 2019-05-24 11:04:01 +0400 | [diff] [blame] | 14 | update_from_metadata_fields() { |
| 15 | local metadataIp="169.254.169.254" |
| 16 | local metadataFiels=$(curl -s --connect-timeout 5 169.254.169.254/openstack/latest/meta_data.json | jq -r .meta) |
| 17 | if [ -n "${metadataFiels}" ]; then |
| 18 | local dmz=$(echo ${metadataFiels} | jq -r .dmz) |
| 19 | if [ "${dmz}" == "true" ] |
| 20 | local dmzGateway=$(echo ${metadataFiels} | jq -r .dmz_gateway) |
| 21 | if [ -n "${dmzGateway}" ]; then |
| 22 | local curDefault=$(ip r | grep 'default via' | cut -f 3 -d ' ') |
| 23 | if [ "${curDefault}" != "${dmzGateway}" ]; then |
| 24 | ip r del default |
| 25 | ip r add default via ${dmzGateway} |
| 26 | fi |
| 27 | fi |
| 28 | fi |
| 29 | fi |
| 30 | } |
| 31 | |
Ivan Berezovskiy | c46e7c0 | 2018-10-29 18:22:09 +0400 | [diff] [blame] | 32 | if [ ! -f /tmp/bootstrap_interfaces ] && [ -d /srv/salt/reclass/nodes/_generated ]; then |
| 33 | sed -i "s/single_address:.*/single_address: $(hostname -I | cut -d ' ' -f 1)/g" /srv/salt/reclass/nodes/cfg01.* |
| 34 | touch /tmp/bootstrap_interfaces |
| 35 | fi |
| 36 | |
Denis Egorenko | 88f1cf5 | 2019-05-24 11:04:01 +0400 | [diff] [blame] | 37 | update_from_metadata_fields || echo "Can't update settings from metadata fields" |
| 38 | |
Ivan Berezovskiy | c46e7c0 | 2018-10-29 18:22:09 +0400 | [diff] [blame] | 39 | exit 0 |