Add service to config hostname based on configdb (#1174)
This commit is contained in:
parent
6d0329af3d
commit
617b3e43b1
@ -120,6 +120,11 @@ sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT/usr/share/sonic/template
|
||||
# Copy initial interfaces configuration file, will be overwritten on first boot
|
||||
sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network
|
||||
|
||||
# Copy hostname configuration scripts
|
||||
sudo cp $IMAGE_CONFIGS/hostname/hostname-config.service $FILESYSTEM_ROOT/etc/systemd/system/
|
||||
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable hostname-config.service
|
||||
sudo cp $IMAGE_CONFIGS/hostname/hostname-config.sh $FILESYSTEM_ROOT/usr/bin/
|
||||
|
||||
# Copy updategraph script and service file
|
||||
sudo cp $IMAGE_CONFIGS/updategraph/updategraph.service $FILESYSTEM_ROOT/etc/systemd/system/
|
||||
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable updategraph.service
|
||||
|
11
files/image_config/hostname/hostname-config.service
Normal file
11
files/image_config/hostname/hostname-config.service
Normal file
@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Update hostname based on configdb
|
||||
Requires=database.service
|
||||
After=database.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/hostname-config.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
11
files/image_config/hostname/hostname-config.sh
Executable file
11
files/image_config/hostname/hostname-config.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
CURRENT_HOSTNAME=`hostname`
|
||||
HOSTNAME=`sonic-cfggen -d -v DEVICE_METADATA[\'localhost\'][\'hostname\']`
|
||||
|
||||
echo $HOSTNAME > /etc/hostname
|
||||
hostname -F /etc/hostname
|
||||
|
||||
sed -i "/\s$CURRENT_HOSTNAME$/d" /etc/hosts
|
||||
echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
|
||||
|
Loading…
Reference in New Issue
Block a user