brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grk...@apache.org
Subject [2/8] git commit: Fixed install issues on Ubuntu and other non-root access images
Date Sat, 27 Sep 2014 19:08:51 GMT
Fixed install issues on Ubuntu and other non-root access images


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/b79e830c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/b79e830c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/b79e830c

Branch: refs/heads/master
Commit: b79e830c5c167f524a68b06dd717b89d9bd1a057
Parents: f61da96
Author: Andrew Kennedy <grkvlt@apache.org>
Authored: Wed Sep 24 15:48:28 2014 +0100
Committer: Andrew Kennedy <grkvlt@apache.org>
Committed: Wed Sep 24 15:48:28 2014 +0100

----------------------------------------------------------------------
 brooklyn-install.sh | 103 ++++++++++++++++++++++++-----------------------
 1 file changed, 53 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b79e830c/brooklyn-install.sh
----------------------------------------------------------------------
diff --git a/brooklyn-install.sh b/brooklyn-install.sh
index 638c1ac..179b6a0 100755
--- a/brooklyn-install.sh
+++ b/brooklyn-install.sh
@@ -15,31 +15,31 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-#
-# Brooklyn Install Script
+# Brooklyn remote install script.
 #
 # Usage:
-#     brooklyn-install.sh [-h] [-q] [-r] [-e] [-s] [-u user] [-k key] [-p port] hostname
+#     brooklyn-install.sh [-h] [-q] [-s] [-e] [-u user] [-k key] [-r root] [-p port] hostname
 #
 #set -x # DEBUG
 
 function help() {
     cat <<EOF
 
-Brooklyn Install Script
+Brooklyn remote install script.
 
 Options
 
     -q  Quiet install
-    -r  Set up random entropy for SSH
     -s  Create and set up user account
+    -e  Set up random entropy for SSH
     -u  Change the Brooklyn username (default 'brooklyn')
+    -r  Change the remote root username (default 'root')
     -k  The private key to use for SSH (default '~/.ssh/id_rsa')
     -p  The SSH port to connect to (default 22)
 
 Usage
 
-    brooklyn-install.sh [-q] [-r] [-s] [-u user] [-k key] [-p port] hostname
+    brooklyn-install.sh [-q] [-s] [-e] [-u user] [-r root] [-k key] [-p port] hostname
 
 Installs Brooklyn on the given hostname as 'brooklyn' or the specified
 user. Optionally it creates and configures the Brooklyn user. 
@@ -73,7 +73,7 @@ function error() {
 }
 
 function usage() {
-    echo "Usage: $(basename ${0}) [-h] [-q] [-r] [-s] [-u user] [-k key] [-p port] hostname"
+    echo "Usage: $(basename ${0}) [-h] [-q] [-s] [-e] [-u user] [-r root] [-k key] [-p port]
hostname"
     exit 1
 }
 
@@ -100,20 +100,23 @@ QUIET=false
 LOG="brooklyn-install.log"
 BROOKLYN_VERSION="0.7.0-M1"
 SSH=ssh
+ROOT=root
 
-while getopts ":hesu:k:q:p:r" o; do
+while getopts ":hqseu:r:k:p:" o; do
     case "${o}" in
         h)  help
             ;;
+        q)  QUIET=true
+            ;;
         s)  SETUP_USER=true
             ;;
-        u)  BROOKLYN_USER="${OPTARG}"
+        e)  SETUP_RANDOM=true
             ;;
-        k)  PRIVATE_KEY_FILE="${OPTARG}"
+        u)  BROOKLYN_USER="${OPTARG}"
             ;;
-        r)  SETUP_RANDOM=true
+        r)  ROOT="${OPTARG}"
             ;;
-        q)  QUIET=true
+        k)  PRIVATE_KEY_FILE="${OPTARG}"
             ;;
         p)  PORT="${OPTARG}"
             ;;            
@@ -131,6 +134,9 @@ HOST="$1"
 USER="${BROOKLYN_USER:-brooklyn}"
 PRIVATE_KEY_FILE="${PRIVATE_KEY_FILE:-${HOME}/.ssh/id_rsa}"
 SSH_PORT=${PORT:-22}
+if [ "${ROOT}" != "root" ]; then
+    SUDO="sudo"
+fi
 
 SSH_OPTS="-o StrictHostKeyChecking=no -p ${SSH_PORT}"
 if [ -f "${PRIVATE_KEY_FILE}" ]; then
