use of org.platformlayer.service.gitosis.model.GitServer in project platformlayer by platformlayer.
the class GitHelpers method doForAllServers.
public void doForAllServers(GitosisOperation operation) throws Exception {
boolean failed = false;
for (Managed<GitServer> gitServer : platformLayer.listItems(GitServer.class)) {
if (gitServer.getState() != ManagedItemState.ACTIVE) {
log.warn("Server not yet active: " + gitServer);
failed = true;
continue;
}
OpenstackComputeMachine machine = instances.findMachine(gitServer);
if (machine == null) {
log.warn("Server instance not found: " + gitServer);
failed = true;
continue;
}
SshKey sshKey = service.getSshKey();
OpsTarget rootTarget = machine.getTarget(sshKey);
OpsTarget adminTarget = getAdminTarget(rootTarget, machine);
doOperation(adminTarget, operation);
}
if (failed) {
throw new OpsException("Could not update all DNS servers in cluster").setRetry(TimeSpan.ONE_MINUTE);
}
}
use of org.platformlayer.service.gitosis.model.GitServer in project platformlayer by platformlayer.
the class GitServerController method doOperation.
public void doOperation(Managed<GitServer> managed) throws OpsException, IOException {
initializeService();
GitServer model = (GitServer) managed.getModel();
Tag tag = new Tag(Tag.CONDUCTOR_ID, managed.getConductorId());
SshKey sshKey = service.getSshKey();
DiskImageRecipe recipe = imageFactory.loadDiskImageResource(getClass(), "DiskImageRecipe.xml");
String securityGroup = service.getSecurityGroupName();
// Git isn't particularly memory intensive (?)
int minimumMemoryMB = 256;
Managed<PersistentInstance> foundPersistentInstance = persistentInstances.getOrCreate(tag, recipe, model.dnsName, sshKey.getName(), securityGroup, minimumMemoryMB);
OpenstackComputeMachine machine = persistentInstances.getMachine(foundPersistentInstance);
OpsTarget target = machine.getTarget(sshKey);
// target.mkdir(new File("/opt/scripts"));
// target.setFileContents(new File("/opt/scripts/dnsdatabasemonitor"),
// ResourceUtils.loadString(getClass(), "dnsdatabasemonitor"));
// target.setFileContents(new
// File("/etc/monit/conf.d/dnsdatabasemonitor"),
// ResourceUtils.loadString(getClass(), "monitrc"));
String adminUser = "gitadmin";
target.executeCommand("adduser --group --system {0}", adminUser);
File adminHomeDir = new File("/home", adminUser);
File adminSshDir = new File(adminHomeDir, ".ssh");
File privateKeyFile = new File(adminSshDir, "id_rsa");
File publicKeyFile = new File(adminSshDir, "id_rsa.pub");
File authorizedKeys = new File(adminSshDir, "authorized_keys");
target.mkdir(adminSshDir);
String passphrase = "";
target.executeCommand("ssh-keygen -t rsa -f {0} -P {1}", privateKeyFile, passphrase);
String privateKeyData = target.readTextFile(privateKeyFile);
String publicKeyData = target.readTextFile(publicKeyFile);
target.executeCommand("cat {0} | sudo -H -u gitosis gitosis-init", publicKeyFile);
target.setFileContents(authorizedKeys, publicKeyData);
target.executeCommand("chown -R {0} {1}", adminUser, adminSshDir);
target.executeCommand("chmod -R 600 {0}", adminSshDir);
target.executeCommand("chmod 700 {0}", adminSshDir);
target.executeCommand("chsh -s /bin/bash {0}", adminUser);
SshKey adminSshKey = new SshKey(null, adminUser, KeyPairUtils.deserialize(privateKeyData));
OpsTarget adminTarget = machine.getTarget(adminSshKey);
{
ProcessExecution execution = adminTarget.executeCommand("ssh-keyscan 127.0.0.1");
File knownHosts = new File(adminSshDir, "known_hosts");
adminTarget.setFileContents(knownHosts, execution.getStdOut());
}
// adminTarget.executeCommand("git clone gitosis@127.0.0.1:gitosis-admin.git /home/gitadmin/gitosis-admin");
// adminSshKey.
//
// adminTarget.executeCommand("git clone git@)
// git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git
// cd gitosis-admin
}
Aggregations