You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2013/12/03 17:44:32 UTC

[3/4] Renamed folder cartridge_create to cartridge-create and init_scripts to init-scripts

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/ec2/healthcheck.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/ec2/healthcheck.sh b/tools/cartridge-create/init-scripts/php/ec2/healthcheck.sh
new file mode 100644
index 0000000..eb06412
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/ec2/healthcheck.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+# ----------------------------------------------------------------------------
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+# ----------------------------------------------------------------------------
+
+
+var=`nc -z localhost 80; echo $?`;
+if [ $var -eq 0 ]
+then
+    echo "port 80 is available" > /dev/null 2>&1
+else
+    echo "port 80 is not available" > /dev/null 2>&1
+    /etc/init.d/apache2 restart
+fi
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/ec2/stratos-init.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/ec2/stratos-init.sh b/tools/cartridge-create/init-scripts/php/ec2/stratos-init.sh
new file mode 100644
index 0000000..aab01ad
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/ec2/stratos-init.sh
@@ -0,0 +1,304 @@
+#!/bin/bash
+
+# ----------------------------------------------------------------------------
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+# ----------------------------------------------------------------------------
+
+# This script will be called from /etc/rc.local when the cartridge
+# instance is spawned. It will initiate all the tasks that needs to 
+# be run to bring the cartridge instance to operational state.
+
+export LOG=/var/log/stratos-cartridge.log
+instance_path=/opt
+PUBLIC_IP=""
+KEY=`uuidgen`
+CRON_DURATION=1
+RETRY_COUNT=30
+SLEEP_DURATION=3
+
+if [ ! -d ${instance_path}/payload ]; then
+
+    echo "creating payload dir ... " >> $LOG
+    mkdir ${instance_path}/payload
+    echo "payload dir created ... " >> $LOG
+    wget http://169.254.169.254/latest/user-data -O ${instance_path}/payload/payload.zip    
+    echo "payload copied  ... "  >> $LOG
+    unzip -d ${instance_path}/payload ${instance_path}/payload/payload.zip
+    echo "unzippeddd..." >> $LOG
+
+    for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+    do
+    echo "exporting to bashrc $i ... " >> $LOG
+        echo "export" ${i} >> /home/ubuntu/.bashrc
+    done
+    source /home/ubuntu/.bashrc
+
+fi
+
+
+echo ---------------------------- >> $LOG
+echo "getting public ip from metadata service" >> $LOG
+
+wget http://169.254.169.254/latest/meta-data/public-ipv4
+files="`cat public-ipv4`"
+if [[ -z ${files} ]]; then
+    echo "getting public ip" >> $LOG
+    for i in {1..30}
+    do
+      rm -f ./public-ipv4
+      wget http://169.254.169.254/latest/meta-data/public-ipv4
+      files="`cat public-ipv4`"
+      if [ -z $files ]; then
+          echo "Public ip is not yet assigned. Wait and continue for $i the time ..." >> $LOG
+          sleep $SLEEP_DURATION
+      else
+          echo "Public ip assigned" >> $LOG
+          break
+      fi
+    done
+
+    if [ -z $files ]; then
+      echo "Public ip is not yet assigned. So exit" >> $LOG
+      exit 0
+    fi
+    for x in $files
+    do
+        PUBLIC_IP="$x"
+    done
+
+
+else 
+   PUBLIC_IP="$files"
+fi
+
+
+for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+do
+    export ${i}
+done
+
+
+cp -f ${instance_path}/payload/ssl-cert-snakeoil.pem /etc/ssl/certs/ssl-cert-snakeoil.pem
+cp -f ${instance_path}/payload/ssl-cert-snakeoil.key /etc/ssl/private/ssl-cert-snakeoil.key
+echo "Restarting apache..." >> $LOG
+
+/etc/init.d/apache2 restart
+
+echo "Apache restarted..." >> $LOG
+
+
+echo "Logging sys variables .. PUBLIC_IP:${PUBLIC_IP}, HOST_NAME:${HOST_NAME}, KEY:${KEY}, PORTS=${PORTS}, BAM:${BAM_IP}, GITREPO:${GIT_REPO}" >> $LOG
+
+mkdir -p  /etc/agent/conf
+
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:agen=\"http://service.agent.cartridge.stratos.apache.org\">
+  <soapenv:Header/>
+  <soapenv:Body>
+     <agen:register>
+        <registrant> 
+           <alarmingLowerRate>${ALARMING_LOWER_RATE}</alarmingLowerRate>
+           <alarmingUpperRate>${ALARMING_UPPER_RATE}</alarmingUpperRate>
+           <hostName>${HOST_NAME}</hostName>
+           <key>${KEY}</key>
+          <maxInstanceCount>${MAX}</maxInstanceCount>
+	  <maxRequestsPerSecond>${MAX_REQUESTS_PER_SEC}</maxRequestsPerSecond>
+          <minInstanceCount>${MIN}</minInstanceCount> " > /etc/agent/conf/request.xml
+
+IFS='|' read -ra PT <<< "${PORTS}"
+for i in "${PT[@]}"; do
+IFS=':' read -ra PP <<< "$i"
+echo "          <portMappings>
+                        <primaryPort>${PP[1]}</primaryPort>
+                        <proxyPort>${PP[2]}</proxyPort>
+                        <type>${PP[0]}</type>
+                </portMappings>">> /etc/agent/conf/request.xml
+done
+
+echo "          <remoteHost>${PUBLIC_IP}</remoteHost>
+           <service>${SERVICE}</service>
+	   <remoteHost>${PUBLIC_IP}</remoteHost>
+           <roundsToAverage>${ROUNDS_TO_AVERAGE}</roundsToAverage>
+           <scaleDownFactor>${SCALE_DOWN_FACTOR}</scaleDownFactor>
+           <tenantRange>${TENANT_RANGE}</tenantRange>
+        </registrant>
+     </agen:register>
+  </soapenv:Body>
+</soapenv:Envelope>
+" >> /etc/agent/conf/request.xml
+
+echo "Creating repoinfo request  " >> $LOG
+echo "TENANT_ID and SERVICE ${TENANT_ID} and ${SERVICE} " >> $LOG
+set -- "${HOST_NAME}" 
+IFS="."; declare -a Array=($*)
+ALIAS="${Array[0]}"
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://org.apache.axis2/xsd\">
+   <soapenv:Header/>
+   <soapenv:Body>
+      <xsd:getRepositoryCredentials>
+         <xsd:tenantId>${TENANT_ID}</xsd:tenantId>
+         <xsd:cartridgeType>${SERVICE}</xsd:cartridgeType>
+         <xsd:alias>${ALIAS}</xsd:alias>
+      </xsd:getRepositoryCredentials>
+   </soapenv:Body>
+</soapenv:Envelope>" > /opt/repoinforequest.xml
+
+echo "Repoinfo request created " >> $LOG
+
+echo "Private Key....Copying to .ssh  " >> $LOG
+
+cp ${instance_path}/payload/id_rsa /root/.ssh/id_rsa
+chmod 0600 /root/.ssh/id_rsa
+echo "StrictHostKeyChecking no" >> /root/.ssh/config
+
+
+
+
+#echo "Getting repo username password from repoInfoService" >> $LOG
+#curl -X POST -H "Content-Type: text/xml" -d @/etc/agent/conf/request.xml --silent --output /dev/null "${CARTRIDGE_AGENT_EPR}"
+
+echo "Git repo sync" >> $LOG
+
+# If repo is available do a git pull, else clone
+echo "#!/bin/bash
+if [ -d \"${APP_PATH}/.git\" ]; then
+    cd ${APP_PATH}
+    
+    curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+   git config --global --bool --add http.sslVerify false
+   sudo git pull
+   rm ~/.netrc
+   sudo rm /root/.netrc
+
+    sudo chown -R www-data:www-data ${APP_PATH}/www
+    if [ -f \"${APP_PATH}/sql/alter.sql\" ]; then
+    	mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} < ${APP_PATH}/sql/alter.sql
+    fi
+else
+    sudo rm -f ${APP_PATH}/index.html
+   curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+   git config --global --bool --add http.sslVerify false
+   sudo git clone \${repo} ${APP_PATH}
+   rm ~/.netrc
+   sudo rm /root/.netrc
+ 
+
+    if [ -f \"${APP_PATH}/sql/init.sql\" ]; then
+        mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} < ${APP_PATH}/sql/init.sql
+    fi
+    echo \"SetEnv STRATOS_MYSQL_USER ${MYSQL_USER}
+    SetEnv STRATOS_MYSQL_HOST ${MYSQL_HOST}
+    SetEnv STRATOS_MYSQL_PASSWORD ${MYSQL_PASSWORD}
+    \" > /tmp/.htaccess
+    sudo mv /tmp/.htaccess ${APP_PATH}/
+    sudo chown -R www-data:www-data ${APP_PATH}/www
+    
+
+
+fi" > /opt/git.sh
+echo "File created.." >> $LOG
+chmod 755 /opt/git.sh
+
+
+
+while true
+do
+var=`nc -z localhost 80; echo $?`;
+if [ $var -eq 0 ]
+   then
+       echo "port 80 is available" >> $LOG
+       break
+   else
+       echo "port 80 is not available" >> $LOG
+   fi
+   sleep 1
+done
+
+
+while true
+do
+var=`nc -z localhost 443; echo $?`;
+if [ $var -eq 0 ]
+   then
+       echo "port 443 is available" >> $LOG
+       break
+   else
+       echo "port 443 is not available" >> $LOG
+   fi
+   sleep 1
+done
+
+
+
+echo "Sending register request to Cartridge agent service" >> $LOG
+
+curl -X POST -H "Content-Type: text/xml" -H "SOAPAction: urn:register" -d @/etc/agent/conf/request.xml -k --silent --output /dev/null "${CARTRIDGE_AGENT_EPR}"
+
+echo "Registered cartridge..." >> $LOG
+
+echo "running git clone........" >> $LOG
+su - ubuntu /opt/git.sh
+
+
+echo "setting up logging conf" >> $LOG
+
+
+echo "host:     ${BAM_IP}
+thriftPort:     ${BAM_PORT}
+
+#cartridge configs
+cartridgeAlias:  ${CARTRIDGE_ALIAS}
+tenantName:      ${HOST_NAME}
+tenantId:        ${TENANT_ID}
+localIP:         ${PUBLIC_IP}" > /opt/cartridge_data_publisher_1.0.2/conf/data_publisher.conf
+
+
+
+echo "started loggin ........."
+cd /opt/cartridge_data_publisher_1.0.2/dist/Debug/GNU-Linux-x86/
+nohup ./cartridge_data_publisher_1.0.2 /var/log/apache2/access.log /var/log/apache2/error.log >> /var/log/startos-data-publisher.log  &
+
+
+
+
+
+# ========================== // End of script ===========================================================

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/get-launch-params.rb
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/get-launch-params.rb b/tools/cartridge-create/init-scripts/php/get-launch-params.rb
new file mode 100644
index 0000000..c6368ca
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/get-launch-params.rb
@@ -0,0 +1,55 @@
+#! /usr/bin/ruby
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+### get-launch-params.rb
+
+# The following script obtains the launch parameters from 
+# the file /tmp/payload/launch-params, then parses out the 
+# parameters for this instance by using the launch index
+# of this particular EC2 instance.
+#
+# Pass the command the -e flag to output the instance 
+# parameters as exports of shell variables. Any other 
+# arguments are ignored.
+
+def get_launch_params(launch_params_file)
+  IO.readlines launch_params_file
+end
+
+export_stmt = ""
+
+launch_params = get_launch_params(
+  "/var/lib/cloud/instance/payload/launch-params")
+
+if launch_params.length > 0
+  instance_params_str = launch_params[0]
+
+  instance_params = instance_params_str.split(',')
+
+  export_stmt = "export " if ARGV.length > 0 && ARGV.include?("-e")
+
+  instance_params.each { |param|
+    puts export_stmt + param
+  }
+
+end
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/openstack/get-launch-params.rb
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/openstack/get-launch-params.rb b/tools/cartridge-create/init-scripts/php/openstack/get-launch-params.rb
new file mode 100644
index 0000000..c6368ca
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/openstack/get-launch-params.rb
@@ -0,0 +1,55 @@
+#! /usr/bin/ruby
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+### get-launch-params.rb
+
+# The following script obtains the launch parameters from 
+# the file /tmp/payload/launch-params, then parses out the 
+# parameters for this instance by using the launch index
+# of this particular EC2 instance.
+#
+# Pass the command the -e flag to output the instance 
+# parameters as exports of shell variables. Any other 
+# arguments are ignored.
+
+def get_launch_params(launch_params_file)
+  IO.readlines launch_params_file
+end
+
+export_stmt = ""
+
+launch_params = get_launch_params(
+  "/var/lib/cloud/instance/payload/launch-params")
+
+if launch_params.length > 0
+  instance_params_str = launch_params[0]
+
+  instance_params = instance_params_str.split(',')
+
+  export_stmt = "export " if ARGV.length > 0 && ARGV.include?("-e")
+
+  instance_params.each { |param|
+    puts export_stmt + param
+  }
+
+end
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/openstack/healthcheck.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/openstack/healthcheck.sh b/tools/cartridge-create/init-scripts/php/openstack/healthcheck.sh
new file mode 100644
index 0000000..4194608
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/openstack/healthcheck.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+var=`nc -z localhost 80; echo $?`;
+if [ $var -eq 0 ]
+then
+    echo "port 80 is available" > /dev/null 2>&1
+else
+    echo "port 80 is not available" > /dev/null 2>&1
+    /etc/init.d/apache2 restart
+fi

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/openstack/stratos-init.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/openstack/stratos-init.sh b/tools/cartridge-create/init-scripts/php/openstack/stratos-init.sh
new file mode 100755
index 0000000..503790f
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/openstack/stratos-init.sh
@@ -0,0 +1,293 @@
+#!/bin/bash
+
+# ----------------------------------------------------------------------------
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+# ----------------------------------------------------------------------------
+
+# This script will be called from /etc/rc.local when the cartridge
+# instance is spawned. It will initiate all the tasks that needs to 
+# be run to bring the cartridge instance to operational state.
+
+export LOG=/var/log/stratos-cartridge.log
+instance_path=/var/lib/cloud/instance
+PUBLIC_IP=""
+KEY=`uuidgen`
+CRON_DURATION=1
+RETRY_COUNT=30
+SLEEP_DURATION=3
+ACCESSLOG="/var/log/apache2/access.log"
+ERRORLOG="/var/log/apache2/error.log"
+
+
+if [ ! -d ${instance_path}/payload ]; then
+
+    echo "creating payload dir ... " >> $LOG
+    mkdir ${instance_path}/payload
+    echo "payload dir created ... " >> $LOG
+    cp ${instance_path}/user-data.txt ${instance_path}/payload/user-data.zip
+    echo "payload copied  ... "  >> $LOG
+    unzip -d ${instance_path}/payload ${instance_path}/payload/user-data.zip
+    echo "unzippeddd..." >> $LOG
+
+    for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+    do
+    echo "exporting to bashrc $i ... " >> $LOG
+        echo "export" ${i} >> /home/ubuntu/.bashrc
+    done
+    source /home/ubuntu/.bashrc
+
+fi
+
+
+echo ---------------------------- >> $LOG
+echo "getting public ip from metadata service" >> $LOG
+
+wget http://169.254.169.254/latest/meta-data/public-ipv4
+files="`cat public-ipv4`"
+if [[ -z ${files} ]]; then
+    echo "getting public ip" >> $LOG
+    for i in {1..30}
+    do
+      rm -f ./public-ipv4
+      wget http://169.254.169.254/latest/meta-data/public-ipv4
+      files="`cat public-ipv4`"
+      if [ -z $files ]; then
+          echo "Public ip is not yet assigned. Wait and continue for $i the time ..." >> $LOG
+          sleep $SLEEP_DURATION
+      else
+          echo "Public ip assigned" >> $LOG
+          break
+      fi
+    done
+
+    if [ -z $files ]; then
+      echo "Public ip is not yet assigned. So exit" >> $LOG
+      exit 0
+    fi
+    for x in $files
+    do
+        PUBLIC_IP="$x"
+    done
+
+
+else 
+   PUBLIC_IP="$files"
+fi
+
+
+for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+do
+    export ${i}
+done
+
+
+cp -f ${instance_path}/payload/ssl-cert-snakeoil.pem /etc/ssl/certs/ssl-cert-snakeoil.pem
+cp -f ${instance_path}/payload/ssl-cert-snakeoil.key /etc/ssl/private/ssl-cert-snakeoil.key
+echo "Restarting apache..." >> $LOG
+
+/etc/init.d/apache2 restart
+
+echo "Apache restarted..." >> $LOG
+
+
+echo "Logging sys variables .. PUBLIC_IP:${PUBLIC_IP}, HOST_NAME:${HOST_NAME}, KEY:${KEY}, PORTS=${PORTS}, BAM:${BAM_IP}, GITREPO:${GIT_REPO}" >> $LOG
+
+mkdir -p  /etc/agent/conf
+
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:agen=\"http://service.agent.cartridge.stratos.apache.org\">
+  <soapenv:Header/>
+  <soapenv:Body>
+     <agen:register>
+        <registrant> 
+           <alarmingLowerRate>${ALARMING_LOWER_RATE}</alarmingLowerRate>
+           <alarmingUpperRate>${ALARMING_UPPER_RATE}</alarmingUpperRate>
+           <hostName>${HOST_NAME}</hostName>
+           <key>${KEY}</key>
+          <maxInstanceCount>${MAX}</maxInstanceCount>
+	  <maxRequestsPerSecond>${MAX_REQUESTS_PER_SEC}</maxRequestsPerSecond>
+          <minInstanceCount>${MIN}</minInstanceCount> " > /etc/agent/conf/request.xml
+
+IFS='|' read -ra PT <<< "${PORTS}"
+for i in "${PT[@]}"; do
+IFS=':' read -ra PP <<< "$i"
+echo "          <portMappings>
+                        <primaryPort>${PP[1]}</primaryPort>
+                        <proxyPort>${PP[2]}</proxyPort>
+                        <type>${PP[0]}</type>
+                </portMappings>">> /etc/agent/conf/request.xml
+done
+
+echo "          <remoteHost>${PUBLIC_IP}</remoteHost>
+           <service>${SERVICE}</service>
+	   <remoteHost>${PUBLIC_IP}</remoteHost>
+           <roundsToAverage>${ROUNDS_TO_AVERAGE}</roundsToAverage>
+           <scaleDownFactor>${SCALE_DOWN_FACTOR}</scaleDownFactor>
+           <tenantRange>${TENANT_RANGE}</tenantRange>
+        </registrant>
+     </agen:register>
+  </soapenv:Body>
+</soapenv:Envelope>
+" >> /etc/agent/conf/request.xml
+
+echo "Creating repoinfo request  " >> $LOG
+echo "TENANT_ID and SERVICE ${TENANT_ID} and ${SERVICE} " >> $LOG
+set -- "${HOST_NAME}" 
+IFS="."; declare -a Array=($*)
+ALIAS="${Array[0]}"
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://org.apache.axis2/xsd\">
+   <soapenv:Header/>
+   <soapenv:Body>
+      <xsd:getRepositoryCredentials>
+         <xsd:tenantId>${TENANT_ID}</xsd:tenantId>
+         <xsd:cartridgeType>${SERVICE}</xsd:cartridgeType>
+         <xsd:alias>${ALIAS}</xsd:alias>
+      </xsd:getRepositoryCredentials>
+   </soapenv:Body>
+</soapenv:Envelope>" > /opt/repoinforequest.xml
+
+echo "Repoinfo request created " >> $LOG
+
+
+echo "Git repo sync" >> $LOG
+
+# If repo is available do a git pull, else clone
+echo "#!/bin/bash
+if [ -d \"${APP_PATH}/.git\" ]; then
+    cd ${APP_PATH}
+
+    curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+   git config --global --bool --add http.sslVerify false
+   sudo git pull
+   rm ~/.netrc
+   sudo rm /root/.netrc
+
+    sudo chown -R www-data:www-data ${APP_PATH}/www
+    if [ -f \"${APP_PATH}/sql/alter.sql\" ]; then
+    	mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} < ${APP_PATH}/sql/alter.sql
+    fi
+else
+    sudo rm -f ${APP_PATH}/index.html
+   curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+   git config --global --bool --add http.sslVerify false
+   sudo git clone \${repo} ${APP_PATH}
+   rm ~/.netrc
+   sudo rm /root/.netrc
+ 
+
+    if [ -f \"${APP_PATH}/sql/init.sql\" ]; then
+        mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} < ${APP_PATH}/sql/init.sql
+    fi
+    echo \"SetEnv STRATOS_MYSQL_USER ${MYSQL_USER}
+    SetEnv STRATOS_MYSQL_HOST ${MYSQL_HOST}
+    SetEnv STRATOS_MYSQL_PASSWORD ${MYSQL_PASSWORD}
+    \" > /tmp/.htaccess
+    sudo mv /tmp/.htaccess ${APP_PATH}/
+    sudo chown -R www-data:www-data ${APP_PATH}/www
+    
+
+
+fi" > /opt/git.sh
+echo "File created.." >> $LOG
+chmod 755 /opt/git.sh
+
+
+
+while true
+do
+var=`nc -z localhost 80; echo $?`;
+if [ $var -eq 0 ]
+   then
+       echo "port 80 is available" >> $LOG
+       break
+   else
+       echo "port 80 is not available" >> $LOG
+   fi
+   sleep 1
+done
+
+
+while true
+do
+var=`nc -z localhost 443; echo $?`;
+if [ $var -eq 0 ]
+   then
+       echo "port 443 is available" >> $LOG
+       break
+   else
+       echo "port 443 is not available" >> $LOG
+   fi
+   sleep 1
+done
+
+
+
+echo "Sending register request to Cartridge agent service" >> $LOG
+
+curl -X POST -H "Content-Type: text/xml" -H "SOAPAction: urn:register" -d @/etc/agent/conf/request.xml -k --silent --output /dev/null "${CARTRIDGE_AGENT_EPR}"
+
+echo "Registered cartridge..." >> $LOG
+
+echo "running git clone........" >> $LOG
+su - ubuntu /opt/git.sh
+
+
+echo "setting up logging conf" >> $LOG
+
+
+echo "host:     ${BAM_IP}
+thriftPort:     ${BAM_PORT}
+
+#cartridge configs
+cartridgeAlias:  ${SERVICE}
+tenantName:      ${HOST_NAME}
+tenantId:      ${TENANT_ID}
+localIP:         ${PUBLIC_IP}" > /opt/cartridge_data_publisher_1.0.2/conf/data_publisher.conf
+
+
+echo "started loggin ........."
+cd /opt/cartridge_data_publisher_1.0.2/dist/Debug/GNU-Linux-x86/
+nohup ./cartridge_data_publisher_1.0.2 ${ACCESSLOG} ${ERRORLOG} 2>&1> /dev/null &
+
+echo "logging started........."
+
+# ========================== // End of script ===========================================================

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/php
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/php b/tools/cartridge-create/init-scripts/php/php
new file mode 100644
index 0000000..9fe5339
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/php
@@ -0,0 +1,49 @@
+#!/bin/bash
+# ----------------------------------------------------------------------------
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+# ----------------------------------------------------------------------------
+
+INSTANCE=$1
+INSTANCE_USER=$2
+KEY=$3
+SOFTWARE=$4
+
+SCP="scp -i ./$KEY"
+SSH="ssh -i ./$KEY"
+
+$SCP ./openstack/wso2-cartridge-init.sh $INSTANCE_USER@$INSTANCE:
+$SCP ./php.ctrg $INSTANCE_USER@$INSTANCE:
+$SCP ./openstack/get-launch-params.rb $INSTANCE_USER@$INSTANCE:
+$SCP ./cc/ssl-cert-snakeoil.pem $INSTANCE_USER@$INSTANCE:
+$SCP ./cc/ssl-cert-snakeoil.key $INSTANCE_USER@$INSTANCE:
+$SCP ./ $INSTANCE_USER@$INSTANCE:
+$SCP ./thrift-0.8.0.tar.gz $INSTANCE_USER@$INSTANCE:
+$SCP ./default $INSTANCE_USER@$INSTANCE:
+$SCP ./default-ssl $INSTANCE_USER@$INSTANCE:
+
+# Copy additional software
+arr=$(echo $SOFTWARE | tr ":" "\n")
+for x in $arr
+do
+   $SCP $x $INSTANCE_USER@$INSTANCE:
+done
+
+# Execute the cartridge creation process in the remoter server
+$SSH $INSTANCE_USER@$INSTANCE "sudo chmod 755 ./php.ctrg;sudo ./php.ctrg"

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/php.ctrg
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/php.ctrg b/tools/cartridge-create/init-scripts/php/php.ctrg
new file mode 100644
index 0000000..cbaf639
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/php.ctrg
@@ -0,0 +1,65 @@
+#!/bin/bash
+# ----------------------------------------------------------------------------
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+# ----------------------------------------------------------------------------
+
+    mv ./wso2-cartridge-init.sh /opt/
+    mv ./get-launch-params.rb /opt/
+    mv ./ssl-cert-snakeoil.pem /etc/ssl/certs/
+    mv ./ssl-cert-snakeoil.key /etc/ssl/private/
+    mv ./cartridge_data_publisher_1.0.2.zip /opt/
+    mv ./thrift-0.8.0.tar.gz /opt/
+    mv ./*.tar.gz /opt/
+    mv ./*.zip /opt/
+    cp -f ./default /etc/apache2/sites-available/
+    cp -f ./default-ssl /etc/apache2/sites-available/
+    rm ./default
+    rm ./default-ssl
+    
+
+	apt-get update
+	# Next, all the packages.
+	
+	apt-get install -y \
+	nano zip build-essential mysql-client apache2 php5 php5-cli libapache2-mod-php5 php5-gd php5-mysql php-db php-pear \
+	php5-curl curl wget php5-ldap php5-adodb mailutils php5-imap php5-intl php5-sqlite php5-xmlrpc php5-xsl \
+	openssl ssl-cert ldap-utils php5-mcrypt mcrypt ufw fail2ban git libboost-all-dev ruby xml-twig-tools
+
+    # Install the thrift library
+    tar -zxf /opt/thrift-0.8.0.tar.gz -C/opt
+    cd /opt/thrift-0.8.0
+    ./configure --libdir=/usr/lib;make;make install
+    cd /opt
+    unzip cartridge_data_publisher_1.0.2.zip
+    cd /opt/cartridge_data_publisher_1.0.2
+    make
+
+
+	# Enable HTTPS:
+	a2enmod ssl
+	a2ensite default-ssl	
+
+    echo "#!/bin/bash -e
+chmod 755 /opt/wso2-cartridge-init.sh
+/opt/wso2-cartridge-init.sh > /var/log/wso2-cartridge-init.log
+exit 0
+    " > /etc/rc.local
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/thrift-0.8.0.tar.gz
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/thrift-0.8.0.tar.gz b/tools/cartridge-create/init-scripts/php/thrift-0.8.0.tar.gz
new file mode 100644
index 0000000..46a1a23
Binary files /dev/null and b/tools/cartridge-create/init-scripts/php/thrift-0.8.0.tar.gz differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/wso2.pem
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/wso2.pem b/tools/cartridge-create/init-scripts/php/wso2.pem
new file mode 100644
index 0000000..f4260f9
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/wso2.pem
@@ -0,0 +1,16 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQCp31ZRD9kPwKoxW3sh+4x2IfldCKEfHbo18LhvOnGPJcNzqHDy
+6WWxpxPAHNAMyvrAv+hUfX4fwSRctieTim0N+fTr+mRP0q4HHhEkvEmxoXs4Y7lz
+jrh5vhMBZBAXsSurHVp2Bpie1xyjW+ksuAziT2gw6KvipjJiGTjuLTnLmQIDAQAB
+AoGAMFvtNbx+PbbKfKyfXChBb2vykmKfg70xwqNZzghkRa0pfCaKqQx6r91xiPJq
+5Alw4yh+2nazThTs5hvRHnZ83tPFxKyekrOdFpFEwAdibmvM3ckfAmUqJErteFhp
+o524O37kWpzwBgk1rxwLHVxyoscVHF8vWSjk9jzvdor9XbUCQQDdPp+F/X5qQLZw
+xaYyHrWmLkRnFRaxxmiOQmvAxYKybMp0Ei8euy+wKHiNPBVPxn143hrag7a2GKIn
+hq6LwoiHAkEAxI7GYK47woZJHI6rjskjxT+DBNKjTmoDZVTa4KrWUVY1NfTC+/jI
+Ajm3cQ1QYnGEYyvlczgD3jvRdDtjJjGy3wJAV4JnkpX7pIdIIj7rR7PB4aM3Rxae
+TV7PCEXZXPxCf9RsF5EBtkQPzruTQznarB00j9Q6BuhGIqyHpt6st3cQjQJBAKtf
+oG7i+o+b7VrMuZ+Al4N+4Ijv7hqMK/HJjhycVsgL1dD5Wpe+TQRDtkEHTrLGLpsY
+xrEygYzdsr0YmlXOtxkCQQC46OoYuk/bZhp1gnFNtWXp73ZESphNOC/FovNKu5Os
+fbxKoqUbosXAi6wxuU1L+eojN0UNx98xyKjG/lyUog/m
+-----END RSA PRIVATE KEY-----
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/x.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/x.sh b/tools/cartridge-create/init-scripts/php/x.sh
new file mode 100644
index 0000000..1f42589
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/x.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+LOG=/tmp/me.log
+CARTRIDGE_AGENT_EPR="http://localhost/me.html"
+echo "Sending register request to Cartridge agent service\n" > $LOG
+for i in {1..2}
+do
+    #curl --write-out "%{http_code}\n" --silent --output /dev/null $CARTRIDGE_AGENT_EPR
+    curl -X POST -H "Content-Type: text/xml" -d @/tmp/request.xml --silent --output /dev/null "$CARTRIDGE_AGENT_EPR"
+    ret=$?
+    echo "return value:$ret" > $LOG
+    if [[ $ret -eq 2  ]]; then
+        echo "[curl] Failed to initialize" >> $LOG
+    fi
+    if [[ $ret -eq 5 || $ret -eq 6 || $ret -eq 7  ]]; then
+        echo "[curl] Resolving host failed" >> $LOG
+    fi
+    if [[ $ret -eq 28 ]]; then
+        echo "[curl] Operation timeout" >> $LOG
+    fi
+    if [[ $ret -eq 55 || $ret -eq 56 ]]; then
+        echo "[curl] Failed sending/receiving network data" >> $LOG
+    fi
+    if [[ $ret -eq 28 ]]; then
+        echo "Operation timeout" >> $LOG
+    fi
+done
+if [[ $ret -gt 0 ]]; then
+    echo "Sending cluster join message failed. So shutdown instance and exit" >> $LOG
+    exit 0
+fi

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/php/y.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/php/y.sh b/tools/cartridge-create/init-scripts/php/y.sh
new file mode 100644
index 0000000..a786460
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/php/y.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+LOG=/tmp/me.log
+CARTRIDGE_AGENT_EPR="http://localhost/me.html"
+echo "Sending register request to Cartridge agent service\n" > $LOG
+for i in {1..1}
+do
+    ret=`curl --write-out "%{http_code}\n" --silent --output /dev/null $CARTRIDGE_AGENT_EPR`
+    echo "return value:$ret" > $LOG
+    #if [[ $ret -eq 2  ]]; then
+    #    echo "[curl] Failed to initialize" >> $LOG
+    #fi
+done

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/tomcat/get-launch-params.rb
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/tomcat/get-launch-params.rb b/tools/cartridge-create/init-scripts/tomcat/get-launch-params.rb
new file mode 100644
index 0000000..0948d6a
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/tomcat/get-launch-params.rb
@@ -0,0 +1,53 @@
+#! /usr/bin/ruby
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+### get-launch-params.rb
+
+# The following script obtains the launch parameters from 
+# the file /tmp/payload/launch-params, then parses out the 
+# parameters for this instance by using the launch index
+# of this particular EC2 instance.
+#
+# Pass the command the -e flag to output the instance 
+# parameters as exports of shell variables. Any other 
+# arguments are ignored.
+
+def get_launch_params(launch_params_file)
+  IO.readlines launch_params_file
+end
+
+export_stmt = ""
+
+launch_params = get_launch_params(
+  "/var/lib/cloud/instance/payload/launch-params")
+
+if launch_params.length > 0
+  instance_params_str = launch_params[0]
+
+  instance_params = instance_params_str.split(',')
+
+  export_stmt = "export " if ARGV.length > 0 && ARGV.include?("-e")
+
+  instance_params.each { |param|
+    puts export_stmt + param
+  }
+
+end
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/tomcat/openstack/get-launch-params.rb
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/tomcat/openstack/get-launch-params.rb b/tools/cartridge-create/init-scripts/tomcat/openstack/get-launch-params.rb
new file mode 100644
index 0000000..c6368ca
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/tomcat/openstack/get-launch-params.rb
@@ -0,0 +1,55 @@
+#! /usr/bin/ruby
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+### get-launch-params.rb
+
+# The following script obtains the launch parameters from 
+# the file /tmp/payload/launch-params, then parses out the 
+# parameters for this instance by using the launch index
+# of this particular EC2 instance.
+#
+# Pass the command the -e flag to output the instance 
+# parameters as exports of shell variables. Any other 
+# arguments are ignored.
+
+def get_launch_params(launch_params_file)
+  IO.readlines launch_params_file
+end
+
+export_stmt = ""
+
+launch_params = get_launch_params(
+  "/var/lib/cloud/instance/payload/launch-params")
+
+if launch_params.length > 0
+  instance_params_str = launch_params[0]
+
+  instance_params = instance_params_str.split(',')
+
+  export_stmt = "export " if ARGV.length > 0 && ARGV.include?("-e")
+
+  instance_params.each { |param|
+    puts export_stmt + param
+  }
+
+end
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/tomcat/openstack/healthcheck.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/tomcat/openstack/healthcheck.sh b/tools/cartridge-create/init-scripts/tomcat/openstack/healthcheck.sh
new file mode 100644
index 0000000..27ab926
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/tomcat/openstack/healthcheck.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+var=`nc -z localhost 8080; echo $?`;
+if [ $var -eq 0 ]
+then
+    echo "port 8080 is available" > /dev/null 2>&1
+else
+    echo "port 8080 is not available" > /dev/null 2>&1
+    /etc/init.d/apache2 restart
+fi

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/tomcat/openstack/stratos-init.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/tomcat/openstack/stratos-init.sh b/tools/cartridge-create/init-scripts/tomcat/openstack/stratos-init.sh
new file mode 100755
index 0000000..ba30b44
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/tomcat/openstack/stratos-init.sh
@@ -0,0 +1,289 @@
+#!/bin/bash
+
+# ----------------------------------------------------------------------------
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+# ----------------------------------------------------------------------------
+
+# This script will be called from /etc/rc.local when the cartridge
+# instance is spawned. It will initiate all the tasks that needs to 
+# be run to bring the cartridge instance to operational state.
+
+export LOG=/var/log/stratos-cartridge.log
+instance_path=/var/lib/cloud/instance
+PUBLIC_IP=""
+KEY=`uuidgen`
+CRON_DURATION=1
+RETRY_COUNT=30
+SLEEP_DURATION=3
+
+if [ ! -d ${instance_path}/payload ]; then
+
+    echo "creating payload dir ... " >> $LOG
+    mkdir ${instance_path}/payload
+    echo "payload dir created ... " >> $LOG
+    cp ${instance_path}/user-data.txt ${instance_path}/payload/user-data.zip
+    echo "payload copied  ... "  >> $LOG
+    unzip -d ${instance_path}/payload ${instance_path}/payload/user-data.zip
+    echo "unzippeddd..." >> $LOG
+
+    for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+    do
+    echo "exporting to bashrc $i ... " >> $LOG
+        echo "export" ${i} >> /home/ubuntu/.bashrc
+    done
+    source /home/ubuntu/.bashrc
+
+fi
+
+
+echo ---------------------------- >> $LOG
+echo "getting public ip from metadata service" >> $LOG
+
+wget http://169.254.169.254/latest/meta-data/public-ipv4
+files="`cat public-ipv4`"
+if [[ -z ${files} ]]; then
+    echo "getting public ip" >> $LOG
+    for i in {1..30}
+    do
+      rm -f ./public-ipv4
+      wget http://169.254.169.254/latest/meta-data/public-ipv4
+      files="`cat public-ipv4`"
+      if [ -z $files ]; then
+          echo "Public ip is not yet assigned. Wait and continue for $i the time ..." >> $LOG
+          sleep $SLEEP_DURATION
+      else
+          echo "Public ip assigned" >> $LOG
+          break
+      fi
+    done
+
+    if [ -z $files ]; then
+      echo "Public ip is not yet assigned. So exit" >> $LOG
+      exit 0
+    fi
+    for x in $files
+    do
+        PUBLIC_IP="$x"
+    done
+
+
+else 
+   PUBLIC_IP="$files"
+fi
+
+
+for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+do
+    export ${i}
+done
+
+
+echo "Restarting apache..." >> $LOG
+
+/etc/init.d/apache2 restart
+
+echo "Apache restarted..." >> $LOG
+
+
+echo "Logging sys variables .. PUBLIC_IP:${PUBLIC_IP}, HOST_NAME:${HOST_NAME}, KEY:${KEY}, PORTS=${PORTS}, BAM:${BAM_IP}, GITREPO:${GIT_REPO}" >> $LOG
+
+mkdir -p  /etc/agent/conf
+
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:agen=\"http://service.agent.cartridge.stratos.apache.org\">
+  <soapenv:Header/>
+  <soapenv:Body>
+     <agen:register>
+        <registrant> 
+           <alarmingLowerRate>${ALARMING_LOWER_RATE}</alarmingLowerRate>
+           <alarmingUpperRate>${ALARMING_UPPER_RATE}</alarmingUpperRate>
+           <hostName>${HOST_NAME}</hostName>
+           <key>${KEY}</key>
+          <maxInstanceCount>${MAX}</maxInstanceCount>
+	  <maxRequestsPerSecond>${MAX_REQUESTS_PER_SEC}</maxRequestsPerSecond>
+          <minInstanceCount>${MIN}</minInstanceCount> " > /etc/agent/conf/request.xml
+
+IFS='|' read -ra PT <<< "${PORTS}"
+for i in "${PT[@]}"; do
+IFS=':' read -ra PP <<< "$i"
+echo "          <portMappings>
+                        <primaryPort>${PP[1]}</primaryPort>
+                        <proxyPort>${PP[2]}</proxyPort>
+                        <type>${PP[0]}</type>
+                </portMappings>">> /etc/agent/conf/request.xml
+done
+
+echo "          <remoteHost>${PUBLIC_IP}</remoteHost>
+           <service>${SERVICE}</service>
+	   <remoteHost>${PUBLIC_IP}</remoteHost>
+           <roundsToAverage>${ROUNDS_TO_AVERAGE}</roundsToAverage>
+           <scaleDownFactor>${SCALE_DOWN_FACTOR}</scaleDownFactor>
+           <tenantRange>${TENANT_RANGE}</tenantRange>
+        </registrant>
+     </agen:register>
+  </soapenv:Body>
+</soapenv:Envelope>
+" >> /etc/agent/conf/request.xml
+
+echo "Creating repoinfo request  " >> $LOG
+echo "TENANT_ID and SERVICE ${TENANT_ID} and ${SERVICE} " >> $LOG
+set -- "${HOST_NAME}" 
+IFS="."; declare -a Array=($*)
+ALIAS="${Array[0]}"
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://org.apache.axis2/xsd\">
+   <soapenv:Header/>
+   <soapenv:Body>
+      <xsd:getRepositoryCredentials>
+         <xsd:tenantId>${TENANT_ID}</xsd:tenantId>
+         <xsd:cartridgeType>${SERVICE}</xsd:cartridgeType>
+         <xsd:alias>${ALIAS}</xsd:alias>
+      </xsd:getRepositoryCredentials>
+   </soapenv:Body>
+</soapenv:Envelope>" > /opt/repoinforequest.xml
+
+echo "Repoinfo request created " >> $LOG
+
+echo "Private Key....Copying to .ssh  " >> $LOG
+
+cp ${instance_path}/payload/id_rsa /root/.ssh/id_rsa
+chmod 0600 /root/.ssh/id_rsa
+echo "StrictHostKeyChecking no" >> /root/.ssh/config
+
+
+
+
+#echo "Getting repo username password from repoInfoService" >> $LOG
+#curl -X POST -H "Content-Type: text/xml" -d @/etc/agent/conf/request.xml --silent --output /dev/null "${CARTRIDGE_AGENT_EPR}"
+
+echo "Git repo sync" >> $LOG
+
+# If repo is available do a git pull, else clone
+
+echo "#!/bin/bash
+if [ -d \"${APP_PATH}/.git\" ]; then
+    cd ${APP_PATH}
+
+    curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+   git config --global --bool --add http.sslVerify false
+   sudo git pull
+   rm ~/.netrc
+   sudo rm /root/.netrc
+
+else
+   curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+    git config --global --bool --add http.sslVerify false
+    cd ${APP_PATH}
+    sudo mv ROOT ../
+    sudo git clone \${repo} ${APP_PATH}
+    sudo mv ../ROOT .
+   rm ~/.netrc
+   sudo rm /root/.netrc
+ 
+
+fi" > /opt/git.sh
+echo "File created.." >> $LOG
+chmod 755 /opt/git.sh
+                       
+
+
+while true
+do
+var=`nc -z localhost 8080; echo $?`;
+if [ $var -eq 0 ]
+   then
+       echo "port 8080 is available" >> $LOG
+       break
+   else
+       echo "port 8080 is not available" >> $LOG
+   fi
+   sleep 1
+done
+
+
+while true
+do
+var=`nc -z localhost 8443; echo $?`;
+if [ $var -eq 0 ]
+   then
+       echo "port 8443 is available" >> $LOG
+       break
+   else
+       echo "port 8443 is not available" >> $LOG
+   fi
+   sleep 1
+done
+
+
+
+echo "Sending register request to Cartridge agent service" >> $LOG
+
+curl -X POST -H "Content-Type: text/xml" -H "SOAPAction: urn:register" -d @/etc/agent/conf/request.xml -k --silent --output /dev/null "${CARTRIDGE_AGENT_EPR}"
+
+echo "Registered cartridge..." >> $LOG
+
+echo "running git clone........" >> $LOG
+su - ubuntu /opt/git.sh
+
+
+echo "setting up logging conf" >> $LOG
+
+
+echo "host:     ${BAM_IP}
+thriftPort:     ${BAM_PORT}
+
+#cartridge configs
+cartridgeAlias:  ${CARTRIDGE_ALIAS}
+tenantName:      ${HOST_NAME}
+tenantId:        ${TENANT_ID}
+localIP:         ${PUBLIC_IP}" > /opt/cartridge_data_publisher_1.0.2/conf/data_publisher.conf
+
+
+
+echo "started loggin ........."
+cd /opt/cartridge_data_publisher_1.0.2/dist/Debug/GNU-Linux-x86/
+nohup ./cartridge_data_publisher_1.0.2 /var/lib/tomcat7/logs/catalina.out >> /var/log/stratos-data-publisher.log  &
+
+echo "logging started........."
+
+
+# ========================== // End of script ===========================================================
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/tomcat/payload/README
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/tomcat/payload/README b/tools/cartridge-create/init-scripts/tomcat/payload/README
new file mode 100644
index 0000000..0e6c864
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/tomcat/payload/README
@@ -0,0 +1,21 @@
+This folder is a sample payload sent to a php instance when it is created.
+
+
+Replace the values in launch_params file with correct values of your environment.
+
+Now pack this payload as payload.zip and pass this when creating php instances.
+
+
+Following is the /etc/rc.local file of the php instance
+
+#!/bin/sh -e
+/opt/wso2-openstack-init.sh > /var/log/wso2-openstack-init.log
+exit 0
+
+By the time rc.local file is invokded in the newly created tomcat instance, the payload is already
+passed to the instance and reside in /var/lib/cloud/instance/payload
+
+You can see that rc.local invoke the wso2-openstack-init.sh script in the payload.
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/tomcat/payload/launch-params
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/tomcat/payload/launch-params b/tools/cartridge-create/init-scripts/tomcat/payload/launch-params
new file mode 100644
index 0000000..70eda77
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/tomcat/payload/launch-params
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+TENANT=1,SVNPASS=g,SVNURL=http://11.0.0.1:80/svn,APP=tomcat7

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/tomcat/stratos-init.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/tomcat/stratos-init.sh b/tools/cartridge-create/init-scripts/tomcat/stratos-init.sh
new file mode 100644
index 0000000..0495b7b
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/tomcat/stratos-init.sh
@@ -0,0 +1,274 @@
+#!/bin/bash
+
+# ----------------------------------------------------------------------------
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+# ----------------------------------------------------------------------------
+
+
+export LOG=/var/log/stratos-init.log
+instance_path=/opt
+PUBLIC_IP=""
+KEY=`uuidgen`
+CRON_DURATION=1
+RETRY_COUNT=30
+SLEEP_DURATION=3
+
+if [ ! -d ${instance_path}/payload ]; then
+
+    echo "creating payload dir ... " >> $LOG
+    mkdir ${instance_path}/payload
+    echo "payload dir created ... " >> $LOG
+    wget http://169.254.169.254/latest/user-data -O ${instance_path}/payload/payload.zip    
+    echo "payload copied  ... "  >> $LOG
+    unzip -d ${instance_path}/payload ${instance_path}/payload/payload.zip
+    echo "unzippeddd..." >> $LOG
+
+    for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+    do
+    echo "exporting to bashrc $i ... " >> $LOG
+        echo "export" ${i} >> /home/ubuntu/.bashrc
+    done
+    source /home/ubuntu/.bashrc
+
+fi
+
+
+echo ---------------------------- >> $LOG
+echo "getting public ip from metadata service" >> $LOG
+
+wget http://169.254.169.254/latest/meta-data/public-ipv4
+files="`cat public-ipv4`"
+if [[ -z ${files} ]]; then
+    echo "getting public ip" >> $LOG
+    for i in {1..30}
+    do
+      rm -f ./public-ipv4
+      wget http://169.254.169.254/latest/meta-data/public-ipv4
+      files="`cat public-ipv4`"
+      if [ -z $files ]; then
+          echo "Public ip is not yet assigned. Wait and continue for $i the time ..." >> $LOG
+          sleep $SLEEP_DURATION
+      else
+          echo "Public ip assigned" >> $LOG
+          break
+      fi
+    done
+
+    if [ -z $files ]; then
+      echo "Public ip is not yet assigned. So exit" >> $LOG
+      exit 0
+    fi
+    for x in $files
+    do
+        PUBLIC_IP="$x"
+    done
+
+
+else 
+   PUBLIC_IP="$files"
+fi
+
+
+for i in `/usr/bin/ruby /opt/get-launch-params.rb`
+do
+    export ${i}
+done
+
+
+echo "Restarting apache..." >> $LOG
+
+/etc/init.d/apache2 restart
+
+echo "Apache restarted..." >> $LOG
+
+
+echo "Logging sys variables .. PUBLIC_IP:${PUBLIC_IP}, HOST_NAME:${HOST_NAME}, KEY:${KEY}, PORTS=${PORTS}, BAM:${BAM_IP}, GITREPO:${GIT_REPO}" >> $LOG
+
+mkdir -p  /etc/agent/conf
+
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:agen=\"http://service.agent.cartridge.stratos.apache.org\">
+  <soapenv:Header/>
+  <soapenv:Body>
+     <agen:register>
+        <registrant> 
+           <alarmingLowerRate>${ALARMING_LOWER_RATE}</alarmingLowerRate>
+           <alarmingUpperRate>${ALARMING_UPPER_RATE}</alarmingUpperRate>
+           <hostName>${HOST_NAME}</hostName>
+           <key>${KEY}</key>
+          <maxInstanceCount>${MAX}</maxInstanceCount>
+	  <maxRequestsPerSecond>${MAX_REQUESTS_PER_SEC}</maxRequestsPerSecond>
+          <minInstanceCount>${MIN}</minInstanceCount> " > /etc/agent/conf/request.xml
+
+IFS='|' read -ra PT <<< "${PORTS}"
+for i in "${PT[@]}"; do
+IFS=':' read -ra PP <<< "$i"
+echo "          <portMappings>
+                        <primaryPort>${PP[1]}</primaryPort>
+                        <proxyPort>${PP[2]}</proxyPort>
+                        <type>${PP[0]}</type>
+                </portMappings>">> /etc/agent/conf/request.xml
+done
+
+echo "          <remoteHost>${PUBLIC_IP}</remoteHost>
+           <service>${SERVICE}</service>
+	   <remoteHost>${PUBLIC_IP}</remoteHost>
+           <roundsToAverage>${ROUNDS_TO_AVERAGE}</roundsToAverage>
+           <scaleDownFactor>${SCALE_DOWN_FACTOR}</scaleDownFactor>
+           <tenantRange>${TENANT_RANGE}</tenantRange>
+        </registrant>
+     </agen:register>
+  </soapenv:Body>
+</soapenv:Envelope>
+" >> /etc/agent/conf/request.xml
+
+echo "Creating repoinfo request  " >> $LOG
+echo "TENANT_ID and SERVICE ${TENANT_ID} and ${SERVICE} " >> $LOG
+set -- "${HOST_NAME}" 
+IFS="."; declare -a Array=($*)
+ALIAS="${Array[0]}"
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://org.apache.axis2/xsd\">
+   <soapenv:Header/>
+   <soapenv:Body>
+      <xsd:getRepositoryCredentials>
+         <xsd:tenantId>${TENANT_ID}</xsd:tenantId>
+         <xsd:cartridgeType>${SERVICE}</xsd:cartridgeType>
+         <xsd:alias>${ALIAS}</xsd:alias>
+      </xsd:getRepositoryCredentials>
+   </soapenv:Body>
+</soapenv:Envelope>" > /opt/repoinforequest.xml
+
+echo "Repoinfo request created " >> $LOG
+
+echo "Private Key....Copying to .ssh  " >> $LOG
+
+cp ${instance_path}/payload/id_rsa /root/.ssh/id_rsa
+chmod 0600 /root/.ssh/id_rsa
+echo "StrictHostKeyChecking no" >> /root/.ssh/config
+
+
+
+
+#echo "Getting repo username password from repoInfoService" >> $LOG
+#curl -X POST -H "Content-Type: text/xml" -d @/etc/agent/conf/request.xml --silent --output /dev/null "${CARTRIDGE_AGENT_EPR}"
+
+echo "Git repo sync" >> $LOG
+
+# If repo is available do a git pull, else clone
+
+echo "#!/bin/bash
+if [ -d \"${APP_PATH}/.git\" ]; then
+    cd ${APP_PATH}
+    
+    curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+   git config --global --bool --add http.sslVerify false
+   sudo git pull
+   rm ~/.netrc
+   sudo rm /root/.netrc
+
+else
+   curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   sed '1,5d' /tmp/git.xml > /tmp/git1.xml
+   sed '2d' /tmp/git1.xml > /tmp/git.xml
+   username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
+   password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
+   repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+    git config --global --bool --add http.sslVerify false
+    cd ${APP_PATH}
+    sudo mv ROOT ../
+    sudo git clone \${repo} ${APP_PATH}
+    sudo mv ../ROOT .
+   rm ~/.netrc
+   sudo rm /root/.netrc
+ 
+
+fi" > /opt/git.sh
+echo "File created.." >> $LOG
+chmod 755 /opt/git.sh
+                       
+
+
+while true
+do
+var=`nc -z localhost 8080; echo $?`;
+if [ $var -eq 0 ]
+   then
+       echo "port 8080 is available" >> $LOG
+       break
+   else
+       echo "port 8080 is not available" >> $LOG
+   fi
+   sleep 1
+done
+
+
+
+
+
+echo "Sending register request to Cartridge agent service" >> $LOG
+
+curl -X POST -H "Content-Type: text/xml" -H "SOAPAction: urn:register" -d @/etc/agent/conf/request.xml -k --silent --output /dev/null "${CARTRIDGE_AGENT_EPR}"
+
+echo "Registered cartridge..." >> $LOG
+
+echo "running git clone........" >> $LOG
+su - ubuntu /opt/git.sh
+
+
+echo "setting up logging conf" >> $LOG
+
+
+echo "host:     ${BAM_IP}
+thriftPort:     ${BAM_PORT}
+
+#cartridge configs
+cartridgeAlias:  ${CARTRIDGE_ALIAS}
+tenantName:      ${HOST_NAME}
+tenantId:        ${TENANT_ID}
+localIP:         ${PUBLIC_IP}" > /opt/cartridge_data_publisher_1.0.2/conf/data_publisher.conf
+
+
+
+echo "started loggin ........."
+cd /opt/cartridge_data_publisher_1.0.2/dist/Debug/GNU-Linux-x86/
+nohup ./cartridge_data_publisher_1.0.2 /var/lib/tomcat7/logs/catalina.out >> /var/log/stratos-data-publisher.log  &
+
+
+
+
+
+# ========================== // End of script ===========================================================

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/init-scripts/tomcat/stratos.pem
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/init-scripts/tomcat/stratos.pem b/tools/cartridge-create/init-scripts/tomcat/stratos.pem
new file mode 100644
index 0000000..f4260f9
--- /dev/null
+++ b/tools/cartridge-create/init-scripts/tomcat/stratos.pem
@@ -0,0 +1,16 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQCp31ZRD9kPwKoxW3sh+4x2IfldCKEfHbo18LhvOnGPJcNzqHDy
+6WWxpxPAHNAMyvrAv+hUfX4fwSRctieTim0N+fTr+mRP0q4HHhEkvEmxoXs4Y7lz
+jrh5vhMBZBAXsSurHVp2Bpie1xyjW+ksuAziT2gw6KvipjJiGTjuLTnLmQIDAQAB
+AoGAMFvtNbx+PbbKfKyfXChBb2vykmKfg70xwqNZzghkRa0pfCaKqQx6r91xiPJq
+5Alw4yh+2nazThTs5hvRHnZ83tPFxKyekrOdFpFEwAdibmvM3ckfAmUqJErteFhp
+o524O37kWpzwBgk1rxwLHVxyoscVHF8vWSjk9jzvdor9XbUCQQDdPp+F/X5qQLZw
+xaYyHrWmLkRnFRaxxmiOQmvAxYKybMp0Ei8euy+wKHiNPBVPxn143hrag7a2GKIn
+hq6LwoiHAkEAxI7GYK47woZJHI6rjskjxT+DBNKjTmoDZVTa4KrWUVY1NfTC+/jI
+Ajm3cQ1QYnGEYyvlczgD3jvRdDtjJjGy3wJAV4JnkpX7pIdIIj7rR7PB4aM3Rxae
+TV7PCEXZXPxCf9RsF5EBtkQPzruTQznarB00j9Q6BuhGIqyHpt6st3cQjQJBAKtf
+oG7i+o+b7VrMuZ+Al4N+4Ijv7hqMK/HJjhycVsgL1dD5Wpe+TQRDtkEHTrLGLpsY
+xrEygYzdsr0YmlXOtxkCQQC46OoYuk/bZhp1gnFNtWXp73ZESphNOC/FovNKu5Os
+fbxKoqUbosXAi6wxuU1L+eojN0UNx98xyKjG/lyUog/m
+-----END RSA PRIVATE KEY-----
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/stratos-image
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/stratos-image b/tools/cartridge-create/stratos-image
new file mode 100755
index 0000000..e11e5de
--- /dev/null
+++ b/tools/cartridge-create/stratos-image
@@ -0,0 +1,100 @@
+#!/bin/bash
+
+# ----------------------------------------------------------------------------
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+# ----------------------------------------------------------------------------
+
+
+# Die on any error:
+set -e
+
+# This script will create an cartridge image from a running virtual machine instance in Openstack using a given cartridge template. Then it will be
+# uploaded into the Glance Server. This script should be executed after logging into the Openstack controller with a valid user account that can
+# upload images to the glance server.
+
+vm_instance_ip=""
+cartridge_template=""
+vm_instance_user=""
+vm_instance_private_key=""
+software=""
+function help {
+    echo ""
+    echo "    This script  will upload the cartridge template execution file into the remote virtual machine from"
+    echo "            which you need to create the image, and execute it. At the end of the execution, image is ready for"
+    echo "            upload"
+    echo "    Usage for action create:"
+    echo ""
+    echo "    stratos-image -s <software> create <ip/hostname of the virtual machine> <cartridge template> <vm instance user> <vm instance private key>"
+    echo ""
+    echo "    -s : Softwared to be copied to the new image, separated by colon(:). Default is none. These will be"
+    echo "         copied into the /opt folder of the instance"
+    echo "    <ip/hostname of the virtual machine> : ip or hostname of the virtual machine using which image will be created from"
+    echo "    <cartridge template> : Template for the new image"
+    echo "    <vm instance user> : User name of the instance from which you need to create the image"
+    echo "    <vm instance private key> : Name of the private key of the user for logging into the virtual machine instance."
+    echo "            Copy the private key to init_scripts/<cartridge template> (e.g., init_scripts/php) folder"
+    echo ""
+}
+
+function image_validate {
+
+if [[ -z $vm_instance_ip || -z $cartridge_template || -z $vm_instance_user || -z $vm_instance_private_key ]]; then
+    help
+    exit 1
+fi
+
+}
+
+while getopts s: opts
+do
+  case $opts in
+    s)
+        software=${OPTARG}
+        ;;
+    *)
+        help
+        exit 1
+        ;;
+  esac
+done
+shift $((OPTIND-1))
+
+vm_instance_ip=$1
+echo $vm_instance_ip
+cartridge_template=$2
+echo $cartridge_template
+vm_instance_user=$3
+vm_instance_private_key=$4
+
+image_validate
+
+echo "Install from cartridge_template $cartridge_template"
+pushd ./init_scripts/$cartridge_template
+chmod 755 ./$cartridge_template
+./$cartridge_template $vm_instance_ip $vm_instance_user $vm_instance_private_key $software
+popd
+echo "Installed from cartridge_template $cartridge_template"
+echo "Now upload the image by using Openstack nova command"
+echo "nova image-create <vm instance id> <image name>"
+echo "where"
+echo "<vm instance id> is the id of the virtual machine instance from which you need to create the image"
+echo "<image name> is the name you wish to give for your new cartridge image"
+
+
+echo "Done"
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/stratos-image-local
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/stratos-image-local b/tools/cartridge-create/stratos-image-local
new file mode 100755
index 0000000..816fd92
--- /dev/null
+++ b/tools/cartridge-create/stratos-image-local
@@ -0,0 +1,310 @@
+#!/bin/bash
+
+# ----------------------------------------------------------------------------
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+# ----------------------------------------------------------------------------
+
+
+# Die on any error:
+set -e
+
+work_dir=""
+new_image=""
+image_root="/tmp"
+image_template="default"
+software=""
+new_image_size="" #In GB
+action=""
+original_image=""
+image_type="qcow2"
+
+function help {
+    echo "Usage: stratos-image-local [optional arguments] <action> <mandatory arguments>"
+    echo "    Action can be one of the following"
+    echo "        create : Mount the base image and customize it according to the given arguments"
+    echo "        pack : Archive the newly created image and unmount the base image"
+    echo ""
+    echo "    Mandatory and optional arguments depend on the action. Following is the list of usages for each action"
+    echo ""
+    echo "    Usage for action create:"
+    echo "        stratos-image-local -r <image root> -t <image template> -s <software> -n <new image size(just enter number without G suffix)> "
+    echo "                            create <path to original image>"
+    echo ""
+    echo "            -r : Image root - This is where the base image is mounted. Default is /tmp"
+    echo "            -t : Template for the new image. Default is no template"
+    echo "            -s : Softwared to be copied to the new image, separated by colon(:). Default is none"
+    echo "            -n : Image size of the new image in GB(just enter number without G suffix). Default is the size of the base image"
+    echo "            -v : Image type. This is one of qcow2 or row. Default is qcow2"
+    echo ""
+    echo "    Usage for action pack:"
+    echo "        stratos-image-local -r <image root> -t <image template> pack <new image archive name in tar.gz format>"
+    echo ""
+    echo "            -r : Image root - This is where the base image is mounted. Default is /tmp"
+    echo "            -t : Template for the new image. Default is no template"
+    echo "            -v : Image type. This is one of qcow2 or row. Default is qcow2"
+    echo ""
+    echo "    Usage for action mount:"
+    echo "        stratos-image-local -r <image root> -t <image template> -n <new image size(just enter number without G suffix)> mount <path to original image>"
+    echo ""
+    echo "            -r : Image root - This is where the base image is mounted. Default is /tmp"
+    echo "            -t : Template for the new image. Default is no template"
+    echo "            -n : Resize the image to this size in GB(just enter number wihout G suffix) before mounting. Default is the size of the base image"
+    echo "            -v : Image type. This is one of qcow2 or row. Default is qcow2"
+    echo ""
+    echo "    eg:sudo ./stratos-image-local -r /tmp/ -n 8 mount /opt/lxc/precise-server-carbon-cloudimg-amd64-disk1.img"
+    echo ""
+    echo "    Usage for action unmount:"
+    echo "        stratos-image-local -r <image root> -t <image template>  unmount"
+    echo ""
+    echo "            -r : Image root - This is where the base image is mounted. Default is /tmp"
+    echo "            -t : Template for the new image. Default is no template"
+    echo "            -v : Image type. This is one of qcow2 or row. Default is qcow2"
+    echo ""
+    echo "    eg:sudo ./stratos-image-local -r /tmp unmount"
+}
+
+function image_validate {
+
+if [[ ( -z $action || ( -n $action && $action == "help" ) ) ]]; then
+    help
+    exit 1
+fi
+
+if [[ ( -z $action || ( -n $action && !( $action == "create" || $action == "pack" || $action == "mount" || $action == "unmount" ) ) ) ]]; then
+        echo "Mandatory parameter action with value create or pack should be provided"
+        echo "    create : Mount the base image and customize it according to the given arguments"
+        echo "    pack : Archive the newly created image and unmount the base image"
+        echo ""
+        exit 1
+    fi
+
+if [[ ( -n $action && $action == "create" && -z $original_image ) ]]; then
+        echo "Usage:"
+        echo "    stratos-image-local -r <image root> -t <image template> -s <software> -n <new image size(just enter number without G suffix)> -v <image type> create <path to original image>"
+        echo ""
+        echo "        -r : Image root - This is where the base image is mounted. Default is /tmp"
+        echo "        -t : Template for the new image. Default is no template"
+        echo "        -s : Softwared to be copied to the new image, separated by colon(:). Default is none"
+        echo "        -n : Image size of the new image in GB. Default is the size of the base image"
+        echo "        -v : Image type. qcow2 or raw. Default is qcow2"
+        echo ""
+        exit 1
+fi
+
+if [[ ( -n $action && $action == "pack" && -z $new_image ) ]]; then
+        echo "Usage:"
+        echo "    stratos-image-local -r <image root> -t <image template> pack <new image archive name in tar.gz format>"
+        echo ""
+        echo "        -r : Image root - This is where the base image is mounted. Default is /tmp"
+        echo "        -t : Template for the new image. Default is no template"
+        echo "        -v : Image type. qcow2 or raw. Default is qcow2"
+        echo ""
+        exit 1
+fi
+
+if [[ ( -n $action && $action == "mount" && -z $original_image ) ]]; then
+        echo "Usage:"
+        echo "    stratos-image-local -r <image root> -t <image template> -n <new image size(just enter number without G suffix)> -v <image type> mount <path to original image>"
+        echo ""
+        echo "        -r : Image root - This is where the base image is mounted. Default is /tmp"
+        echo "        -t : Template for the new image. Default is no template"
+        echo "        -n : Resize the image to this size in GB(just enter number without G suffix) before mounting. Default is the size of the base image"
+        echo "        -v : Image type. qcow2 or raw. Default is qcow2"
+        echo ""
+        echo "    eg:sudo ./stratos-image-local -r /tmp/ -n 8 mount /opt/lxc/precise-server-carbon-cloudimg-amd64-disk1.img"
+        exit 1
+fi
+
+}
+
+# Make sure the user is running as root.
+if [ "$UID" -ne "0" ]; then
+	echo ; echo "  You must be root to run $0.  (Try running 'sudo bash' first.)" ; echo 
+	exit 69
+fi
+
+while getopts r:t:s:n:v: opts
+do
+  case $opts in
+    r)
+        image_root=${OPTARG}
+        ;;
+    t)
+        image_template=${OPTARG}
+        ;;
+    s)
+        software=${OPTARG}
+        ;;
+    n)
+        new_image_size=${OPTARG}
+        ;;
+    v)
+        image_type=${OPTARG}
+        ;;
+    *)
+        help
+        exit 1
+        ;;
+  esac
+done
+shift $((OPTIND-1))
+action=$1
+if [[ $action == "create" ]]; then
+    original_image=$2
+elif [[ $action == "pack" ]]; then
+    new_image=$2
+elif [[ $action == "mount" ]]; then
+    original_image=$2
+fi
+
+image_validate
+
+work_dir="$image_root/$image_template"
+img_dir="$work_dir/image"
+
+if [[ $action == "create" || $action == "mount" ]]; then
+    if [ $image_type = "qcow2" ]; then
+        let "new_image_size=$new_image_size*1024*1024*1024"
+        new_image_size=$new_image_size
+        echo "qcow2 new_image_size:$new_image_size"
+    else
+        new_image_size=$new_image_size"G"
+        echo "raw new_image_size:$new_image_size"
+    fi
+fi
+
+if [[ $action == "create" ]]; then
+
+    if [ -d ./$work_dir ]; then
+        rm -rf ./$work_dir
+    fi
+
+    mkdir -p $work_dir
+
+    if [ ! -d $img_dir ]; then
+        mkdir -p $img_dir
+    fi
+
+    pushd $img_dir
+    type=`echo $original_image|awk -F . '{print $NF}'`
+    if [[ $type == "zip" ]]; then
+        zip -rq $original_image
+    elif [[ $type == "gz" || $type == "tgz" ]]; then
+        tar -zxf $original_image
+    else
+        cp -f $original_image ./
+    fi
+    popd
+    echo $img_dir
+    image_image=`ls $img_dir/*.img`
+    echo $image_image
+    if [ -z $new_image_size ]; then
+        echo "Image will not be resized since new image size is not provided"
+    else
+        echo "Resizing the original image"
+        if [ $image_type = "qcow2" ]; then
+            qemu-img resize $image_image $new_image_size
+        else
+            fsck.ext3 -f $image_image
+            e2fsck -f $image_image
+            resize2fs $image_image $new_image_size
+        fi
+    fi
+
+    echo "Mount the original image"
+    ./image_action.sh action=mount image-template=$image_template image-root=$image_root image-image=$image_image image-type=$image_type
+    echo "Original image mounted"
+    read
+
+    if [[ !( $image_template == "default" ) ]]; then
+    	echo "Customizing the original image"
+    	./image_action.sh action=create image-template=$image_template image-root=$image_root software=$software image-type=$image_type
+    fi
+
+fi
+
+if [[ $action == "pack" ]]; then
+    echo "Archiving the new image"
+    pushd $work_dir/image
+    type=`echo $new_image|awk -F . '{print $NF}'`
+    if [[ $type == "zip" ]]; then
+        zip -rq $new_image ./*
+    elif [[ $type == "gz" || $type == "tgz" ]]; then
+        tar -zcf $new_image ./*
+    elif [[ $type == "img" ]]; then
+        mv *.img $new_image
+    fi
+
+    popd
+    echo "Unmounting"
+    ./image_action.sh action=unmount image-template=$image_template image-root=$image_root image-type=$image_type
+fi
+
+if [[ $action == "mount" ]]; then
+    if [ -d ./$work_dir ]; then
+        rm -rf ./$work_dir
+    fi
+
+    mkdir -p $work_dir
+
+    if [ ! -d $img_dir ]; then
+        mkdir -p $img_dir
+    fi
+
+    pushd $img_dir
+    type=`echo $original_image|awk -F . '{print $NF}'`
+    if [[ $type == "zip" ]]; then
+        zip -rq $original_image
+    elif [[ $type == "gz" || $type == "tgz" ]]; then
+        tar -zxf $original_image
+    else
+        cp -f $original_image ./
+    fi
+    popd
+    echo $img_dir
+    image_image=`ls $img_dir/*.img`
+    echo $image_image
+
+    if [ -z $new_image_size ]; then
+        echo "Image will not be resized since new image size is not provided"
+    else
+        echo "Resizing the original image"
+        if [ $image_type = "qcow2" ]; then
+            qemu-img resize $image_image $new_image_size
+        else
+            echo "image:"$image_image
+            fsck.ext3 -f $image_image
+            e2fsck -f $image_image
+            resize2fs $image_image $new_image_size
+        fi
+    fi
+
+    echo "Mount the image"
+    ./image_action.sh action=mount image-template=$image_template image-root=$image_root image-image=$image_image image-type=$image_type
+    echo "Mounted the image"
+fi
+
+if [[ $action == "unmount" ]]; then
+    echo "Unmount the image"
+
+    ./image_action.sh action=unmount image-template=$image_template image-root=$image_root image-type=$image_type
+    echo "Unmounted the image"
+fi
+
+echo "Done"
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge-create/uploadimg.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge-create/uploadimg.sh b/tools/cartridge-create/uploadimg.sh
new file mode 100755
index 0000000..2afec21
--- /dev/null
+++ b/tools/cartridge-create/uploadimg.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+# ----------------------------------------------------------------------------
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+# ----------------------------------------------------------------------------
+
+
+ip=$1
+imagename=$2
+userrc=$3
+mysqlpass=$4
+source ./$userrc
+ret=`mysql -u root -p$mysqlpass nova -e "select i.uuid from instances i, fixed_ips x, floating_ips f where i.id=x.instance_id and x.id=f.fixed_ip_id and f.address='$ip' and i.vm_state='ACTIVE'"`
+tok_str=(`echo $ret | tr '.' ' '`)
+id=${tok_str[1]}
+echo $id > /tmp/test
+nova image-create $id $imagename

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b60d2c7d/tools/cartridge_create/README
----------------------------------------------------------------------
diff --git a/tools/cartridge_create/README b/tools/cartridge_create/README
deleted file mode 100644
index 883fe48..0000000
--- a/tools/cartridge_create/README
+++ /dev/null
@@ -1,50 +0,0 @@
-This folder contain utilities to create customized images from the already running openstack instances.
-The main utility is a CLI tool called stratos-image.
-Pre-requisites:
-
-You need the private or public(floating)ip of the openstack instance from which you need to create the image. Also you need a username
-for that instance and a private key to access that instance. Copy the private key to init_scripts/<template> (e.g., init_scripts/php) folder.
-
-You need a file with the following information regarding the Openstack environment and copy that file into the current folder.
-When uploading the image you need the variables in the file exported to the environment. 
-Normally when you install the Openstack you get this file generated. Please refer to your Openstack installation documents 
-on how to get the information in this file.
-
-----------------------------------------------------------
-NOVA_API_HOST=192.168.16.20
-GLANCE_API_HOST=192.168.16.20
-KEYSTONE_API_HOST=192.168.16.20
-
-NOVA_REGION="nova"
-
-export NOVA_USERNAME=demo
-export NOVA_PROJECT_ID=demo
-export NOVA_PASSWORD=openstack
-export NOVA_API_KEY=openstack
-export NOVA_REGION_NAME=$NOVA_REGION
-export NOVA_URL="http://$NOVA_API_HOST:5000/v2.0/"
-export NOVA_VERSION="1.1"
-
-export OS_USERNAME=demo
-export OS_PASSWORD=openstack
-export OS_TENANT_ID=7434d33c18e04e60a6751922773fbe2d
-export OS_AUTH_URL="http://$KEYSTONE_API_HOST:5000/v2.0/"
-export OS_AUTH_STRATEGY="keystone"
-
-export EC2_URL="http://$NOVA_API_HOST:8773/services/Cloud"
-export EC2_ACCESS_KEY="8b742fee68c6464198517242828adb82"
-export EC2_SECRET_KEY="279a7f28c8a54d5db8e27524f648a7d3"
-export S3_URL="http://$GLANCE_API_HOST:3333"
-
-----------------------------------------------------------
-
-For help on how to execute stratos-image execute.
-./stratos-image help
-
-Following is an example of create and upload the image for php cartridge
-
-./stratos-image create 192.168.16.129 php ubuntu wso2.pem
-
-nova image-create <vm instance id> php-cloudimg-amd64
-
-