Support for connecting to DB in namespace via TCP port in multi-asic platform. (#4779)
* Support for connecting to DB in namespace via IP:port ( using docker bridge network ) for applications in multi-asic platform. * Added the default IP as 127.0.0.1 if the IPaddress derivation from interface fails. Moved the localhost loopback IP binding logic into the supervisor.j2 file.
This commit is contained in:
parent
0921e3d6ff
commit
1af68b3aa6
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"INSTANCES": {
|
"INSTANCES": {
|
||||||
"redis":{
|
"redis":{
|
||||||
"hostname" : "127.0.0.1",
|
"hostname" : "{{HOST_IP}}",
|
||||||
"port" : 6379,
|
"port" : 6379,
|
||||||
"unix_socket_path" : "/var/run/redis{{NAMESPACE_ID}}/redis.sock",
|
"unix_socket_path" : "/var/run/redis{{NAMESPACE_ID}}/redis.sock",
|
||||||
"persistence_for_warm_boot" : "yes"
|
"persistence_for_warm_boot" : "yes"
|
||||||
|
@ -1,12 +1,29 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# For linux host namespace, in both single and multi ASIC platform use the loopback interface
|
||||||
|
# For other namespaces, use eth0 interface which is connected to the docker0 bridge in the host.
|
||||||
|
if [[ $NAMESPACE_ID == "" ]]
|
||||||
|
then
|
||||||
|
INTFC=lo
|
||||||
|
else
|
||||||
|
INTFC=eth0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get the ip address of the interface
|
||||||
|
# if the ip address was not retrieved correctly, put localhost(127.0.0.1) as the default.
|
||||||
|
host_ip=$(ip -4 -o addr show $INTFC | awk '{print $4}' | cut -d'/' -f1 | head -1)
|
||||||
|
if [[ $host_ip == "" ]]
|
||||||
|
then
|
||||||
|
host_ip=127.0.0.1
|
||||||
|
fi
|
||||||
|
|
||||||
REDIS_DIR=/var/run/redis$NAMESPACE_ID
|
REDIS_DIR=/var/run/redis$NAMESPACE_ID
|
||||||
mkdir -p $REDIS_DIR/sonic-db
|
mkdir -p $REDIS_DIR/sonic-db
|
||||||
|
|
||||||
if [ -f /etc/sonic/database_config$NAMESPACE_ID.json ]; then
|
if [ -f /etc/sonic/database_config$NAMESPACE_ID.json ]; then
|
||||||
cp /etc/sonic/database_config$NAMESPACE_ID.json $REDIS_DIR/sonic-db/database_config.json
|
cp /etc/sonic/database_config$NAMESPACE_ID.json $REDIS_DIR/sonic-db/database_config.json
|
||||||
else
|
else
|
||||||
j2 /usr/share/sonic/templates/database_config.json.j2 > $REDIS_DIR/sonic-db/database_config.json
|
HOST_IP=$host_ip j2 /usr/share/sonic/templates/database_config.json.j2 > $REDIS_DIR/sonic-db/database_config.json
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p /etc/supervisor/conf.d/
|
mkdir -p /etc/supervisor/conf.d/
|
||||||
|
@ -20,7 +20,12 @@ stderr_logfile=syslog
|
|||||||
{% if INSTANCES %}
|
{% if INSTANCES %}
|
||||||
{% for redis_inst, redis_items in INSTANCES.iteritems() %}
|
{% for redis_inst, redis_items in INSTANCES.iteritems() %}
|
||||||
[program: {{ redis_inst }}]
|
[program: {{ redis_inst }}]
|
||||||
command=/bin/bash -c "{ [[ -s /var/lib/{{ redis_inst }}/dump.rdb ]] || rm -f /var/lib/{{ redis_inst }}/dump.rdb; } && mkdir -p /var/lib/{{ redis_inst }} && exec /usr/bin/redis-server /etc/redis/redis.conf --port {{ redis_items['port'] }} --unixsocket {{ redis_items['unix_socket_path'] }} --pidfile /var/run/redis/{{ redis_inst }}.pid --dir /var/lib/{{ redis_inst }}"
|
{% if redis_items['hostname'] != '127.0.0.1' %}
|
||||||
|
{%- set LOOPBACK_IP = '127.0.0.1' -%}
|
||||||
|
{%- else -%}
|
||||||
|
{%- set LOOPBACK_IP = '' -%}
|
||||||
|
{%- endif -%}
|
||||||
|
command=/bin/bash -c "{ [[ -s /var/lib/{{ redis_inst }}/dump.rdb ]] || rm -f /var/lib/{{ redis_inst }}/dump.rdb; } && mkdir -p /var/lib/{{ redis_inst }} && exec /usr/bin/redis-server /etc/redis/redis.conf --bind {{ LOOPBACK_IP }} {{ redis_items['hostname'] }} --port {{ redis_items['port'] }} --unixsocket {{ redis_items['unix_socket_path'] }} --pidfile /var/run/redis/{{ redis_inst }}.pid --dir /var/lib/{{ redis_inst }}"
|
||||||
priority=2
|
priority=2
|
||||||
autostart=true
|
autostart=true
|
||||||
autorestart=false
|
autorestart=false
|
||||||
|
Reference in New Issue
Block a user