更新 simpleadmin/console/menu/change_hostname.sh

This commit is contained in:
sky 2024-12-14 00:55:55 +08:00
parent 89ac10bd53
commit 63e7def498

View File

@ -35,17 +35,22 @@ 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 with sleep
# Create the hostname service
cat > /lib/systemd/system/set-hostname.service << EOF
[Unit]
Description=Set system hostname
After=network.target
After=network.target network-online.target
Wants=network-online.target
After=multi-user.target
After=systemd-user-sessions.service
[Service]
Type=oneshot
ExecStartPre=/bin/sleep 30
ExecStart=/bin/sh -c 'hostname \$(cat /etc/hostname)'
RemainAfterExit=yes
StartLimitIntervalSec=300
StartLimitBurst=3
[Install]
WantedBy=multi-user.target