public static ShellResult checkTimeSync()

in bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/utils/os/TimeSyncDetection.java [33:64]


    public static ShellResult checkTimeSync() {
        List<String> params = new ArrayList<>();
        params.add("systemctl");
        params.add("status");
        params.add("chronyd");
        ShellResult shellResult;
        try {
            log.info("Checking service chronyd status");
            shellResult = ShellExecutor.execCommand(params);
            if (shellResult.getExitCode() == 0) {
                log.info("Service chronyd is enabled");
                return shellResult;
            }

            log.info("Service chronyd is not enabled, checking ntpd status");
            params.remove(params.size() - 1);
            params.add("ntpd");
            shellResult = ShellExecutor.execCommand(params);
            if (shellResult.getExitCode() == 0) {
                log.info("Service ntpd is enabled");
                return shellResult;
            }

            log.info("Service ntpd is not enabled");
        } catch (IOException e) {
            shellResult = new ShellResult();
            shellResult.setExitCode(-1);
            shellResult.setErrMsg("Neither chronyd nor ntpd check failed");
        }

        return shellResult;
    }