private void insertCallback(Entity entity, ConfigKey<String> commandKey, String callback) { String command = entity.config().get(commandKey); if (Strings.isNonBlank(command)) { command = BashCommands.chain(String.format("( %s )", command), callback); } else { command = callback; } entity.config().set(commandKey, command); }
@Override public void install() { LOG.info("Installing Node.JS {}", getVersion()); List<String> commands = MutableList.<String>builder() .add(BashCommands.INSTALL_CURL) .add( BashCommands.ifExecutableElse0( "apt-get", BashCommands.chain( BashCommands.installPackage( "software-properties-common python-software-properties python g++ make"), BashCommands.sudo("add-apt-repository ppa:chris-lea/node.js")))) .add( BashCommands.installPackage( MutableMap.of("yum", "git nodejs npm", "apt", "git-core nodejs"), null)) .add("mkdir -p \"$HOME/.npm\"") .add(BashCommands.sudo("npm install -g n")) .add(BashCommands.sudo("n " + getVersion())) .build(); newScript(INSTALLING).body.append(commands).execute(); }
/** * Resolves the on-box dir. * * <p>Initialize and pre-create the right onbox working dir, if an ssh machine location. Logs a * warning if not. */ @SuppressWarnings("deprecation") public static String resolveOnBoxDir(EntityInternal entity, MachineLocation machine) { String base = entity.getConfig(BrooklynConfigKeys.ONBOX_BASE_DIR); if (base == null) base = machine.getConfig(BrooklynConfigKeys.ONBOX_BASE_DIR); if (base != null && Boolean.TRUE.equals(entity.getConfig(ON_BOX_BASE_DIR_RESOLVED))) return base; if (base == null) base = entity.getManagementContext().getConfig().getConfig(BrooklynConfigKeys.ONBOX_BASE_DIR); if (base == null) base = entity.getConfig(BrooklynConfigKeys.BROOKLYN_DATA_DIR); if (base == null) base = machine.getConfig(BrooklynConfigKeys.BROOKLYN_DATA_DIR); if (base == null) base = entity.getManagementContext().getConfig().getConfig(BrooklynConfigKeys.BROOKLYN_DATA_DIR); if (base == null) base = "~/brooklyn-managed-processes"; if (base.equals("~")) base = "."; if (base.startsWith("~/")) base = "." + base.substring(1); String resolvedBase = null; if (entity.getConfig(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION) || machine.getConfig(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION)) { if (log.isDebugEnabled()) log.debug("Skipping on-box base dir resolution for " + entity + " at " + machine); if (!Os.isAbsolutish(base)) base = "~/" + base; resolvedBase = Os.tidyPath(base); } else if (machine instanceof SshMachineLocation) { SshMachineLocation ms = (SshMachineLocation) machine; ProcessTaskWrapper<Integer> baseTask = SshEffectorTasks.ssh( BashCommands.alternatives( "mkdir -p \"${BASE_DIR}\"", BashCommands.chain( BashCommands.sudo("mkdir -p \"${BASE_DIR}\""), BashCommands.sudo("chown " + ms.getUser() + " \"${BASE_DIR}\""))), "cd ~", "cd ${BASE_DIR}", "echo BASE_DIR_RESULT':'`pwd`:BASE_DIR_RESULT") .environmentVariable("BASE_DIR", base) .requiringExitCodeZero() .summary("initializing on-box base dir " + base) .newTask(); DynamicTasks.queueIfPossible(baseTask).orSubmitAsync(entity); resolvedBase = Strings.getFragmentBetween( baseTask.block().getStdout(), "BASE_DIR_RESULT:", ":BASE_DIR_RESULT"); } if (resolvedBase == null) { if (!Os.isAbsolutish(base)) base = "~/" + base; resolvedBase = Os.tidyPath(base); log.warn( "Could not resolve on-box directory for " + entity + " at " + machine + "; using " + resolvedBase + ", though this may not be accurate at the target (and may fail shortly)"); } entity.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, resolvedBase); entity.config().set(ON_BOX_BASE_DIR_RESOLVED, true); return resolvedBase; }