use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.
the class ApacheBootstrap method handler.
@Handler
public void handler() throws OpsException {
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
target.rm(new File("/etc/apache2/sites-enabled/000-default"));
}
use of org.platformlayer.ops.Handler 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.Handler 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);
}
use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.
the class NginxServerBootstrap method handler.
@Handler
public void handler() throws OpsException {
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
target.rm(new File("/etc/nginx/sites-enabled/default"));
}
use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.
the class InstanceBuilder method doOperation.
@Handler
public void doOperation() throws OpsException, IOException {
ItemBase item = ops.getInstance(ItemBase.class);
Tag parentTag = Tag.buildParentTag(item.getKey());
PersistentInstance persistentInstanceTemplate = buildPersistentInstanceTemplate();
persistentInstanceTemplate.getTags().add(parentTag);
// Set during doOperation
Machine machine = null;
PersistentInstance persistentInstance = null;
InstanceBase instance = null;
OpsTarget target = null;
persistentInstance = getOrCreate(parentTag, persistentInstanceTemplate);
if (persistentInstance != null) {
// We have to connect to the underlying machine not-via-DNS for Dns service => use instance id
// TODO: Should we always use the instance id??
instance = instances.findInstance(persistentInstance);
if (instance == null && !OpsContext.isDelete()) {
// A machine has not (yet) been assigned
throw new OpsException("Machine is not yet built").setRetry(TimeSpan.ONE_MINUTE);
}
}
if (instance != null) {
machine = cloudHelpers.toMachine(instance);
}
if (addTagToManaged && !OpsContext.isDelete()) {
// Add tag with instance id to persistent instance (very helpful for
// DNS service!)
PlatformLayerKey machineKey = machine.getKey();
platformLayer.addTag(item.getKey(), Tag.INSTANCE_KEY.build(machineKey));
}
SshKey sshKey = service.getSshKey();
if (machine != null) {
if (OpsContext.isDelete()) {
target = null;
machine = null;
} else {
target = machine.getTarget(sshKey);
}
}
RecursionState recursion = getRecursionState();
if (OpsContext.isDelete() && machine == null) {
// Don't recurse into no machine :-)
recursion.setPreventRecursion(true);
}
recursion.pushChildScope(Machine.class, machine);
recursion.pushChildScope(PersistentInstance.class, persistentInstance);
recursion.pushChildScope(InstanceBase.class, instance);
recursion.pushChildScope(OpsTarget.class, target);
}
Aggregations