From 69a740adcfed1cd153e58b9f6f3c2d14ccbb7978 Mon Sep 17 00:00:00 2001 From: waner Date: Wed, 27 May 2026 13:51:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=9D=83=E9=99=90sudo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/service/impl/TimeConfigServiceImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cisd/tms/modules/device/service/impl/TimeConfigServiceImpl.java b/src/main/java/com/cisd/tms/modules/device/service/impl/TimeConfigServiceImpl.java index ad7b3fa..388a0c2 100644 --- a/src/main/java/com/cisd/tms/modules/device/service/impl/TimeConfigServiceImpl.java +++ b/src/main/java/com/cisd/tms/modules/device/service/impl/TimeConfigServiceImpl.java @@ -62,7 +62,7 @@ public class TimeConfigServiceImpl implements TimeConfigService { } try { - executeCommand("systemctl", "stop", "chronyd"); + executeCommand("sudo", "systemctl", "stop", "chronyd"); } catch (Exception e){ throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "停止chronyd服务失败"); } @@ -72,7 +72,7 @@ public class TimeConfigServiceImpl implements TimeConfigService { executeCommand("date", "-s", request.getDatetime()); } catch (Exception e) { // 失败后重启 chronyd - executeCommand("systemctl", "start", "chronyd"); + executeCommand("sudo", "systemctl", "start", "chronyd"); throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "设置时间失败,已回退并重启 chronyd 服务"); } @@ -126,7 +126,7 @@ public class TimeConfigServiceImpl implements TimeConfigService { Files.writeString(confPath, confContent); - executeCommand("systemctl", "restart", "chronyd"); + executeCommand("sudo", "systemctl", "restart", "chronyd"); executeCommand("chronyc", "-a", "makestep"); String status = executeCommand("chronyc", "tracking"); @@ -138,7 +138,7 @@ public class TimeConfigServiceImpl implements TimeConfigService { try { if (Files.exists(backupPath)) { Files.copy(backupPath, confPath, StandardCopyOption.REPLACE_EXISTING); - executeCommand("systemctl", "restart", "chronyd"); + executeCommand("sudo", "systemctl", "restart", "chronyd"); } } catch (Exception rollbackEx) { throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "应用新的Chrony配置失败,且回滚也失败");