Issue 616:move integration tests to jboss as7

This commit is contained in:
Adrian Cole 2011-07-01 18:01:40 -07:00
parent b56f08b9a5
commit ceaffbf103
5 changed files with 142 additions and 70 deletions

View File

@ -30,9 +30,9 @@ import java.util.Map;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.predicates.OperatingSystemPredicates; import org.jclouds.compute.predicates.OperatingSystemPredicates;
import org.jclouds.scriptbuilder.InitBuilder; import org.jclouds.scriptbuilder.InitBuilder;
import org.jclouds.scriptbuilder.domain.AuthorizeRSAPublicKey;
import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.scriptbuilder.domain.Statements;
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -66,25 +66,62 @@ public class RunScriptData {
exec("iptables-save")); exec("iptables-save"));
} }
public static Statement createScriptInstallAndStartJBoss(String publicKey, OperatingSystem os) { public static Statement createScriptInstallAndStartJBoss(OperatingSystem os) {
Map<String, String> envVariables = ImmutableMap.of("jbossHome", jbossHome); Map<String, String> envVariables = ImmutableMap.of("jbossHome", jbossHome);
Statement toReturn = new InitBuilder( Statement toReturn = new InitBuilder(
"jboss", "jboss",
jbossHome, jbossHome,
jbossHome, jbossHome,
envVariables, envVariables,
ImmutableList.<Statement> of(new AuthorizeRSAPublicKey(publicKey),// ImmutableList.<Statement> of(AdminAccess.standard(),//
installJavaAndCurl(os),// installJavaAndCurl(os),//
authorizePortInIpTables(8080), authorizePortInIpTables(8080),
extractTargzIntoDirectory(URI.create(System.getProperty("test.jboss-url", extractTargzIntoDirectory(URI.create(System.getProperty("test.jboss-url",
"http://d37gkgjhl3prlk.cloudfront.net/jboss-6.0.0.Final.tar.gz")), "/usr/local"),// "http://d37gkgjhl3prlk.cloudfront.net/jboss-7.0.0.CR1.tar.gz")), "/usr/local"),//
exec("{md} " + jbossHome), exec("mv /usr/local/jboss-*/* " + jbossHome),// exec("{md} " + jbossHome), exec("mv /usr/local/jboss-*/* " + jbossHome),//
changeStandaloneConfigToListenOnAllIPAddresses(),
exec("chmod -R oug+r+w " + jbossHome)),// exec("chmod -R oug+r+w " + jbossHome)),//
//TODO http://community.jboss.org/wiki/AS7StartupTimeShowdown
ImmutableList ImmutableList
.<Statement> of(interpret("java -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=lib/endorsed -classpath bin/run.jar org.jboss.Main -c jbossweb-standalone -b 0.0.0.0"))); .<Statement> of(interpret(new StringBuilder().append("java ").append(' ')
.append("-Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000").append(' ')
.append("-Djboss.modules.system.pkgs=org.jboss.byteman").append(' ')
.append("-Dorg.jboss.boot.log.file=$JBOSS_HOME/standalone/log/boot.log").append(' ')
.append("-Dlogging.configuration=file:$JBOSS_HOME/standalone/configuration/logging.properties").append(' ')
.append("-jar $JBOSS_HOME/jboss-modules.jar").append(' ')
.append("-mp $JBOSS_HOME/modules").append(' ')
.append("-logmodule org.jboss.logmanager").append(' ')
.append("-jaxpmodule javax.xml.jaxp-provider").append(' ')
.append("org.jboss.as.standalone").append(' ')
.append("-Djboss.home.dir=$JBOSS_HOME")
.toString())));
return toReturn; return toReturn;
} }
public static Statement normalizeHostAndDNSConfig() {
return newStatementList(//
addHostnameToEtcHostsIfMissing(),//
addDnsToResolverIfMissing());
}
public static Statement addHostnameToEtcHostsIfMissing() {
return exec("grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1\" \"hostname }' /proc/net/arp >> /etc/hosts");
}
public static Statement addDnsToResolverIfMissing() {
return exec("nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf");
}
public static Statement installSunJDKFromWhirrIfNotPresent() {
return newStatementList(exec("(which java && java -fullversion 2>&1|egrep -q 1.6 ) ||"),//
execHttpResponse(URI.create("http://whirr.s3.amazonaws.com/0.3.0-incubating/sun/java/install")));
}
// TODO make this a cli option
private static Statement changeStandaloneConfigToListenOnAllIPAddresses() {
return exec("(cd $JBOSS_HOME/standalone/configuration && sed 's~inet-address value=.*/~any-address/~g' standalone.xml > standalone.xml.new && mv standalone.xml.new standalone.xml)");
}
public static String aptInstall = "apt-get install -f -y -qq --force-yes"; public static String aptInstall = "apt-get install -f -y -qq --force-yes";
public static String installAfterUpdatingIfNotPresent(String cmd) { public static String installAfterUpdatingIfNotPresent(String cmd) {
@ -93,28 +130,21 @@ public class RunScriptData {
} }
public static final Statement APT_RUN_SCRIPT = newStatementList(// public static final Statement APT_RUN_SCRIPT = newStatementList(//
normalizeHostAndDNSConfig(),//
exec(installAfterUpdatingIfNotPresent("curl")),// exec(installAfterUpdatingIfNotPresent("curl")),//
exec("(which java && java -fullversion 2>&1|egrep -q 1.6 ) ||"),// installSunJDKFromWhirrIfNotPresent(),//
execHttpResponse(URI.create("http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install")),// exec("rm -rf /var/cache/apt /usr/lib/vmware-tools"),//
exec(new StringBuilder()// exec("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc"));
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")//
// jeos hasn't enough room!
.append("rm -rf /var/cache/apt /usr/lib/vmware-tools\n")//
.append("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc")//
.toString()));
public static final Statement YUM_RUN_SCRIPT = newStatementList( public static final Statement YUM_RUN_SCRIPT = newStatementList(//
exec("which curl ||yum --nogpgcheck -y install curl"),// normalizeHostAndDNSConfig(),//
exec("(which java && java -fullversion 2>&1|egrep -q 1.6 ) ||"),// exec("which curl || yum --nogpgcheck -y install curl"),//
execHttpResponse(URI.create("http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install")),// installSunJDKFromWhirrIfNotPresent(),//
exec(new StringBuilder()// exec("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc"));
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n") //
.append("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc")//
.toString()));
public static final Statement ZYPPER_RUN_SCRIPT = exec(new StringBuilder()// public static final Statement ZYPPER_RUN_SCRIPT = newStatementList(//
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")// normalizeHostAndDNSConfig(),//
.append("which curl || zypper install curl\n")// exec("which curl || zypper install curl"),//
.append("(which java && java -fullversion 2>&1|egrep -q 1.6 ) || zypper install java-1.6.0-openjdk\n")// exec("(which java && java -fullversion 2>&1|egrep -q 1.6 ) || zypper install java-1.6.0-openjdk"),//
.toString()); exec("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /root/.bashrc"));
} }

View File

@ -113,7 +113,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
@Override @Override
public Supplier<Map<String, String>> defaultAdminSshKeys() { public Supplier<Map<String, String>> defaultAdminSshKeys() {
return Suppliers.<Map<String, String>> ofInstance(ImmutableMap.of("public", "publicKey", "private", return Suppliers.<Map<String, String>> ofInstance(ImmutableMap.of("public", "publicKey", "private",
"privateKey")); "privateKey"));
} }
@Override @Override
@ -134,66 +134,69 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
}); });
SshClient.Factory factory = createMock(SshClient.Factory.class); SshClient.Factory factory = createMock(SshClient.Factory.class);
SshClient client1 = createMock(SshClient.class); SshClient client1 = createMock(SshClient.class);
SshClient client1New = createMock(SshClient.class);
SshClient client2 = createMock(SshClient.class); SshClient client2 = createMock(SshClient.class);
SshClient client3 = createMock(SshClient.class); SshClient client3 = createMock(SshClient.class);
SshClient client4 = createMock(SshClient.class); SshClient client4 = createMock(SshClient.class);
SshClient client5 = createMock(SshClient.class); SshClient client5 = createMock(SshClient.class);
expect(factory.create(new IPSocket("144.175.1.1", 22), new Credentials("root", "password1"))).andReturn( expect(factory.create(new IPSocket("144.175.1.1", 22), new Credentials("root", "password1"))).andReturn(
client1); client1);
runScriptAndService(client1, 1); expect(factory.create(new IPSocket("144.175.1.1", 22), new Credentials("defaultAdminUsername", "privateKey"))).andReturn(
client1New);
runScriptAndService(client1, client1New);
expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "password2"))).andReturn( expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "password2"))).andReturn(
client2).times(4); client2).times(4);
expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "romeo"))).andThrow( expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "romeo"))).andThrow(
new SshException("Auth fail")); new SshException("Auth fail"));
// run script without backgrounding (via predicate) // run script without backgrounding (via predicate)
client2.connect(); client2.connect();
expect(client2.exec("echo hello\n")).andReturn(new ExecResponse("hello\n", "", 0)); expect(client2.exec("echo hello\n")).andReturn(new ExecResponse("hello\n", "", 0));
client2.disconnect(); client2.disconnect();
// run script without backgrounding (via id) // run script without backgrounding (via id)
client2.connect(); client2.connect();
expect(client2.exec("echo hello\n")).andReturn(new ExecResponse("hello\n", "", 0)); expect(client2.exec("echo hello\n")).andReturn(new ExecResponse("hello\n", "", 0));
client2.disconnect(); client2.disconnect();
client2.connect(); client2.connect();
try { try {
runScript(client2, "runScriptWithCreds", runScript(client2, "runScriptWithCreds",
Strings2.toStringAndClose(StubComputeServiceIntegrationTest.class Strings2.toStringAndClose(StubComputeServiceIntegrationTest.class
.getResourceAsStream("/runscript.sh")), 2); .getResourceAsStream("/runscript.sh")), 2);
} catch (IOException e) { } catch (IOException e) {
Throwables.propagate(e); Throwables.propagate(e);
} }
client2.disconnect(); client2.disconnect();
expect(factory.create(new IPSocket("144.175.1.3", 22), new Credentials("root", "password3"))).andReturn( expect(factory.create(new IPSocket("144.175.1.3", 22), new Credentials("root", "password3"))).andReturn(
client3).times(2); client3).times(2);
expect(factory.create(new IPSocket("144.175.1.4", 22), new Credentials("root", "password4"))).andReturn( expect(factory.create(new IPSocket("144.175.1.4", 22), new Credentials("root", "password4"))).andReturn(
client4).times(2); client4).times(2);
expect(factory.create(new IPSocket("144.175.1.5", 22), new Credentials("root", "password5"))).andReturn( expect(factory.create(new IPSocket("144.175.1.5", 22), new Credentials("root", "password5"))).andReturn(
client5).times(2); client5).times(2);
runScriptAndInstallSsh(client3, "bootstrap", 3); runScriptAndInstallSsh(client3, "bootstrap", 3);
runScriptAndInstallSsh(client4, "bootstrap", 4); runScriptAndInstallSsh(client4, "bootstrap", 4);
runScriptAndInstallSsh(client5, "bootstrap", 5); runScriptAndInstallSsh(client5, "bootstrap", 5);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.1", 22)), factory.create(eq(new IPSocket("144.175.1.1", 22)), eq(new Credentials("defaultAdminUsername",
eq(new Credentials("defaultAdminUsername", "privateKey")))).andReturn(client1); "privateKey")))).andReturn(client1);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.2", 22)), factory.create(eq(new IPSocket("144.175.1.2", 22)), eq(new Credentials("defaultAdminUsername",
eq(new Credentials("defaultAdminUsername", "privateKey")))).andReturn(client2); "privateKey")))).andReturn(client2);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.3", 22)), factory.create(eq(new IPSocket("144.175.1.3", 22)), eq(new Credentials("defaultAdminUsername",
eq(new Credentials("defaultAdminUsername", "privateKey")))).andReturn(client3); "privateKey")))).andReturn(client3);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.4", 22)), factory.create(eq(new IPSocket("144.175.1.4", 22)), eq(new Credentials("defaultAdminUsername",
eq(new Credentials("defaultAdminUsername", "privateKey")))).andReturn(client4); "privateKey")))).andReturn(client4);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.5", 22)), factory.create(eq(new IPSocket("144.175.1.5", 22)), eq(new Credentials("defaultAdminUsername",
eq(new Credentials("defaultAdminUsername", "privateKey")))).andReturn(client5); "privateKey")))).andReturn(client5);
helloAndJava(client2); helloAndJava(client2);
helloAndJava(client3); helloAndJava(client3);
@ -202,6 +205,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
replay(factory); replay(factory);
replay(client1); replay(client1);
replay(client1New);
replay(client2); replay(client2);
replay(client3); replay(client3);
replay(client4); replay(client4);
@ -210,17 +214,34 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
bind(SshClient.Factory.class).toInstance(factory); bind(SshClient.Factory.class).toInstance(factory);
} }
private void runScriptAndService(SshClient client, int nodeId) { private void runScriptAndService(SshClient client, SshClient clientNew) {
client.connect(); client.connect();
try { try {
runScript(client, "jboss", Strings2.toStringAndClose(StubComputeServiceIntegrationTest.class String scriptName = "jboss";
.getResourceAsStream("/initscript_with_jboss.sh")), nodeId); client.put("/tmp/init-" + scriptName, Strings2.toStringAndClose(StubComputeServiceIntegrationTest.class
.getResourceAsStream("/initscript_with_jboss.sh")));
expect(client.exec("chmod 755 /tmp/init-" + scriptName)).andReturn(EXEC_GOOD);
expect(client.exec("ln -fs /tmp/init-" + scriptName + " " + scriptName)).andReturn(EXEC_GOOD);
expect(client.getUsername()).andReturn("root").atLeastOnce();
expect(client.getHostAddress()).andReturn(clientNew + "").atLeastOnce();
expect(client.exec("./" + scriptName + " init")).andReturn(EXEC_GOOD);
// note we have to reconnect here, as we updated the login user.
client.disconnect();
clientNew.connect();
expect(clientNew.getUsername()).andReturn("defaultAdminUsername").atLeastOnce();
expect(clientNew.getHostAddress()).andReturn(clientNew + "").atLeastOnce();
expect(clientNew.exec("ln -fs /tmp/init-" + scriptName + " " + scriptName)).andReturn(EXEC_GOOD);
expect(clientNew.exec("sudo ./" + scriptName + " start")).andReturn(EXEC_GOOD);
expect(clientNew.exec("sudo ./" + scriptName + " status")).andReturn(EXEC_GOOD);
// next status says the script is done, since not found.
expect(clientNew.exec("sudo ./" + scriptName + " status")).andReturn(EXEC_BAD);
expect(clientNew.exec("sudo ./" + scriptName + " tail")).andReturn(EXEC_GOOD);
expect(clientNew.exec("sudo ./" + scriptName + " tailerr")).andReturn(EXEC_GOOD);
} catch (IOException e) { } catch (IOException e) {
Throwables.propagate(e); Throwables.propagate(e);
} }
clientNew.disconnect();
client.disconnect();
} }
@ -229,7 +250,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
try { try {
runScript(client, scriptName, Strings2.toStringAndClose(StubComputeServiceIntegrationTest.class runScript(client, scriptName, Strings2.toStringAndClose(StubComputeServiceIntegrationTest.class
.getResourceAsStream("/initscript_with_java.sh")), nodeId); .getResourceAsStream("/initscript_with_java.sh")), nodeId);
} catch (IOException e) { } catch (IOException e) {
Throwables.propagate(e); Throwables.propagate(e);
} }
@ -239,8 +260,9 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
} }
private void runScript(SshClient client, String scriptName, String script, int nodeId) { private void runScript(SshClient client, String scriptName, String script, int nodeId) {
client.put(scriptName, script); client.put("/tmp/init-" + scriptName, script);
expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD); expect(client.exec("chmod 755 /tmp/init-" + scriptName)).andReturn(EXEC_GOOD);
expect(client.exec("ln -fs /tmp/init-" + scriptName + " " + scriptName)).andReturn(EXEC_GOOD);
expect(client.getUsername()).andReturn("root").atLeastOnce(); expect(client.getUsername()).andReturn("root").atLeastOnce();
expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce(); expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce();
expect(client.exec("./" + scriptName + " init")).andReturn(EXEC_GOOD); expect(client.exec("./" + scriptName + " init")).andReturn(EXEC_GOOD);
@ -282,7 +304,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
public void testAssignability() throws Exception { public void testAssignability() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
RestContext<ConcurrentMap<String, NodeMetadata>, ConcurrentMap<String, NodeMetadata>> stubContext = new ComputeServiceContextFactory() RestContext<ConcurrentMap<String, NodeMetadata>, ConcurrentMap<String, NodeMetadata>> stubContext = new ComputeServiceContextFactory()
.createContext(provider, identity, credential).getProviderSpecificContext(); .createContext(provider, identity, credential).getProviderSpecificContext();
} }
private static class PayloadEquals implements IArgumentMatcher, Serializable { private static class PayloadEquals implements IArgumentMatcher, Serializable {
@ -329,7 +351,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
return false; return false;
PayloadEquals other = (PayloadEquals) o; PayloadEquals other = (PayloadEquals) o;
return this.expected == null && other.expected == null || this.expected != null return this.expected == null && other.expected == null || this.expected != null
&& this.expected.equals(other.expected); && this.expected.equals(other.expected);
} }
@Override @Override