@@ -147,9 +153,9 @@ log "Configuring '${HOST}:${PORT}'... "
 
 # Install packages
 log -n "Installing packages for curl, sed, tar, wget on '${HOST}:${SSH_PORT}'..."
-ssh ${SSH_OPTS} root@${HOST} "yum check-update || apt-get update" >> ${LOG} 2>&1
+ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} yum check-update || ${SUDO} apt-get update" >>
${LOG} 2>&1
 for package in "curl" "sed" "tar" "wget"; do
-    ssh ${SSH_OPTS} root@${HOST} "which ${package} || { yum check-update && yum -y
--nogpgcheck -q install ${package} || apt-get update && apt-get -y --allow-unauthenticated
install ${package}; }" >> ${LOG} 2>&1
+    ssh ${SSH_OPTS} ${ROOT}@${HOST} "which ${package} || { ${SUDO} yum -y --nogpgcheck -q
install ${package} || ${SUDO} ${SUDO} apt-get -y --allow-unauthenticated install ${package};
}" >> ${LOG} 2>&1
 done
 log " done!"
 
@@ -161,49 +167,49 @@ else
     check="java"
     JAVA_HOME="/usr"
 fi
-ssh ${SSH_OPTS} root@${HOST} "which ${check} || { yum -y -q install java-1.7.0-openjdk-devel
|| apt-get update && apt-get -y install openjdk-7-jdk; }" >> ${LOG} 2>&1
+ssh ${SSH_OPTS} ${ROOT}@${HOST} "which ${check} || { ${SUDO} yum -y -q install java-1.7.0-openjdk-devel
|| ${SUDO} apt-get -y install openjdk-7-jdk; }" >> ${LOG} 2>&1
 for java in "jre" "jdk" "java-1.7.0-openjdk" "java-1.7.0-openjdk-amd64"; do
-    if ssh ${SSH_OPTS} root@${HOST} "test -d /usr/lib/jvm/${java}"; then
+    if ssh ${SSH_OPTS} ${ROOT}@${HOST} "test -d /usr/lib/jvm/${java}"; then
         JAVA_HOME="/usr/lib/jvm/${java}/" && echo "Java: ${JAVA_HOME}" >> ${LOG}
     fi
 done
-ssh ${SSH_OPTS} root@${HOST}  "test -x ${JAVA_HOME}/bin/${check}" >> ${LOG} 2>&1
|| fail "Java is not installed"
+ssh ${SSH_OPTS} ${ROOT}@${HOST}  "test -x ${JAVA_HOME}/bin/${check}" >> ${LOG} 2>&1
|| fail "Java is not installed"
 log "done!"
 
 # Increase linux kernel entropy for faster ssh connections
 if [ "${SETUP_RANDOM}" ]; then
     log -n "Installing rng-tool to increase entropy on '${HOST}:${SSH_PORT}'... "
-    ssh ${SSH_OPTS} root@${HOST} "which rng-tools || { yum -y -q install rng-tools || apt-get
-y install rng-tools; }" >> ${LOG} 2>&1
-    if ssh ${SSH_OPTS} root@${HOST} "test -f /etc/default/rng-tools"; then
-        echo "HRNGDEVICE=/dev/urandom" | ssh ${SSH_OPTS} root@${HOST} "cat >> /etc/default/rng-tools"
-        ssh ${SSH_OPTS} root@${HOST} "/etc/init.d/rng-tools start" >> ${LOG} 2>&1
+    ssh ${SSH_OPTS} ${ROOT}@${HOST} "which rng-tools || { ${SUDO} yum -y -q install rng-tools
|| ${SUDO} apt-get -y install rng-tools; }" >> ${LOG} 2>&1
+    if ssh ${SSH_OPTS} ${ROOT}@${HOST} "test -f /etc/default/rng-tools"; then
+        echo "HRNGDEVICE=/dev/urandom" | ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} cat >>
/etc/default/rng-tools"
+        ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} /etc/init.d/rng-tools start" >> ${LOG}
2>&1
     else
-        echo "EXTRAOPTIONS=\"-r /dev/urandom\"" | ssh ${SSH_OPTS} root@${HOST} "cat >>
/etc/sysconfig/rngd"
-        ssh ${SSH_OPTS} root@${HOST} "/etc/init.d/rngd start" >> ${LOG} 2>&1
+        echo "EXTRAOPTIONS=\"-r /dev/urandom\"" | ssh ${SSH_OPTS} ${ROOT}@${HOST} "cat >>
/etc/sysconfig/rngd"
+        ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} /etc/init.d/rngd start" >> ${LOG}
2>&1
     fi
     log "done!"
 fi
 
 # Create Brooklyn user if required
