更新 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
|
sed -i "s/127.0.1.1.*$/127.0.1.1\t$new_hostname/g" /etc/hosts
|
||||||
hostname "$new_hostname"
|
hostname "$new_hostname"
|
||||||
|
|
||||||
# Create the hostname service
|
# Create the hostname service with sleep
|
||||||
cat > /lib/systemd/system/set-hostname.service << EOF
|
cat > /lib/systemd/system/set-hostname.service << EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Set system hostname
|
Description=Set system hostname
|
||||||
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
|
ExecStartPre=/bin/sleep 30
|
||||||
ExecStart=/bin/sh -c 'hostname \$(cat /etc/hostname)'
|
ExecStart=/bin/sh -c 'hostname \$(cat /etc/hostname)'
|
||||||
RemainAfterExit=yes
|
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]
|
[Install]
|
||||||
WantedBy=timers.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable set-hostname.timer
|
systemctl enable set-hostname.service
|
||||||
systemctl start set-hostname.timer
|
systemctl start set-hostname.service
|
||||||
|
|
||||||
remount_ro
|
remount_ro
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user