View File

@ -97,10 +97,11 @@ PermitRootLogin no
/etc/init.d/sshd reload||/etc/init.d/ssh reload /etc/init.d/sshd reload||/etc/init.d/ssh reload
awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}} awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}}
test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow
grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1" "hostname }' /proc/net/arp >> /etc/hosts
nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
which curl || (apt-get install -f -y -qq --force-yes curl || (apt-get update && apt-get install -f -y -qq --force-yes curl)) which curl || (apt-get install -f -y -qq --force-yes curl || (apt-get update && apt-get install -f -y -qq --force-yes curl))
(which java && java -fullversion 2>&1|egrep -q 1.6 ) || (which java && java -fullversion 2>&1|egrep -q 1.6 ) ||
curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://whirr.s3.amazonaws.com/0.3.0-incubating/sun/java/install |(bash)
echo nameserver 208.67.222.222 >> /etc/resolv.conf
rm -rf /var/cache/apt /usr/lib/vmware-tools rm -rf /var/cache/apt /usr/lib/vmware-tools
echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc

View File

@ -58,23 +58,41 @@ case $1 in
init) init)
default || exit 1 default || exit 1
jboss || exit 1 jboss || exit 1
mkdir -p ~/.ssh rm /etc/sudoers
cat >> ~/.ssh/authorized_keys <<'END_OF_FILE' cat >> /etc/sudoers <<'END_OF_FILE'
ssh-rsa root ALL = (ALL) ALL
%wheel ALL = (ALL) NOPASSWD:ALL
END_OF_FILE END_OF_FILE
chmod 600 ~/.ssh/authorized_keys chmod 0440 /etc/sudoers
mkdir -p /home/users/defaultAdminUsername
groupadd -f wheel
useradd -s /bin/bash -g wheel -d /home/users/defaultAdminUsername -p 'crypt(randompassword)' defaultAdminUsername
mkdir -p /home/users/defaultAdminUsername/.ssh
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE'
publicKey
END_OF_FILE
chmod 600 /home/users/defaultAdminUsername/.ssh/authorized_keys
chown -R defaultAdminUsername /home/users/defaultAdminUsername
exec 3<> /etc/ssh/sshd_config && awk -v TEXT="PasswordAuthentication no
PermitRootLogin no
" 'BEGIN {print TEXT}{print}' /etc/ssh/sshd_config >&3
/etc/init.d/sshd reload||/etc/init.d/ssh reload
awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}}
test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow
grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1" "hostname }' /proc/net/arp >> /etc/hosts
nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
which curl || (apt-get install -f -y -qq --force-yes curl || (apt-get update && apt-get install -f -y -qq --force-yes curl)) which curl || (apt-get install -f -y -qq --force-yes curl || (apt-get update && apt-get install -f -y -qq --force-yes curl))
(which java && java -fullversion 2>&1|egrep -q 1.6 ) || (which java && java -fullversion 2>&1|egrep -q 1.6 ) ||
curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://whirr.s3.amazonaws.com/0.3.0-incubating/sun/java/install |(bash)
echo nameserver 208.67.222.222 >> /etc/resolv.conf
rm -rf /var/cache/apt /usr/lib/vmware-tools rm -rf /var/cache/apt /usr/lib/vmware-tools
echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc
iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport 8080 -j ACCEPT iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport 8080 -j ACCEPT
iptables-save iptables-save
curl -X GET -s --retry 20 http://d37gkgjhl3prlk.cloudfront.net/jboss-6.0.0.Final.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -) curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://d37gkgjhl3prlk.cloudfront.net/jboss-7.0.0.CR1.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
mkdir -p /usr/local/jboss mkdir -p /usr/local/jboss
mv /usr/local/jboss-*/* /usr/local/jboss mv /usr/local/jboss-*/* /usr/local/jboss
(cd $JBOSS_HOME/standalone/configuration && sed 's~inet-address value=.*/~any-address/~g' standalone.xml > standalone.xml.new && mv standalone.xml.new standalone.xml)
chmod -R oug+r+w /usr/local/jboss chmod -R oug+r+w /usr/local/jboss
mkdir -p $INSTANCE_HOME mkdir -p $INSTANCE_HOME
@ -96,7 +114,7 @@ END_OF_SCRIPT
# add desired commands from the user # add desired commands from the user
cat >> $INSTANCE_HOME/jboss.sh <<'END_OF_SCRIPT' cat >> $INSTANCE_HOME/jboss.sh <<'END_OF_SCRIPT'
cd $INSTANCE_HOME cd $INSTANCE_HOME
java -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=lib/endorsed -classpath bin/run.jar org.jboss.Main -c jbossweb-standalone -b 0.0.0.0 java -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Dorg.jboss.boot.log.file=$JBOSS_HOME/standalone/log/boot.log -Dlogging.configuration=file:$JBOSS_HOME/standalone/configuration/logging.properties -jar $JBOSS_HOME/jboss-modules.jar -mp $JBOSS_HOME/modules -logmodule org.jboss.logmanager -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone -Djboss.home.dir=$JBOSS_HOME
END_OF_SCRIPT END_OF_SCRIPT
# add runscript footer # add runscript footer

View File

@ -76,10 +76,11 @@ END_OF_SCRIPT
# add desired commands from the user # add desired commands from the user
cat >> $INSTANCE_HOME/runScriptWithCreds.sh <<'END_OF_SCRIPT' cat >> $INSTANCE_HOME/runScriptWithCreds.sh <<'END_OF_SCRIPT'
cd $INSTANCE_HOME cd $INSTANCE_HOME
grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1" "hostname }' /proc/net/arp >> /etc/hosts
nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
which curl || (apt-get install -f -y -qq --force-yes curl || (apt-get update && apt-get install -f -y -qq --force-yes curl)) which curl || (apt-get install -f -y -qq --force-yes curl || (apt-get update && apt-get install -f -y -qq --force-yes curl))
(which java && java -fullversion 2>&1|egrep -q 1.6 ) || (which java && java -fullversion 2>&1|egrep -q 1.6 ) ||
curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://whirr.s3.amazonaws.com/0.3.0-incubating/sun/java/install |(bash)
echo nameserver 208.67.222.222 >> /etc/resolv.conf
rm -rf /var/cache/apt /usr/lib/vmware-tools rm -rf /var/cache/apt /usr/lib/vmware-tools
echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc