diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index da7ad28b546..db00e79f498 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -183,6 +183,11 @@ sudo cp $IMAGE_CONFIGS/hostname/hostname-config.service $FILESYSTEM_ROOT/etc/sy sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable hostname-config.service sudo cp $IMAGE_CONFIGS/hostname/hostname-config.sh $FILESYSTEM_ROOT/usr/bin/ +# Copy timezone configuration scripts +sudo cp $IMAGE_CONFIGS/timezone/timezone-config.service $FILESYSTEM_ROOT/etc/systemd/system/ +sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable timezone-config.service +sudo cp $IMAGE_CONFIGS/timezone/timezone-config.sh $FILESYSTEM_ROOT/usr/bin/ + # Copy updategraph script and service file j2 files/build_templates/updategraph.service.j2 | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/updategraph.service sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable updategraph.service diff --git a/files/image_config/timezone/timezone-config.service b/files/image_config/timezone/timezone-config.service new file mode 100644 index 00000000000..c1c4d547716 --- /dev/null +++ b/files/image_config/timezone/timezone-config.service @@ -0,0 +1,11 @@ +[Unit] +Description=Update timezone based on configdb +Requires=updategraph.service +After=updategraph.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/timezone-config.sh + +[Install] +WantedBy=multi-user.target diff --git a/files/image_config/timezone/timezone-config.sh b/files/image_config/timezone/timezone-config.sh new file mode 100755 index 00000000000..86e2c3841a3 --- /dev/null +++ b/files/image_config/timezone/timezone-config.sh @@ -0,0 +1,12 @@ +#!/bin/bash -e + +CURRENT_TIMEZONE=`cat /etc/timezone` +TIMEZONE=`sonic-cfggen -d -v DEVICE_METADATA[\'localhost\'][\'timezone\']` + +if [ -n "$TIMEZONE" ] +then + sudo bash -c "echo $TIMEZONE > /etc/timezone" + sudo bash -c "dpkg-reconfigure -f noninteractive tzdata" + sudo bash -c "systemctl restart rsyslog" + sudo bash -c "systemctl restart cron" +fi