Skip to content

[hostname-config] improve hostname-config process #3676

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

Merged
merged 1 commit into from
Oct 29, 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
10 changes: 8 additions & 2 deletions files/image_config/hostname/hostname-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ hostname -F /etc/hostname

# Remove the old hostname entry from hosts file.
# But, 'localhost' entry is used by multiple applications. Don't remove it altogether.
# Edit contents of /etc/hosts and put in /etc/hosts.new
if [ $CURRENT_HOSTNAME != "localhost" ] || [ $CURRENT_HOSTNAME == $HOSTNAME ] ; then
sed -i "/\s$CURRENT_HOSTNAME$/d" /etc/hosts
sed "/\s$CURRENT_HOSTNAME$/d" /etc/hosts > /etc/hosts.new
else
cp -f /etc/hosts /etc/hosts.new
fi

echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
echo "127.0.0.1 $HOSTNAME" >> /etc/hosts.new

# Swap file: hosts.new and hosts
mv -f /etc/hosts /etc/hosts.old
mv -f /etc/hosts.new /etc/hosts