Skip to content

Commit e7eb50f

Browse files
author
damitha
committed
Adding php cartridge init script and updating carbon cartridge init script. Also add mysql and
php cartridge templates from a patch provided by Lakmal git-svn-id: https://svn.wso2.org/repos/wso2/carbon/platform/trunk@147906 a5903396-d722-0410-b921-86c7d4935375
1 parent 911edfd commit e7eb50f

File tree

7 files changed

+249
-76
lines changed

7 files changed

+249
-76
lines changed

build/tropos/image_create/configure_software

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mysql() {
3535
nano zip mysql-server git \
3636
apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common dbconfig-common fontconfig-config libapache2-mod-php5 \
3737
libaprutil1-dbd-sqlite3 libaprutil1-ldap libcap2 libfontconfig1 libgd2-xpm libjpeg-turbo8 libjpeg8 libmcrypt4 \
38-
libt1-5 libxpm4 php5-cli php5-common php5-gd php5-mcrypt php5-mysql phpmyadmin ssl-cert ttf-dejavu-core libboost-all-dev
38+
libt1-5 libxpm4 php5-cli php5-common php5-gd php5-mcrypt php5-mysql phpmyadmin ssl-cert ttf-dejavu-core libboost-all-dev ruby
3939

4040
# Be sure to have a new SSL cert for this new LXC host:
4141
rm -f $ROOTFS/etc/ssl/private/ssl-cert-snakeoil.key
@@ -68,13 +68,17 @@ s/ or starting networking)/# or starting network-manager/
6868

