Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for connecting to DB in namespace via TCP port in multi-asic platform. #4779

Merged
merged 5 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dockers/docker-database/database_config.json.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"INSTANCES": {
"redis":{
"hostname" : "127.0.0.1",
"hostname" : "{{HOST_IP}}",
"port" : 6379,
"unix_socket_path" : "/var/run/redis{{NAMESPACE_ID}}/redis.sock",
"persistence_for_warm_boot" : "yes"
Expand Down
23 changes: 22 additions & 1 deletion dockers/docker-database/docker-database-init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
#!/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
judyjoseph marked this conversation as resolved.
Show resolved Hide resolved
else
INTFC=eth0
LOOPBACK_IP=127.0.0.1
fi
local_ip=$(ip -4 -o addr show $INTFC | awk '{print $4}' | cut -d'/' -f1 | head -1)

# if the ip address was not retrieved correctly, put the loopbackIP as the default.
if [[ $local_ip == "" ]]
then
local_ip=127.0.0.1
fi
export HOST_IP=$local_ip

REDIS_DIR=/var/run/redis$NAMESPACE_ID
mkdir -p $REDIS_DIR/sonic-db

Expand All @@ -22,6 +40,9 @@ then
fi

# generate all redis server supervisord configuration file
sonic-cfggen -j /var/run/redis/sonic-db/database_config.json -t /usr/share/sonic/templates/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf
# Pass the Loopback IP explicitly in case of namespaces other than the linux host namespace.
# This is needed as there are applications who hardcoded host=loopback IP in Connector classes.
# Redis server will then bind on multiple IP addresses viz <loopback ip> , <eth0 ip>
sonic-cfggen -j /var/run/redis/sonic-db/database_config.json -a "{\"LOOPBACK_IP\":\"$LOOPBACK_IP\"}" -t /usr/share/sonic/templates/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf
judyjoseph marked this conversation as resolved.
Show resolved Hide resolved

exec /usr/bin/supervisord
2 changes: 1 addition & 1 deletion dockers/docker-database/supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ stderr_logfile=syslog
{% if INSTANCES %}
{% for redis_inst, redis_items in INSTANCES.iteritems() %}
[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 }}"
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 }}"
judyjoseph marked this conversation as resolved.
Show resolved Hide resolved
judyjoseph marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wonder is there any case both LOOPBACK_IP and HOST_IP are empty, if there is a case , the --bind without parameter will work or NOT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case should not happen as the LOOPBACK_IP is hardcoded to 127.0.0.1 , the HOST_IP is either 127.0.0.1 ( in case of linux host namespace ) or the docker0 IP address in case of namespaces. But I can add the the default fallback IP of 127.0.0.1, if this error scenario arises.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code, so that if we are not able to get the ip address correctly from interface, it is set to loopback ip 127.0.0.1 as the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dzhangalibaba let me know it this was ok ?

priority=2
autostart=true
autorestart=false
Expand Down