更新 simpleadmin/console/menu/change_hostname.sh
This commit is contained in:
parent
b0ea5ffa95
commit
89ac10bd53
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user