-if ! ssh ${SSH_OPTS} root@${HOST} "id ${USER} > /dev/null 2>&1"; then
+if ! ssh ${SSH_OPTS} ${ROOT}@${HOST} "id ${USER} > /dev/null 2>&1"; then
     if [ -z "${SETUP_USER}" ]; then
         error "User '${USER}' does not exist on ${HOST}"
     fi
     log -n "Creating user '${USER}'..."
-    ssh ${SSH_OPTS} root@${HOST}  "useradd ${USER} -s /bin/bash -d /home/${USER} -m" >>
${LOG} 2>&1
-    ssh ${SSH_OPTS} root@${HOST}  "id ${USER}" >> ${LOG} 2>&1 || fail "User
was not created"
+    ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} useradd ${USER} -s /bin/bash -d /home/${USER}
-m" >> ${LOG} 2>&1
+    ssh ${SSH_OPTS} ${ROOT}@${HOST} "id ${USER}" >> ${LOG} 2>&1 || fail "User
was not created"
     log "done!"
 fi
 
 # Setup Brooklyn user
 if [ "${SETUP_USER}" ]; then
     log -n "Setting up user '${USER}'... "
-    ssh ${SSH_OPTS} root@${HOST} "echo '${USER} ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers"
-    ssh ${SSH_OPTS} root@${HOST} "sed -i.brooklyn.bak 's/.*requiretty.*/#brooklyn-removed-require-tty/'
/etc/sudoers"
-    ssh ${SSH_OPTS} root@${HOST} "mkdir -p /home/${USER}/.ssh"
-    ssh ${SSH_OPTS} root@${HOST} "chmod 700 /home/${USER}/.ssh"
-    ssh ${SSH_OPTS} root@${HOST} "echo ${SSH_PUBLIC_KEY_DATA} >> /home/${USER}/.ssh/authorized_keys"
-    ssh ${SSH_OPTS} root@${HOST} "chown -R ${USER}.${USER} /home/${USER}/.ssh"
+    echo "${USER} ALL = (ALL) NOPASSWD: ALL" | ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} tee
-a /etc/sudoers"
+    ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} sed -i.brooklyn.bak 's/.*requiretty.*/#brooklyn-removed-require-tty/'
/etc/sudoers"
+    ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} mkdir -p /home/${USER}/.ssh"
+    ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} chmod 700 /home/${USER}/.ssh"
+    echo "${SSH_PUBLIC_KEY_DATA}" | ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} tee -a /home/${USER}/.ssh/authorized_keys"
+    ssh ${SSH_OPTS} ${ROOT}@${HOST} "${SUDO} chown -R ${USER}.${USER} /home/${USER}/.ssh"
     ssh ${SSH_OPTS} ${USER}@${HOST} "ssh-keygen -q -t rsa -N \"\" -f .ssh/id_rsa"
     ssh ${SSH_OPTS} ${USER}@${HOST} "ssh-keygen -y -f .ssh/id_rsa >> .ssh/authorized_keys"
     log "done!"
@@ -235,38 +241,35 @@ ssh ${SSH_OPTS} ${USER}@${HOST} "cat > .brooklyn/catalog.xml" <<EOF
     <name>Brooklyn Demos</name>
 
     <template type="brooklyn.demo.WebClusterDatabaseExample" name="Demo Web Cluster with
DB">
-      <description>Deploys a demonstration web application to a managed JBoss cluster
with elasticity, persisting to a MySQL</description>
-      <iconUrl>http://downloads.cloudsoftcorp.com/brooklyn/catalog/logos/JBoss_by_Red_Hat.png</iconUrl>
+        <description>Deploys a demonstration web application to a managed JBoss cluster
with elasticity, persisting to a MySQL</description>
+        <iconUrl>http://downloads.cloudsoftcorp.com/brooklyn/catalog/logos/JBoss_by_Red_Hat.png</iconUrl>
     </template>
 
     <template type="brooklyn.demo.GlobalWebFabricExample" name="Demo GeoDNS Web Fabric
DB">
-      <description>Deploys a demonstration web application to JBoss clusters around
the world</description>
-      <iconUrl>http://downloads.cloudsoftcorp.com/brooklyn/catalog/logos/JBoss_by_Red_Hat.png</iconUrl>
+        <description>Deploys a demonstration web application to JBoss clusters around
the world</description>
+        <iconUrl>http://downloads.cloudsoftcorp.com/brooklyn/catalog/logos/JBoss_by_Red_Hat.png</iconUrl>
     </template>
 
     <template type="brooklyn.demo.NodeJsTodoApplication" name="NodeJs TODO application">
