fix:权限sudo
This commit is contained in:
parent
6823cc4d3e
commit
69a740adcf
@ -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配置失败,且回滚也失败");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user