更新 simpleadmin/console/menu/change_hostname.sh

This commit is contained in:
sky 2024-12-13 23:41:42 +08:00
parent b5753d448c
commit 1d61b5e9f0

View File

@ -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