use of org.jclouds.scriptbuilder.ScriptBuilder in project whirr by apache.
the class RunUrlBuilder method runUrls.
// Need to be able to specify base URL
// Perhaps make these scripts parameterizable?
// e.g. just java/install then base url is .../openjdk or .../sun or
// .../apache or .../cloudera
public static byte[] runUrls(String... urls) throws MalformedURLException {
ScriptBuilder scriptBuilder = new ScriptBuilder().addStatement(exec("wget -qO/usr/bin/runurl run.alestic.com/runurl")).addStatement(exec("chmod 755 /usr/bin/runurl"));
// Note that the runurl scripts should be checked in to whirr/scripts/
String runUrlBase = System.getProperty("whirr.runurl.base", "http://whirr.s3.amazonaws.com/");
for (String url : urls) {
scriptBuilder.addStatement(exec("runurl " + new URL(new URL(runUrlBase), url)));
}
return scriptBuilder.build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX).getBytes();
}
use of org.jclouds.scriptbuilder.ScriptBuilder in project legacy-jclouds-examples by jclouds.
the class CreateVolumeAndAttach method mountVolume.
private void mountVolume(NodeMetadata node) {
System.out.println("Mount Volume and Create Filesystem");
String script = new ScriptBuilder().addStatement(exec("mkfs -t ext4 /dev/xvdd")).addStatement(exec("mount /dev/xvdd /mnt")).render(OsFamily.UNIX);
RunScriptOptions options = RunScriptOptions.Builder.blockOnComplete(true).overrideLoginPassword(Constants.PASSWORD);
ExecResponse response = compute.runScriptOnNode(node.getId(), script, options);
if (response.getExitStatus() == 0) {
System.out.println(" Exit Status: " + response.getExitStatus());
} else {
System.out.println(" Error: " + response.getOutput());
}
}
use of org.jclouds.scriptbuilder.ScriptBuilder in project legacy-jclouds-examples by jclouds.
the class DetachVolume method unmountVolume.
/**
* Make sure you've unmounted the volume first. Failure to do so could result in failure or data loss.
*/
private void unmountVolume(VolumeAttachment volumeAttachment) {
System.out.println("Unmount Volume");
String script = new ScriptBuilder().addStatement(exec("umount /mnt")).render(OsFamily.UNIX);
RunScriptOptions options = RunScriptOptions.Builder.overrideLoginUser(Constants.ROOT).overrideLoginPassword(Constants.PASSWORD).blockOnComplete(true);
ZoneAndId zoneAndId = ZoneAndId.fromZoneAndId(Constants.ZONE, volumeAttachment.getServerId());
ExecResponse response = compute.runScriptOnNode(zoneAndId.slashEncode(), script, options);
if (response.getExitStatus() == 0) {
System.out.println(" Exit Status: " + response.getExitStatus());
} else {
System.out.println(" Error: " + response.getOutput());
}
}
use of org.jclouds.scriptbuilder.ScriptBuilder in project legacy-jclouds-examples by jclouds.
the class CloudServersPublish method configureAndStartWebserver.
private void configureAndStartWebserver(Set<? extends NodeMetadata> nodes) throws TimeoutException {
for (NodeMetadata nodeMetadata : nodes) {
String publicAddress = nodeMetadata.getPublicAddresses().iterator().next();
String privateAddress = nodeMetadata.getPrivateAddresses().iterator().next();
System.out.println("Configure And Start Webserver");
awaitSsh(publicAddress);
String message = new StringBuilder().append("Hello from ").append(nodeMetadata.getHostname()).append(" @ ").append(publicAddress).append("/").append(privateAddress).append(" in ").append(nodeMetadata.getLocation().getParent().getId()).toString();
String script = new ScriptBuilder().addStatement(exec("yum -y install httpd")).addStatement(exec("/usr/sbin/apachectl start")).addStatement(exec("iptables -I INPUT -p tcp --dport 80 -j ACCEPT")).addStatement(exec("echo '" + message + "' > /var/www/html/index.html")).render(OsFamily.UNIX);
RunScriptOptions options = RunScriptOptions.Builder.blockOnComplete(true);
compute.runScriptOnNode(nodeMetadata.getId(), script, options);
System.out.println(" Login: ssh " + nodeMetadata.getCredentials().getUser() + "@" + publicAddress);
System.out.println(" Password: " + nodeMetadata.getCredentials().getPassword());
System.out.println(" Go to http://" + publicAddress);
}
}
Aggregations