use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class ZookeeperUtils method sendCommand.
public static ZookeeperResponse sendCommand(OpsTarget target, InetSocketAddress socketAddress, String zkCommand) throws OpsException {
Command command = Command.build("echo {0} | nc {1} {2}", zkCommand, socketAddress.getAddress().getHostAddress(), socketAddress.getPort());
ProcessExecution execution = target.executeCommand(command);
return new ZookeeperResponse(execution.getStdOut());
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class PosixUser method doOperation.
@Handler
public void doOperation() throws OpsException {
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
// TODO: Only if user not found
{
Command command = Command.build("adduser");
command.addLiteral("--system");
command.addLiteral("--no-create-home");
if (shell != null) {
command.addLiteral("--shell").addFile(shell);
}
if (!Strings.isNullOrEmpty(primaryGroup)) {
command.addLiteral("--ingroup");
command.addQuoted(primaryGroup);
}
command.addQuoted(userName);
target.executeCommand(command);
}
for (String secondaryGroup : secondaryGroups) {
Command command = Command.build("adduser");
command.addQuoted(userName);
command.addQuoted(secondaryGroup);
target.executeCommand(command);
}
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class DownloadFileByHash method uploadFile.
@Override
protected void uploadFile(OpsTarget target, File remoteFilePath) throws IOException, OpsException {
target.mkdir(remoteFilePath.getParentFile());
Md5Hash resolved = getResolved(target);
CasStoreObject casObject;
CasStoreMap casStoreMap = cas.getCasStoreMap(target);
try {
casObject = casStoreMap.findArtifact(new OpsCasTarget(target), resolved);
} catch (Exception e) {
throw new OpsException("Error while resolving artifact:" + getHumanName(), e);
}
if (url != null && casObject == null) {
target.mkdir(remoteFilePath.getParentFile());
CurlRequest curlRequest = new CurlRequest(url);
curlRequest.bareRequest = true;
CommandEnvironment commandEnvironment = httpProxies.getHttpProxyEnvironment(target, Usage.General, url);
Command curlCommand = curlRequest.toCommand();
curlCommand.addLiteral(">");
curlCommand.addFile(remoteFilePath);
curlCommand.setEnvironment(commandEnvironment);
curlCommand.setTimeout(TimeSpan.FIVE_MINUTES);
// TODO: Can we cache into CAS instead??
log.info("Not found in CAS system; downloading directly: " + url);
target.executeCommand(curlCommand);
} else {
if (casObject == null) {
throw new OpsException("Unable to find artifact: " + getHumanName());
}
log.info("Doing a CAS copy from " + casObject + " to target");
cas.copyObject(casStoreMap, casObject, new OpsCasTarget(target), remoteFilePath, true);
}
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class PackageRemoval method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
// Make sure openssh-server is manually installed (i.e. not through task-ssh-server)
target.executeCommand("apt-get install openssh-server");
// Only for wheezy? Squeeze has a depencency of install-info -> findutils
Command command = Command.build("apt-get remove --yes aptitude tasksel tasksel-data man-db manpages libxapian22 libboost-iostreams1.49.0 info ");
target.executeCommand(command);
// Maybe:
command = Command.build("apt-get remove --yes groff-base consolekit sane-utils exim4-config installation-report");
target.executeCommand(command);
// Replace netcat with netcat6
target.executeCommand("apt-get install netcat6");
target.executeCommand("apt-get remove netcat-traditional");
// We just want headless...
command = Command.build("apt-get remove --yes dbus openjdk-7-jdk openjdk-7-jre icedtea-7-jre-cacao icedtea-7-jre-jamvm");
target.executeCommand(command);
// Do we need python?? Does it still get installed??
// apt-get remove python
// Warnings??
// apt-get remove install-info
//
// Squeeze:
// apt-get remove aptitude tasksel tasksel-data man-db manpages libxapian22 info
target.executeCommand("apt-get autoremove");
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class PersistIptablesScripts method addChildren.
@Override
protected void addChildren() throws OpsException {
addChild(ManagedDirectory.build(BASE_DIR, "0644"));
addChild(SimpleFile.build(getClass(), new File("/etc/network/if-pre-up.d/iptables-lockdown")).setFileMode("755").setUpdateAction(new FilesystemAction() {
@Override
public void execute(OpsTarget target, ManagedFilesystemItem managedFilesystemItem) throws OpsException {
if (managedFilesystemItem.getNewFileWasCreated()) {
// Set the parameters the ifup sets
CommandEnvironment env = new CommandEnvironment();
env.put("MODE", "start");
env.put("IFACE", "--all");
env.put("ADDRFAM", "meta");
Command runLockdown = Command.build("/etc/network/if-pre-up.d/iptables-lockdown");
runLockdown.setEnvironment(env);
target.executeCommand(runLockdown);
}
}
}));
addChild(SimpleFile.build(getClass(), new File("/etc/network/if-up.d/iptables-ifup")).setFileMode("755"));
}
Aggregations