You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ma...@apache.org on 2013/08/23 08:58:56 UTC
git commit: Re-factored mysql cartridge init scripts
Updated Branches:
refs/heads/master b4c48cdf2 -> c0213d478
Re-factored mysql cartridge init scripts
Signed-off-by: Manula Thantriwatte <ma...@wso2.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/c0213d47
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/c0213d47
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/c0213d47
Branch: refs/heads/master
Commit: c0213d4787a9569a240f39f9c36590d769b6032f
Parents: b4c48cd
Author: Imesh Gunaratne <im...@wso2.com>
Authored: Fri Aug 23 11:47:08 2013 +0530
Committer: Manula Thantriwatte <ma...@wso2.com>
Committed: Fri Aug 23 12:27:59 2013 +0530
----------------------------------------------------------------------
.../mysql/openstack/get-launch-params.rb | 0
.../init_scripts/mysql/openstack/healthcheck.sh | 10 ++
.../mysql/openstack/stratos-init.sh | 165 +++++++++++++++++++
.../mysql/openstack/wso2-cartridge-init.sh | 144 ----------------
4 files changed, 175 insertions(+), 144 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c0213d47/tools/cartridge_create/init_scripts/mysql/openstack/get-launch-params.rb
----------------------------------------------------------------------
diff --git a/tools/cartridge_create/init_scripts/mysql/openstack/get-launch-params.rb b/tools/cartridge_create/init_scripts/mysql/openstack/get-launch-params.rb
old mode 100644
new mode 100755
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c0213d47/tools/cartridge_create/init_scripts/mysql/openstack/healthcheck.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge_create/init_scripts/mysql/openstack/healthcheck.sh b/tools/cartridge_create/init_scripts/mysql/openstack/healthcheck.sh
new file mode 100755
index 0000000..df4897b
--- /dev/null
+++ b/tools/cartridge_create/init_scripts/mysql/openstack/healthcheck.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+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/c0213d47/tools/cartridge_create/init_scripts/mysql/openstack/stratos-init.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge_create/init_scripts/mysql/openstack/stratos-init.sh b/tools/cartridge_create/init_scripts/mysql/openstack/stratos-init.sh
new file mode 100755
index 0000000..29ae6f6
--- /dev/null
+++ b/tools/cartridge_create/init_scripts/mysql/openstack/stratos-init.sh
@@ -0,0 +1,165 @@
+#!/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
+ # Write a cronjob to execute wso2-cartridge-init.sh periodically until public ip is assigned
+ #crontab -l > ./mycron
+ #echo "*/${CRON_DURATION} * * * * /opt/wso2-cartridge-init.sh > /var/log/wso2-cartridge-init.log" >> ./mycron
+ #crontab ./mycron
+ #rm ./mycron
+
+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
+ #crontab -r
+ 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"
+ #crontab -r
+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 "Setting MySQL root password" >> $LOG
+if [[ (-n ${MYSQL_PASSWORD} ) ]]; then
+ mysqladmin -u root password "${MYSQL_PASSWORD}"
+ mysql -uroot -p${MYSQL_PASSWORD} -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}' WITH GRANT OPTION;flush privileges;"
+ echo "MySQL root password set" >> $LOG
+fi
+
+/etc/init.d/apache2 restart
+
+
+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 "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 --silent --output /dev/null "$CARTRIDGE_AGENT_EPR" --insecure
+
+
+sleep 5
+
+/etc/init.d/apache2 restart
+# ========================== // End of script ===========================================================
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c0213d47/tools/cartridge_create/init_scripts/mysql/openstack/wso2-cartridge-init.sh
----------------------------------------------------------------------
diff --git a/tools/cartridge_create/init_scripts/mysql/openstack/wso2-cartridge-init.sh b/tools/cartridge_create/init_scripts/mysql/openstack/wso2-cartridge-init.sh
deleted file mode 100644
index 21324a3..0000000
--- a/tools/cartridge_create/init_scripts/mysql/openstack/wso2-cartridge-init.sh
+++ /dev/null
@@ -1,144 +0,0 @@
-#!/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/wso2-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
- # Write a cronjob to execute wso2-cartridge-init.sh periodically until public ip is assigned
- #crontab -l > ./mycron
- #echo "*/${CRON_DURATION} * * * * /opt/wso2-cartridge-init.sh > /var/log/wso2-cartridge-init.log" >> ./mycron
- #crontab ./mycron
- #rm ./mycron
-
-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
- #crontab -r
- 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"
- #crontab -r
-fi
-
-
-for i in `/usr/bin/ruby /opt/get-launch-params.rb`
-do
- export ${i}
-done
-
-#MYSQL_PASSWORD
-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.carbon.wso2.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 "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 --silent --output /dev/null "$CARTRIDGE_AGENT_EPR"
-
-# ========================== // End of script ===========================================================