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

[snmp] Configure snmp docker hostname from config DB #2773

Merged
merged 2 commits into from
Apr 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dockers/docker-snmp-sv2/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ sonic-cfggen -d -y /etc/sonic/snmp.yml -t /usr/share/sonic/templates/snmpd.conf.
mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status

CURRENT_HOSTNAME=`hostname`
HOSTNAME=`sonic-cfggen -d -v DEVICE_METADATA[\'localhost\'][\'hostname\']`
Copy link
Collaborator

@qiluo-msft qiluo-msft Apr 13, 2019

Choose a reason for hiding this comment

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

HOSTNAME [](start = 0, length = 8)

Will you handle command error or empty hostname cases? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HOSTNAME [](start = 0, length = 8)

Will you handle command error or empty hostname cases?

Added validation. Please check.


if [ "$?" == "0" ] && [ "$HOSTNAME" != "" ]; then
echo $HOSTNAME > /etc/hostname
hostname -F /etc/hostname

sed -i "/\s$CURRENT_HOSTNAME$/d" /etc/hosts
Copy link
Collaborator

Choose a reason for hiding this comment

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

sed -i "/\s$CURRENT_HOSTNAME$/d" /etc/hosts [](start = 4, length = 43)

This line does not work inside docker container.
ref: http://blog.jonathanargentiero.com/docker-sed-cannot-rename-etcsedl8ysxl-device-or-resource-busy/

Could you double check and fix?

echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
fi

rm -f /var/run/rsyslogd.pid

supervisorctl start rsyslogd
Expand Down