From 747041527fb73371e726d63f3dded3c505573acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sun, 23 Nov 2025 18:12:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96hos?= =?UTF-8?q?tname=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/service/toolbox_system.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/service/toolbox_system.go b/internal/service/toolbox_system.go index 054fb7d3..f50ad006 100644 --- a/internal/service/toolbox_system.go +++ b/internal/service/toolbox_system.go @@ -258,7 +258,10 @@ func (s *ToolboxSystemService) SyncTime(w http.ResponseWriter, r *http.Request) // GetHostname 获取主机名 func (s *ToolboxSystemService) GetHostname(w http.ResponseWriter, r *http.Request) { - hostname, _ := io.Read("/etc/hostname") + hostname, err := shell.Execf("hostnamectl hostname") + if err != nil { + hostname, _ = io.Read("/etc/hostname") + } Success(w, strings.TrimSpace(hostname)) } @@ -270,7 +273,7 @@ func (s *ToolboxSystemService) UpdateHostname(w http.ResponseWriter, r *http.Req return } - if _, err = shell.Execf("hostnamectl set-hostname '%s'", req.Hostname); err != nil { + if _, err = shell.Execf("hostnamectl hostname '%s'", req.Hostname); err != nil { // 直接写 /etc/hostname if err = io.Write("/etc/hostname", req.Hostname, 0644); err != nil { Error(w, http.StatusInternalServerError, s.t.Get("failed to set hostname: %v", err))