-      <description>Deploys a Nodejs TODO application around the world</description>
-      <iconUrl>classpath://nodejs-logo.png</iconUrl>
+        <description>Deploys a Nodejs TODO application around the world</description>
+        <iconUrl>classpath://nodejs-logo.png</iconUrl>
     </template>    
 
     <template type="brooklyn.demo.SimpleCassandraCluster" name="Demo Cassandra Cluster">
-      <description>Deploys a demonstration Cassandra clusters around the world</description>
-      <iconUrl>http://downloads.cloudsoftcorp.com/brooklyn/catalog/logos/cassandra-sq-icon.jpg</iconUrl>
+        <description>Deploys a demonstration Cassandra clusters around the world</description>
+        <iconUrl>http://downloads.cloudsoftcorp.com/brooklyn/catalog/logos/cassandra-sq-icon.jpg</iconUrl>
     </template>
 
     <template type="brooklyn.demo.SimpleCouchDBCluster" name="Demo CouchDB">
-      <description>Deploys a demonstration CouchDB clusters around the world</description>
-      <iconUrl>http://downloads.cloudsoftcorp.com/brooklyn/catalog/logos/couchdb-logo-icon.png</iconUrl>
+        <description>Deploys a demonstration CouchDB clusters around the world</description>
+        <iconUrl>http://downloads.cloudsoftcorp.com/brooklyn/catalog/logos/couchdb-logo-icon.png</iconUrl>
     </template>
 
     <classpath>
-      <entry>http://search.maven.org/remotecontent?filepath=io/brooklyn/example/brooklyn-example-simple-web-cluster/${BROOKLYN_VERSION}/brooklyn-example-simple-web-cluster-${BROOKLYN_VERSION}.jar</entry>
-      <entry>http://search.maven.org/remotecontent?filepath=io/brooklyn/example/brooklyn-example-simple-nosql-cluster/${BROOKLYN_VERSION}/brooklyn-example-simple-nosql-cluster-${BROOKLYN_VERSION}.jar</entry>
+        <entry>http://search.maven.org/remotecontent?filepath=io/brooklyn/example/brooklyn-example-simple-web-cluster/${BROOKLYN_VERSION}/brooklyn-example-simple-web-cluster-${BROOKLYN_VERSION}.jar</entry>
+        <entry>http://search.maven.org/remotecontent?filepath=io/brooklyn/example/brooklyn-example-simple-nosql-cluster/${BROOKLYN_VERSION}/brooklyn-example-simple-nosql-cluster-${BROOKLYN_VERSION}.jar</entry>
     </classpath>
-
-
 </catalog>
-
 EOF
 
 log "done!"
@@ -279,11 +282,11 @@ ssh -n -f ${SSH_OPTS} ${USER}@${HOST} "nohup ./brooklyn-${BROOKLYN_VERSION}/bin/
 retry "ssh ${SSH_OPTS} ${USER}@${HOST} \"test -e ./brooklyn-${BROOKLYN_VERSION}/brooklyn-console.log\""
 retry "ssh ${SSH_OPTS} ${USER}@${HOST} \"grep -q \"Started Brooklyn console at\" ./brooklyn-${BROOKLYN_VERSION}/brooklyn-console.log
&>/dev/null\""
 
-URL=$(ssh ${SSH_OPTS} ${USER}@${HOST} "grep 'Started Brooklyn console at' ./brooklyn-${BROOKLYN_VERSION}/brooklyn-console.log
| cut -d' ' -f9 | tr -d ," 2>&1)
+URL=$(ssh ${SSH_OPTS} ${USER}@${HOST} "grep 'Started Brooklyn console at' ./brooklyn-${BROOKLYN_VERSION}/brooklyn-console.log
| cut -d' ' -f9 | tr -d ," | sed -e "s/127\.0\.0\.1/${HOST}/g" -e "s/0\.0\.0\.0/${HOST}/g"
2>&1)
 log "Brooklyn Console URL at ${URL}"
 
 if wget -qO- --retry-connrefused --no-check-certificate ${URL} &> /dev/null; then
-  log "Brooklyn is running at ${URL}"
+    log "Brooklyn is running at ${URL}"
 else
-  log "Brooklyn is not running at ${URL}"
+    log "Brooklyn is not running at ${URL}"
 fi


Mime
View raw message