File tree 3 files changed +25
-3
lines changed
3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"INSTANCES": {
3
3
"redis":{
4
- "hostname" : "127.0.0.1 ",
4
+ "hostname" : "{{HOST_IP}} ",
5
5
"port" : 6379,
6
6
"unix_socket_path" : "/var/run/redis{{NAMESPACE_ID}}/redis.sock",
7
7
"persistence_for_warm_boot" : "yes"
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
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
+
3
20
REDIS_DIR=/var/run/redis$NAMESPACE_ID
4
21
mkdir -p $REDIS_DIR /sonic-db
5
22
6
23
if [ -f /etc/sonic/database_config$NAMESPACE_ID .json ]; then
7
24
cp /etc/sonic/database_config$NAMESPACE_ID .json $REDIS_DIR /sonic-db/database_config.json
8
25
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
10
27
fi
11
28
12
29
mkdir -p /etc/supervisor/conf.d/
Original file line number Diff line number Diff line change @@ -20,7 +20,12 @@ stderr_logfile=syslog
20
20
{% if INSTANCES %}
21
21
{% for redis_inst , redis_items in INSTANCES .iteritems () %}
22
22
[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 }}"
24
29
priority=2
25
30
autostart=true
26
31
autorestart=false
You can’t perform that action at this time.
0 commit comments