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配置失败,且回滚也失败");