use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class StandardServiceInstance method addChildren.
@Override
protected void addChildren() throws OpsException {
final StandardTemplateData template = getTemplate();
File instanceDir = template.getInstanceDir();
addChild(MetricsInstance.class);
String user = template.getUser();
String group = template.getGroup();
addChild(ManagedDirectory.build(instanceDir, "0700").setOwner(user).setGroup(group));
addChild(ManagedDirectory.build(template.getConfigDir(), "0700").setOwner(user).setGroup(group));
addConfigurationFile(template);
addLogFile(template);
addExtraFiles();
{
StandardService service = addChild(StandardService.class);
Command command = template.getCommand();
service.command = OpsProvider.of(command);
Map<String, String> env = template.getEnvironment();
service.environment = Providers.of(env);
service.instanceDir = instanceDir;
service.key = template.getServiceKey();
service.owner = template.getModel().getKey();
service.matchExecutableName = template.getMatchExecutableName();
}
if (template.shouldCreateKeystore()) {
createKeystore(template);
}
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class ScriptBuilder method add.
public void add(String literal, Object... args) {
Command command = Command.build(literal, args);
add(command);
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class AptPackageManager method findOutOfDatePackages.
// // some packages might need longer if the network is slow
// private static Map<String, TimeSpan> packageTimeMap = new HashMap<String, TimeSpan>() {
// {
// put("sun-java6-jdk", new TimeSpan("30m"));
// }
// };
//
// public static void update(OpsServer server) throws OpsException {
// SimpleBashCommand command = new SimpleBashCommand("/usr/bin/apt-get");
// command.addLiteralArg("-q");
// command.addLiteralArg("-y");
// command.addLiteralArg("update");
//
// server.simpleRun(command, new TimeSpan("5m"));
// }
//
// public static void installUpdates(OpsServer server) throws OpsException {
// SimpleBashCommand command = new SimpleBashCommand("/usr/bin/apt-get");
// command.addLiteralArg("-q");
// command.addLiteralArg("-y");
// command.addLiteralArg("upgrade");
//
// server.simpleRun(command, new TimeSpan("15m"));
// }
public List<String> findOutOfDatePackages(OpsTarget target) throws OpsException {
Command command = Command.build("apt-get -q -q --simulate dist-upgrade");
ProcessExecution execution = target.executeCommand(command);
final List<String> packages = Lists.newArrayList();
for (String line : Splitter.on("\n").split(execution.getStdOut())) {
line = line.trim();
if (line.isEmpty()) {
continue;
}
List<String> tokens = Lists.newArrayList(Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings().split(line));
if (tokens.size() < 2) {
continue;
}
String action = tokens.get(0);
if (action.equals("Inst")) {
// e.g. Inst coreutils [8.13-3.1] (8.13-3.2 Debian:testing [amd64])
packages.add(tokens.get(1));
// New version is in tokens[2]
// Current version is in tokens[3], but that's a trick
}
}
return packages;
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class AptPackageManager method install.
public void install(OpsTarget target, Iterable<String> packageNames) throws OpsException {
CommandEnvironment commandEnvironment = buildEnvironmentWithProxy(target);
commandEnvironment.put("DEBIAN_FRONTEND", "noninteractive");
log.info("Installing APT packages: " + Joiner.on(",").join(packageNames));
Command command = Command.build("apt-get install --yes");
for (String packageName : packageNames) {
command.addQuoted(packageName);
}
target.executeCommand(command.setEnvironment(commandEnvironment).setTimeout(TimeSpan.TEN_MINUTES));
flushCache(target);
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class AptPackageManager method clean.
public void clean(OpsTarget target) throws OpsException {
CommandEnvironment commandEnvironment = buildEnvironmentWithProxy(target);
Command command = Command.build("apt-get clean");
target.executeCommand(command.setEnvironment(commandEnvironment).setTimeout(TimeSpan.TEN_MINUTES));
}
Aggregations