From 1d61b5e9f0faafca3d385d5ea26f37362ee6cd68 Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 13 Dec 2024 23:41:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20simpleadmin/console/menu/c?= =?UTF-8?q?hange=5Fhostname.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simpleadmin/console/menu/change_hostname.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/simpleadmin/console/menu/change_hostname.sh b/simpleadmin/console/menu/change_hostname.sh index 3e47d08..3012e67 100644 --- a/simpleadmin/console/menu/change_hostname.sh +++ b/simpleadmin/console/menu/change_hostname.sh @@ -35,24 +35,33 @@ echo "$new_hostname" > /etc/hostname sed -i "s/127.0.1.1.*$/127.0.1.1\t$new_hostname/g" /etc/hosts hostname "$new_hostname" -# Create and enable the hostname service +# Create the hostname service cat > /lib/systemd/system/set-hostname.service << EOF [Unit] -Description=Set system hostname at boot +Description=Set system hostname [Service] Type=oneshot -ExecStartPre=/bin/sleep 10 ExecStart=/bin/sh -c 'hostname \$(cat /etc/hostname)' RemainAfterExit=yes +EOF + +# Create the hostname timer +cat > /lib/systemd/system/set-hostname.timer << EOF +[Unit] +Description=Set hostname 30 seconds after boot + +[Timer] +OnBootSec=30sec +Unit=set-hostname.service [Install] -WantedBy=multi-user.target +WantedBy=timers.target EOF systemctl daemon-reload -systemctl enable set-hostname.service -systemctl start set-hostname.service +systemctl enable set-hostname.timer +systemctl start set-hostname.timer remount_ro