public static boolean isSudoAllowed() { if (Time.hasElapsedSince(lastSudoCheckTime, Duration.FIVE_MINUTES)) checkIfNeeded(); return lastSudoResult; } private static synchronized void checkIfNeeded() {
private static synchronized void checkIfNeeded() { if (Time.hasElapsedSince(lastSudoCheckTime, Duration.FIVE_MINUTES)) { try { lastSudoResult = new ProcessTool().execCommands(MutableMap.<String,Object>of(), Arrays.asList( BashCommands.sudo("date"))) == 0; } catch (Exception e) { lastSudoResult = false; LOG.debug("Error checking sudo at localhost: "+e, e); } lastSudoCheckTime = System.currentTimeMillis(); } } }
if (changed || Time.hasElapsedSince(lastUpdate, Duration.ONE_HOUR)) update();