fix:权限sudo

This commit is contained in:
waner 2026-05-27 13:51:31 +08:00
parent 6823cc4d3e
commit 69a740adcf

View File

@ -62,7 +62,7 @@ public class TimeConfigServiceImpl implements TimeConfigService {
} }
try { try {
executeCommand("systemctl", "stop", "chronyd"); executeCommand("sudo", "systemctl", "stop", "chronyd");
} catch (Exception e){ } catch (Exception e){
throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "停止chronyd服务失败"); throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "停止chronyd服务失败");
} }
@ -72,7 +72,7 @@ public class TimeConfigServiceImpl implements TimeConfigService {
executeCommand("date", "-s", request.getDatetime()); executeCommand("date", "-s", request.getDatetime());
} catch (Exception e) { } catch (Exception e) {
// 失败后重启 chronyd // 失败后重启 chronyd
executeCommand("systemctl", "start", "chronyd"); executeCommand("sudo", "systemctl", "start", "chronyd");
throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "设置时间失败,已回退并重启 chronyd 服务"); throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "设置时间失败,已回退并重启 chronyd 服务");
} }
@ -126,7 +126,7 @@ public class TimeConfigServiceImpl implements TimeConfigService {
Files.writeString(confPath, confContent); Files.writeString(confPath, confContent);
executeCommand("systemctl", "restart", "chronyd"); executeCommand("sudo", "systemctl", "restart", "chronyd");
executeCommand("chronyc", "-a", "makestep"); executeCommand("chronyc", "-a", "makestep");
String status = executeCommand("chronyc", "tracking"); String status = executeCommand("chronyc", "tracking");
@ -138,7 +138,7 @@ public class TimeConfigServiceImpl implements TimeConfigService {
try { try {
if (Files.exists(backupPath)) { if (Files.exists(backupPath)) {
Files.copy(backupPath, confPath, StandardCopyOption.REPLACE_EXISTING); Files.copy(backupPath, confPath, StandardCopyOption.REPLACE_EXISTING);
executeCommand("systemctl", "restart", "chronyd"); executeCommand("sudo", "systemctl", "restart", "chronyd");
} }
} catch (Exception rollbackEx) { } catch (Exception rollbackEx) {
throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "应用新的Chrony配置失败且回滚也失败"); throw new BizException(ErrorCode.BIZ_ERROR.getCode(), "应用新的Chrony配置失败且回滚也失败");