Search in sources :

Example 1 with Command

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);
    }
}
Also used : Command(org.platformlayer.ops.Command) StandardService(org.platformlayer.ops.supervisor.StandardService) File(java.io.File) Map(java.util.Map)

Example 2 with Command

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);
}
Also used : Command(org.platformlayer.ops.Command)

Example 3 with 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;
}
Also used : Command(org.platformlayer.ops.Command) ProcessExecution(org.platformlayer.ops.process.ProcessExecution)

Example 4 with Command

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);
}
Also used : Command(org.platformlayer.ops.Command) CommandEnvironment(org.platformlayer.ops.CommandEnvironment)

Example 5 with Command

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));
}
Also used : Command(org.platformlayer.ops.Command) CommandEnvironment(org.platformlayer.ops.CommandEnvironment)

Aggregations

Command (org.platformlayer.ops.Command)72 File (java.io.File)21 Handler (org.platformlayer.ops.Handler)17 OpsException (org.platformlayer.ops.OpsException)16 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)16 CommandEnvironment (org.platformlayer.ops.CommandEnvironment)11 OpsTarget (org.platformlayer.ops.OpsTarget)9 InetAddress (java.net.InetAddress)4 CurlRequest (org.platformlayer.ops.helpers.CurlRequest)4 Md5Hash (com.fathomdb.hash.Md5Hash)3 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 Map (java.util.Map)3 FilesystemInfo (org.platformlayer.ops.filesystem.FilesystemInfo)3 ImageFormat (org.platformlayer.ops.images.ImageFormat)3 List (java.util.List)2 Properties (java.util.Properties)2 RequestBuilder (org.openstack.client.common.RequestBuilder)2 AddressModel (org.platformlayer.core.model.AddressModel)2 Tag (org.platformlayer.core.model.Tag)2