Search in sources :

Example 51 with Handler

use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.

the class MkIsoFs method handler.

@Handler
public void handler(OpsTarget target) throws OpsException {
    FilesystemInfo isoInfo = target.getFilesystemInfoFile(iso);
    boolean rebuild = true;
    if (isoInfo != null) {
        // TODO: Do timestamp based dependency checking?
        rebuild = false;
    }
    if (rebuild) {
        Command mkisoCommand = Command.build("genisoimage -input-charset utf-8 -R -o {0}", iso);
        if (volumeLabel != null) {
            mkisoCommand.addLiteral("-V").addQuoted(volumeLabel);
        }
        mkisoCommand.addFile(srcDir);
        target.executeCommand(mkisoCommand);
    }
}
Also used : FilesystemInfo(org.platformlayer.ops.filesystem.FilesystemInfo) Command(org.platformlayer.ops.Command) Handler(org.platformlayer.ops.Handler)

Example 52 with Handler

use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.

the class LxcBootstrap method handler.

// private void setupAutostart() throws OpsException {
// // ln -s /var/lib/lxc/${NAME}/config /etc/lxc/auto/${NAME}
//
// target.symlink(getConfigFile(), new File("/etc/lxc/auto/" + lxcId), false);
// }
@Handler
public void handler(OpsTarget target) throws OpsException {
    if (OpsContext.isConfigure()) {
        // TODO: Move to children
        //
        // File rootDir = getRoot();
        // target.mkdir(rootDir);
        // target.executeCommand(Command.build("cd {0}; tar jxf {1}", rootDir,
        // imagePath).setTimeout(TimeSpan.FIVE_MINUTES));
        // mknod -m 666 ${ROOT}/dev/tty1 c 4 1
        // mknod -m 666 ${ROOT}/dev/tty2 c 4 2
        // mknod -m 666 ${ROOT}/dev/tty3 c 4 3
        // mknod -m 666 ${ROOT}/dev/tty4 c 4 4
        // mknod -m 666 ${ROOT}/dev/tty5 c 4 5
        // mknod -m 666 ${ROOT}/dev/tty6 c 4 6
        {
            ChrootOpsTarget chrootTarget = new ChrootOpsTarget(getRoot(), new File("/tmp"), target);
            if (sshPublicKey != null) {
                SshAuthorizedKey.ensureSshAuthorization(chrootTarget, "root", sshPublicKey);
            }
        }
        setupLxcConfig();
        setupResolveConf();
        setupInittab();
        setupInterfaces();
        setupIpv6Script();
        setupHostname();
    // if (startOnBoot) {
    // setupAutostart();
    // }
    }
}
Also used : ChrootOpsTarget(org.platformlayer.ops.ChrootOpsTarget) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 53 with Handler

use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.

the class GitRepoInit method handler.

@Handler
public void handler(OpsTarget target) throws OpsException {
    File canaryFile = new File(repoDir, "config");
    if (OpsContext.isConfigure()) {
        if (target.getFilesystemInfoFile(canaryFile) == null) {
            target.executeCommand(Command.build("git --bare init {0}", repoDir));
            File hooks = new File(repoDir, "hooks");
            File postUpdateHook = new File(hooks, "post-update");
            target.mv(new File(hooks, "post-update.sample"), postUpdateHook);
            target.chmod(postUpdateHook, "755");
            target.executeCommand(Command.build("cd {0}; git update-server-info", repoDir));
            target.executeCommand(Command.build("cd {0}; git config http.receivepack true", repoDir));
            target.chown(repoDir, "www-data", "www-data", true, false);
        }
    }
}
Also used : File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 54 with Handler

use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.

the class PostgresqlServerBackup method doBackup.

@Handler(BackupAction.class)
public void doBackup() throws OpsException, IOException {
    OpsContext opsContext = OpsContext.get();
    // Machine machine = opsContext.getInstance(Machine.class);
    OpsTarget target = opsContext.getInstance(OpsTarget.class);
    // We use pg_dump, not pg_dumpall:
    // 1) pg_dumpall doesn't support binary dumping (?)
    // 2) pg_dumpall wouldn't let us split the dump into different files (?)
    List<String> databases = listDatabases(target);
    BackupContext backupContext = backups.getContext();
    String baseName = UUID.randomUUID().toString();
    PostgresqlServer server = OpsContext.get().getInstance(PostgresqlServer.class);
    backupContext.add(new BackupItem(server.getKey(), FORMAT, baseName));
    {
        Command dumpAll = Command.build("su postgres -c \"pg_dumpall --globals-only\"");
        Backup request = new Backup();
        request.target = target;
        request.objectName = baseName + "/pgdump_meta";
        backupContext.uploadStream(request, dumpAll);
    }
    for (String database : databases) {
        // template0 cannot be backed up
        if (database.equals("template0")) {
            continue;
        }
        // template1 can be backed up, even though it isn't typically very useful
        String fileName = "pgdump_db_" + database;
        Backup request = new Backup();
        request.target = target;
        request.objectName = baseName + "/" + fileName;
        Command dumpDatabase = Command.build("su postgres -c \"pg_dump --oids -Fc --verbose {0}\"", database);
        backupContext.uploadStream(request, dumpDatabase);
    }
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) BackupItem(org.platformlayer.ops.backups.BackupItem) Command(org.platformlayer.ops.Command) Backup(org.platformlayer.ops.backups.Backup) BackupContext(org.platformlayer.ops.backups.BackupContext) PostgresqlServer(org.platformlayer.service.postgresql.model.PostgresqlServer) OpsContext(org.platformlayer.ops.OpsContext) Handler(org.platformlayer.ops.Handler)

Example 55 with Handler

use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.

the class NexusApp method handler.

@Handler
public void handler() throws IOException, OpsException {
    // TODO: This needs to be idempotent
    OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
    String url = "http://nexus.sonatype.org/downloads/all/nexus-webapp-1.9.2.4.war";
    File warFile = new File("/var/lib/jetty/wars/nexus-webapp-1.9.2.4.war");
    target.executeCommand("wget {0} -O {1}", url, warFile);
    // Whatever version of nexus we have, we want it to be the root
    target.symlink(warFile, new File("/var/lib/jetty/webapps/root.war"), false);
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Aggregations

Handler (org.platformlayer.ops.Handler)58 File (java.io.File)21 Command (org.platformlayer.ops.Command)17 OpsException (org.platformlayer.ops.OpsException)17 OpsTarget (org.platformlayer.ops.OpsTarget)17 Tag (org.platformlayer.core.model.Tag)8 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)5 SshKey (org.platformlayer.ops.helpers.SshKey)5 Machine (org.platformlayer.ops.Machine)4 PublicKey (java.security.PublicKey)3 Action (org.platformlayer.core.model.Action)3 EndpointInfo (org.platformlayer.core.model.EndpointInfo)3 ItemBase (org.platformlayer.core.model.ItemBase)3 Tags (org.platformlayer.core.model.Tags)3 MachineCreationRequest (org.platformlayer.ops.MachineCreationRequest)3 Map (java.util.Map)2 OpenstackComputeClient (org.openstack.client.common.OpenstackComputeClient)2 SecurityGroup (org.openstack.model.compute.SecurityGroup)2 Server (org.openstack.model.compute.Server)2 PlatformLayerClientException (org.platformlayer.PlatformLayerClientException)2