From 89ac10bd536ce111d58d924e73e260ac7f125dc2 Mon Sep 17 00:00:00 2001 From: sky Date: Sat, 14 Dec 2024 00:49:38 +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 | 22 ++++++--------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/simpleadmin/console/menu/change_hostname.sh b/simpleadmin/console/menu/change_hostname.sh index 52708f3..ede205f 100644 --- a/simpleadmin/console/menu/change_hostname.sh +++ b/simpleadmin/console/menu/change_hostname.sh @@ -35,35 +35,25 @@ 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 the hostname service +# Create the hostname service with sleep cat > /lib/systemd/system/set-hostname.service << EOF [Unit] Description=Set system hostname +After=network.target [Service] Type=oneshot +ExecStartPre=/bin/sleep 30 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 -After=network.target -Requires=network.target - -[Timer] -OnBootSec=30sec -Unit=set-hostname.service [Install] -WantedBy=timers.target +WantedBy=multi-user.target EOF systemctl daemon-reload -systemctl enable set-hostname.timer -systemctl start set-hostname.timer +systemctl enable set-hostname.service +systemctl start set-hostname.service remount_ro