6969
php() {
7070

71+
cp -f ./init_scripts/php/wso2-openstack-init.sh $ROOTFS/opt/
72+
cp -f ./init_scripts/php/get-launch-params.rb $ROOTFS/opt/
73+
chroot $ROOTFS mkdir -p /etc/agent/conf
74+
cp -f ./init_scripts/php/request.xml $ROOTFS/etc/agent/conf/
7175
chroot $ROOTFS apt-get update
7276
# Next, all the LAMP packages. We must first pre-save the password
7377

7478
chroot $ROOTFS apt-get install -y \
7579
nano zip mysql-client apache2 php5 php5-cli libapache2-mod-php5 php5-gd php5-mysql php-db php-pear \
7680
php5-curl curl wget php5-ldap php5-adodb mailutils php5-imap php5-ldap \
77-
openssl ssl-cert ldap-utils php5-mcrypt mcrypt ufw fail2ban git libboost-all-dev
81+
openssl ssl-cert ldap-utils php5-mcrypt mcrypt ufw fail2ban git libboost-all-dev ruby
7882

7983
# install gitpython
8084
# chroot $ROOTFS easy_install GitPython
@@ -222,11 +226,13 @@ wso2_carbon_server() {
222226

223227
#chroot $ROOTFS apt-get update
224228

225-
chroot $ROOTFS apt-get install -y \
229+
chroot $ROOTFS apt-get install -y \
226230
nano zip \
227231
wget \
228-
openssl ssl-cert ldap-utils ruby
229-
232+
openssl ssl-cert ldap-utils ruby git
233+
234+
# TODO install puppet agent
235+
230236
# Be sure to have a new SSL cert for this new LXC host:
231237
#rm -f $ROOTFS/etc/ssl/private/ssl-cert-snakeoil.key
232238
#chroot $ROOTFS dpkg-reconfigure ssl-cert

build/tropos/image_create/init_scripts/carbon/wso2-openstack-init.sh

Lines changed: 43 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
2+
3+
# ----------------------------------------------------------------------------
4+
# Copyright 2005-20012 WSO2, Inc. http://www.wso2.org
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# ----------------------------------------------------------------------------
219
export LOG=/var/log/wso2-openstack.log
3-
export JAVA_HOME=/opt/java/
4-
instance_path=/var/lib/cloud/instance
5-
6-
# Variables taken from the payload passed to the instance
7-
export REPO_PATH_S3=""
8-
export CONF_PATH_S3=""
9-
export REPO_PATH_EBS=""
10-
export CONF_PATH_EBS=""
11-
export PRODUCT_NAME=""
12-
export CONTROLLER_IP=""
13-
CRON_DURATION=2
20+
export instance_path=/var/lib/cloud/instance
1421
PUBLIC_IP=""
15-
22+
CRON_DURATION=1
23+
PRODUCT_NAME=""
1624

1725
#Check whether if any java processes are running
1826
if [[ "$(pidof java)" ]]; then
@@ -29,50 +37,36 @@ fi
2937

3038
echo ---------------------------- >> $LOG
3139

32-
if [ ! -d ${instance_path}/payload ]; then
33-
# payload will be copied into ${instance_path}/user-data.txt file
34-
# that file will be renamed as zip file and extract,
35-
36-
# copy user-data.txt and rename as payload.zip file
37-
cp ${instance_path}/user-data.txt ${instance_path}/payload.zip
38-
39-
# if error code is 0, there was no error
40-
if [ "$?" = "0" ]; then
41-
echo retrieved data >> $LOG
42-
rm -Rf ${instance_path}/payload
43-
unzip ${instance_path}/payload.zip -d ${instance_path}/
44-
# if unzip error code is 0, there was no error
45-
if [ "$?" = "0" ]; then
46-
echo Extracted payload >> $LOG
47-
else
48-
echo rc.local : payload.zip is corrupted >> $LOG
49-
fi
50-
51-
else
52-
echo rc.local : error retrieving user data >> $LOG
53-
fi
54-
55-
chmod -R 0600 ${instance_path}/payload/wso2-key
56-
cat ${instance_path}/payload/known_hosts >> ~/.ssh/known_hosts
5740

41+
if [ ! -d ${instance_path}/payload ]; then
42+
echo "creating payload dir ... " >> $LOG
43+
mkdir ${instance_path}/payload
44+
echo "payload dir created ... " >> $LOG
45+
# payload will be copied into ${instance_path}/payload/launch-params file
46+
cp ${instance_path}/user-data.txt ${instance_path}/payload/launch-params
47+
echo "payload copied ... " >> $LOG
48+
for i in `/usr/bin/ruby /opt/get-launch-params.rb`
49+
do
50+
echo "exporting to bashrc $i ... " >> $LOG
51+
echo "export" ${i} >> /home/ubuntu/.bashrc
52+
done
53+
source /home/ubuntu/.bashrc
5854
# Write a cronjob to execute wso2-openstack-init.sh periodically until public ip is assigned
5955
crontab -l > ./mycron
6056
echo "*/${CRON_DURATION} * * * * /opt/wso2-openstack-init.sh > /var/log/wso2-openstack-init.log" >> ./mycron
6157
crontab ./mycron
6258
rm ./mycron
6359

64-
for i in `/usr/bin/ruby /opt/get-launch-params.rb`
65-
do
66-
echo "export" ${i} >> /home/ubuntu/.bashrc
67-
done
68-
6960
fi
7061

7162

63+
echo ---------------------------- >> $LOG
64+
65+
echo "getting public ip from metadata service" >> $LOG
7266
wget http://169.254.169.254/latest/meta-data/public-ipv4
7367
files="`cat public-ipv4`"
7468
if [[ -z ${files} ]]; then
75-
echo "getting public ip" >> $LOG
69+
echo "getting public ip. If fail retry 30 times" >> $LOG
7670
for i in {1..30}
7771
do
7872
rm -f ./public-ipv4
@@ -83,6 +77,7 @@ if [[ -z ${files} ]]; then
8377
sleep 1
8478
else
8579
echo "Public ip assigned" >> $LOG
80+
crontab -r
8681
break
8782
fi
8883
done
@@ -96,41 +91,18 @@ if [[ -z ${files} ]]; then
9691
PUBLIC_IP="$x"
9792
done
9893

99-
fi
100-
101-
echo wget the ipv4 >> $LOG
102-
echo "$files" >> $LOG
10394

104-
echo done_ public ip >> $LOG
105-
echo $PUBLIC_IP >> $LOG
95+
else
96+
PUBLIC_IP="$files"
97+
crontab -r
98+
fi
10699

107-
temp_private_ip=`ifconfig eth0 | grep inet | grep -v inet6 | cut -d ":" -f 2 | cut -d " " -f 1`
108-
PRIVATE_IP=$temp_private_ip
109100

110101
for i in `/usr/bin/ruby /opt/get-launch-params.rb`
111102
do
112103
export ${i}
113104
done
114105

115-
if [[ ! -d /opt/${PRODUCT_NAME} ]]; then
116-
if [[ "$(pidof scp)" || "$(pidof unzip)" ]]; then
117-
echo "Copying and unarchiving the products already begun. So exiting ..." >> $LOG
118-
exit 0
119-
fi
120-
if [[ ! -f /opt/${PRODUCT_NAME}.zip ]]; then
121-
echo "Copying the product from the controller" >> $LOG
122-
echo "scp -i ${instance_path}/payload/wso2-key root@${CONTROLLER_IP}:/opt/${PRODUCT_NAME}.zip /opt/" >> $LOG
123-
scp -i ${instance_path}/payload/wso2-key root@${CONTROLLER_IP}:/opt/${PRODUCT_NAME}.zip /opt/
124-
echo "Unarchiving the pack ..." >> $LOG
125-
unzip /opt/${PRODUCT_NAME}.zip -d /opt/
126-
if [ "$?" = "0" ]; then
127-
echo Extracted product >> $LOG
128-
else
129-
echo product zip file is corrupted >> $LOG
130-
exit 0
131-
fi
132-
fi
133-
fi
134106

135107
if [ "$ADMIN_USERNAME" = "" ]; then
136108
echo Launching with default admin username >> $LOG
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#! /usr/bin/ruby
2+
3+
### get-launch-params.rb
4+
5+
# The following script obtains the launch parameters from
6+
# the file /tmp/payload/launch-params, then parses out the
7+
# parameters for this instance by using the launch index
8+
# of this particular EC2 instance.
9+
#
10+
# Pass the command the -e flag to output the instance
11+
# parameters as exports of shell variables. Any other
12+
# arguments are ignored.
13+
14+
def get_launch_params(launch_params_file)
15+
IO.readlines launch_params_file
16+
end
17+
18+
export_stmt = ""
19+
20+
launch_params = get_launch_params(
21+
"/var/lib/cloud/instance/payload/launch-params")
22+
23+
if launch_params.length > 0
24+
instance_params_str = launch_params[0]
25+
26+
instance_params = instance_params_str.split(',')
27+
28+
export_stmt = "export " if ARGV.length > 0 && ARGV.include?("-e")
29+
30+
instance_params.each { |param|
31+
puts export_stmt + param
32+
}
33+
34+
end
35+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This folder is a sample payload sent to a php instance when it is created.
2+
3+
4+
Replace the values in launch_params file with correct values of your environment.
5+
6+
Now pack this payload as payload.zip and pass this when creating php instances.
7+
8+
9+
Following is the /etc/rc.local file of the php instance
10+
11+
#!/bin/sh -e
12+
/opt/wso2-openstack-init.sh > /var/log/wso2-openstack-init.log
13+
exit 0
14+
15+
By the time rc.local file is invokded in the newly created php instance, the payload is already
16+
passed to the instance and reside in /var/lib/cloud/instance/payload
17+
18+
You can see that rc.local invoke the wso2-openstack-init.sh script in the payload.
19+
20+
21+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TENANT=1,SVNPASS=g,SVNURL=http://11.0.0.1:80/svn,APP=php
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:agen="http://agent.cartridge.carbon.wso2.org">
2+
<soapenv:Header/>
3+
<soapenv:Body>
4+
<agen:register>
5+
<registrant>
6+
<hostName>host_name</hostName>
7+
<key>key</key>
8+
<portMappings>
9+
<primaryPort>primary_port</primaryPort>
10+
<proxyPort>proxy_port</proxyPort>
11+
<type>type</type>
12+
</portMappings>
13+
<remoteHost>remote_host</remoteHost>
14+
<service>service</service>
15+
<tenantId>tenant_id</tenantId>
16+
</registrant>
17+
</agen:register>
18+
</soapenv:Body>
19+
</soapenv:Envelope>

0 commit comments

Comments
 (0)