use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class AptPackageManager method doDpkgConfigure.
private void doDpkgConfigure(OpsTarget target) throws OpsException {
CommandEnvironment commandEnvironment = buildEnvironmentWithProxy(target);
Command command = Command.build("dpkg --configure -a");
command = command.setEnvironment(commandEnvironment).setTimeout(TimeSpan.TEN_MINUTES);
target.executeCommand(command);
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class AptPackageManager method getInstalledPackageInfo.
public List<String> getInstalledPackageInfo(OpsTarget target) throws OpsException {
AptInfoCache cached = getCache(target);
if (cached.installedPackages == null) {
Command command = Command.build("/usr/bin/dpkg --get-selections");
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) {
throw new OpsException("Error parsing line; expected 2 items: " + line);
}
String state = tokens.get(1);
if (state.equals("install")) {
String packageName = tokens.get(0);
int colonIndex = packageName.indexOf(':');
if (colonIndex != -1) {
// Architecture sometimes follows package name
packageName = packageName.substring(0, colonIndex);
}
packages.add(packageName);
} else if (state.equals("deinstall")) {
// Not installed (?)
} else {
throw new OpsException("Unknown package state in line: " + line);
}
}
cached.installedPackages = packages;
} else {
log.debug("Re-using cached package info");
}
return cached.installedPackages;
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class LdapMasterPassword method doOperation.
@Handler
public void doOperation(OpsTarget target) throws OpsException {
// TODO: Make this idempotent
LdifRecord configLdif;
{
Command ldapSearch = Command.build("ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=config olcRootDN=cn=admin,cn=config dn olcRootDN olcRootPW");
List<LdifRecord> ldifs = LdifRecord.parse(target.executeCommand(ldapSearch).getStdOut());
if (ldifs.size() != 1) {
throw new OpsException("Expected exactly one LDIF record for config");
}
configLdif = ldifs.get(0);
}
{
StringBuilder modify = new StringBuilder();
modify.append("dn: " + configLdif.getLdapDn().toString() + "\n");
modify.append("replace: olcRootPW\n");
modify.append("olcRootPW: " + LdapPasswords.getLdapPasswordEncoded(ldapSecret.plaintext()) + "\n");
modify.append("\n");
File tempDir = target.createTempDir();
File modifyFile = new File(tempDir, "modifypw.ldif");
FileUpload.upload(target, modifyFile, modify.toString());
Command ldapModify = Command.build("ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f {0}", modifyFile);
target.executeCommand(ldapModify);
}
ldap.writeLdapServerPassword(target, ldapSecret);
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class OpenLdapManager method doLdapQuery.
public static List<LdifRecord> doLdapQuery(OpsTarget target, LdapDN bindDN, String ldapPassword, LdapDN searchBaseDN, String filter, SearchScope searchScope) throws OpsException {
Command command = Command.build(CMD_LDAP_SEARCH);
// Pure LDIF, no extra junk
command.addLiteral("-LLL");
// Simple auth
command.addLiteral("-x");
// Bind DN
command.addLiteral("-D");
command.addQuoted(bindDN.toLdifEncoded());
// Simple auth password
command.addLiteral("-w");
command.addQuoted(ldapPassword);
// Search base
command.addLiteral("-b");
command.addQuoted(searchBaseDN.toLdifEncoded());
// Scope
command.addLiteral("-s");
command.addLiteral(searchScope.toString().toLowerCase());
if (!Strings.isNullOrEmpty(filter)) {
command.addQuoted(filter);
}
ProcessExecution processExecution = target.executeCommand(command);
return LdifRecord.parse(processExecution.getStdOut());
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class PostgresqlServerBootstrap method handler.
@Handler
public void handler() throws OpsException {
PostgresqlServer model = OpsContext.get().getInstance(PostgresqlServer.class);
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
// su postgres -c "psql --command=\"ALTER USER postgres WITH PASSWORD 'secret';\""
String password = model.rootPassword.plaintext();
String sql = String.format("ALTER USER postgres WITH PASSWORD '%s';", password);
String psql = String.format("psql --command=\"%s\"", sql);
Command command = Command.build("su postgres -c {0}", psql);
target.executeCommand(command);
}
Aggregations