Skip to content

Commit a80683d

Browse files
judyjosephabdosi
authored andcommitted
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.
1 parent fad2d47 commit a80683d

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

dockers/docker-database/database_config.json.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"INSTANCES": {
33
"redis":{
4-
"hostname" : "127.0.0.1",
4+
"hostname" : "{{HOST_IP}}",
55
"port" : 6379,
66
"unix_socket_path" : "/var/run/redis{{NAMESPACE_ID}}/redis.sock",
77
"persistence_for_warm_boot" : "yes"

dockers/docker-database/docker-database-init.sh

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
#!/usr/bin/env bash
22

3+
# For linux host namespace, in both single and multi ASIC platform use the loopback interface
4+
# For other namespaces, use eth0 interface which is connected to the docker0 bridge in the host.
5+
if [[ $NAMESPACE_ID == "" ]]
6+
then
7+
INTFC=lo
8+
else
9+
INTFC=eth0
10+
fi
11+
12+
# Get the ip address of the interface
13+
# if the ip address was not retrieved correctly, put localhost(127.0.0.1) as the default.
14+
host_ip=$(ip -4 -o addr show $INTFC | awk '{print $4}' | cut -d'/' -f1 | head -1)
15+
if [[ $host_ip == "" ]]
16+
then
17+
host_ip=127.0.0.1
18+
fi
19+
320
REDIS_DIR=/var/run/redis$NAMESPACE_ID
421
mkdir -p $REDIS_DIR/sonic-db
522

623
if [ -f /etc/sonic/database_config$NAMESPACE_ID.json ]; then
724
cp /etc/sonic/database_config$NAMESPACE_ID.json $REDIS_DIR/sonic-db/database_config.json
825
else
9-
j2 /usr/share/sonic/templates/database_config.json.j2 > $REDIS_DIR/sonic-db/database_config.json
26+
HOST_IP=$host_ip j2 /usr/share/sonic/templates/database_config.json.j2 > $REDIS_DIR/sonic-db/database_config.json
1027
fi
1128

1229
mkdir -p /etc/supervisor/conf.d/

dockers/docker-database/supervisord.conf.j2

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ stderr_logfile=syslog
2020
{% if INSTANCES %}
2121
{% for redis_inst, redis_items in INSTANCES.iteritems() %}
2222
[program: {{ redis_inst }}]
23-
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 }}"
23+
{% if redis_items['hostname'] != '127.0.0.1' %}
24+
{%- set LOOPBACK_IP = '127.0.0.1' -%}
25+
{%- else -%}
26+
{%- set LOOPBACK_IP = '' -%}
27+
{%- endif -%}
28+
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 }}"
2429
priority=2
2530
autostart=true
2631
autorestart=false

0 commit comments

Comments
 (0)