Commit a7886396 authored by Alain Takoudjou's avatar Alain Takoudjou

Merge branch 'lamp' into master:

commit 9486fa3d33ed70722df0ab78cf0d60f4b1bcab4b
Author: Alain Takoudjou <talino@tiolive.com>
Date:   Thu Oct 20 12:51:52 2011 +0100

    Add documentation for lamp recipe

commit cb684d1170c04ff6ad193b25fb181c71ccded042
Author: Alain Takoudjou <talino@tiolive.com>
Date:   Thu Oct 20 11:07:40 2011 +0100

    Add PunBB [Forum] software release

commit 1b2209ee64fea3854c4a8d0f9c7be1badaf2addb
Author: Alain Takoudjou <talino@tiolive.com>
Date:   Thu Oct 20 10:24:25 2011 +0100

    Add B2evolution [blog] software release

commit adf2972b4678b47ef8b4debdeecaf08536d131d3
Author: Alain Takoudjou <talino@tiolive.com>
Date:   Thu Oct 20 10:19:01 2011 +0100

    Restore lamp-template/software.cfg after the merge of lamp with master

commit 9b07d7c1a64b6ff346bfe444664787ff60886033
Author: Alain Takoudjou <talino@tiolive.com>
Date:   Wed Oct 19 15:35:46 2011 +0100

    Restore lamp.cfg

commit 4804e7aa0c1f99aad61732955f9da4a486f6aed0
Author: Alain Takoudjou <talino@tiolive.com>
Date:   Wed Oct 19 15:31:37 2011 +0100

    Add comment and fix indentation
parent 5676ddf8
lamp
=====
the lamp recipe help you to deploy simply a php based application on slapos. This recipe is
able to setup mariadb, apache and apache-php for your php application, is also capable to
configure your software during installation to ensure a full compatibility.
How to use?
-----------
just add this part in your software.cfg to use the lamp.simple module
[instance-recipe]
egg = slapos.cookbook
module = lamp.simple
you also need to extend lamp.cfg
extends =
http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.50:/stack/lamp.cfg
lamp.runner
=====
When you install some software (such as prestashop) you need to remove or rename folder, with slapos you can not
access to the www-data directory. to do this, you need to tell to lamp recipe to remove or/and it when software
will be instantiated. Some software requires more than rename or delete a folder (manualy create database etc...)
in this case you need to write a python script and lamp recipe must run it when installing your software.
How to use?
-----------
CONDITION
--------
the action (move, rename, launch script) only starts when the condition is filled.
in instance.cfg, add
file_token = path_of_file
and the action will begin when path_of_www-data/path_of_file will be created
you can also use database to check condition. add
table_name = name_of_table
constraint = sql_where_condition
name_of_table is the full or partial name(in some cases we can not know the prefix used to create tables) of table
into mariadb databse for example table_name = admin. if you use
name_of_table = **, the action will begin when database is ready.
constraint is the sql_condition to use when search entry into name_of_table for example constraint = `admin_id`=1
you can no use file_token and table_name at the same time, otherwise file_token will be used in priority. attention
to the conditions that will never be satisfied.
ACTION
-------
the action start when condition is true
1- delete file or folder
into instance.cfg, use
delete = file_or_folder1, file_or_folder2, file_or_folder3 ...
for example delete = admin
2- rename file or folder
into instance.cfg, use
rename = old_name1 => new_name1, old_name2 => new_name2, ... you can also use
rename = old_name1, old_name2 => new_name2, ... in this case old_name1 will be rename and the new name will be chose
by joining old_name1 and mysql_user: this should give
rename = old_name1 => old_name1-mysql_user, old_name2 => new_name2, ...
3- launch python script
use script = ${configure-script:location}/${configure-script:filename} into instance.cfg, add part configure-script
into software.cfg
parts = configure-script
[configure-script]
recipe = hexagonit.recipe.download
location = ${buildout:parts-directory}/${:_buildout_section_name_}
url = url_of_script_name.py
filename = script_name.py
download-only = True
the script_name.py should contain a main module, sys.argv is passed to the main. you can write script_name.py like this
....
def setup(args):
base_url, htdocs, renamed, mysql_user, mysql_password, mysql_database, mysql_host = args
.......
if __name__ == '__main__':
setup(sys.argv[1:])
base_url: is the url of php software
htdocs: is the path of www-data directory
mysql_user, mysql_password, mysql_database, mysql_host: is the mariadb parameters
......@@ -154,6 +154,9 @@ class BaseRecipe(BaseSlapRecipe):
open(destination, 'w').write(open(template, 'r').read() % d)
def configureInstallation(self, document_root, mysql_conf, url):
"""Start process which can launch python scripts, move or remove files or
directories when installing software.
"""
if not self.options.has_key('delete') and not \
self.options.has_key('rename') and not self.options.has_key('script'):
return
......
......@@ -5,63 +5,78 @@ import shutil
import MySQLdb
def executeRunner(args):
delete, rename, token, mysql_config, script_data = args
timeout = 5;
while True:
if not checkAction(token, mysql_config):
print "Waiting for 3s and retrying"
time.sleep(3)
continue
time.sleep(timeout)
for path in delete:
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
for data in rename:
os.rename(data['old'], data['new'])
if script_data != {}:
script = script_data['script']
if os.path.exists(script):
import subprocess
#run python script with predefined data
return_code = subprocess.call([sys.executable, script, script_data['base_url'],
script_data['htdocs'], script_data['renamed'],
mysql_config['mysql_user'], mysql_config['mysql_password'],
mysql_config['mysql_database'], mysql_config['mysql_host']])
if return_code != 0:
print "Execution of script %r failed with code: %s" % (script, return_code)
return
"""Start the instance runner. this may run a python script, move or/and rename
file or directory when dondition is filled. the condition may be when file exist or when an entry
exist into database.
"""
delete, rename, token, mysql_config, script_data = args
timeout = 5;
while True:
if not checkAction(token, mysql_config):
print "Waiting for 3s and retrying"
time.sleep(3)
continue
time.sleep(timeout)
for path in delete:
if not os.path.exists(path):
print "Error when deleting: '%s': no such file or directory" % path
continue
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
for data in rename:
if not os.path.exists(data['old']):
print "Error when moving: '%s': no such file or directory" % data['old']
continue
os.rename(data['old'], data['new'])
if script_data != {}:
script = script_data['script']
if os.path.exists(script):
import subprocess
#run python script with predefined data
return_code = subprocess.call([sys.executable, script, script_data['base_url'],
script_data['htdocs'], script_data['renamed'],
mysql_config['mysql_user'], mysql_config['mysql_password'],
mysql_config['mysql_database'], mysql_config['mysql_host']])
if return_code != 0:
print "Error: execution of script %r failed with code: %s" % (script, return_code)
else:
print "Error: can not read file '%s'" % script
return
def checkAction(token, mysql_config):
if type(token) is dict:
try:
conn = MySQLdb.connect (host = mysql_config['mysql_host'],
port = int(mysql_config['mysql_port']),
user = mysql_config['mysql_user'],
passwd = mysql_config['mysql_password'],
db = mysql_config['mysql_database'])
except:
#Mysql is not ready yet?...
return False
if token['table'] == "**":
#only detect if mysql has been started
conn.close()
return True
cursor = conn.cursor ()
cursor.execute("SHOW TABLES LIKE '%" + token['table'] + "'") #Check if table has been created
row = cursor.fetchone ()
if row == None:
conn.close()
return False
else:
token['table'] = row[0]
cursor.execute ("SELECT * FROM " + token['table'] + " WHERE " + token['constraint'])
row = cursor.fetchone ()
conn.close()
if row == None:
return False
else:
return True
"""Check if condition is filled. If token is string(that represent a path), the function check if file exist
otherwise token is a dictionary and mysql_config is used to check condition into database
"""
if type(token) is dict:
try:
conn = MySQLdb.connect (host = mysql_config['mysql_host'],
port = int(mysql_config['mysql_port']),
user = mysql_config['mysql_user'],
passwd = mysql_config['mysql_password'],
db = mysql_config['mysql_database'])
except:
#Mysql is not ready yet?...
return False
if token['table'] == "**":
#only detect if mysql has been started
conn.close()
return True
cursor = conn.cursor ()
cursor.execute("SHOW TABLES LIKE '%" + token['table'] + "'") #Check if table has been created
row = cursor.fetchone ()
if row == None:
conn.close()
return False
else:
return os.path.exists(token)
\ No newline at end of file
token['table'] = row[0]
cursor.execute ("SELECT * FROM " + token['table'] + " WHERE " + token['constraint'])
row = cursor.fetchone ()
conn.close()
if row == None:
return False
else:
return True
else:
return os.path.exists(token)
\ No newline at end of file
[buildout]
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
parts = instance
[instance]
recipe = ${instance-recipe:egg}:${instance-recipe:module}
source = ${application:location}
template = ${application-template:location}/${application-template:filename}
configuration = ${application-configuration:location}
httpd_binary = ${apache:location}/bin/httpd
mysql_binary = ${mariadb:location}/bin/mysql
mysql_install_binary = ${mariadb:location}/bin/mysql_install_db
mysql_upgrade_binary = ${mariadb:location}/bin/mysql_upgrade
mysqld_binary = ${mariadb:location}/libexec/mysqld
[buildout]
versions = versions
parts =
template
apache-php
mariadb
eggs
instance-recipe-egg
downloadcache-workaround
extends =
../../stack/lamp.cfg
../../stack/shacache-client.cfg
[application]
recipe = slapos.recipe.build
url = http://freefr.dl.sourceforge.net/project/evocms/b2evolution/b2evo%204.1.1-stable/b2evolution-4.1.1-stable-2011-10-03.zip
md5sum = 63c771f43f0c40ff822fe80234be42e1
script =
if not self.options.get('url'): self.options['url'], self.options['md5sum'] = self.options[guessPlatform()].split(' ')
extract_dir = self.extract(self.download(self.options['url'], self.options.get('md5sum')))
workdir = guessworkdir(extract_dir)
self.copyTree(workdir + "/blogs", "${buildout:parts-directory}/${:_buildout_section_name_}")
[application-template]
recipe = slapos.recipe.download
url = ${:_profile_base_location_}/template/b2evolution.inc.php.in
#md5sum = Student may put here md5sum of this file, this is good idea
download-only = True
filename = template.in
mode = 0644
location = ${buildout:parts-directory}/${:_buildout_section_name_}
[application-configuration]
location = config.inc.php
[instance-recipe]
egg = slapos.cookbook
module = lamp.simple
[template]
# Default template for the instance.
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg
#md5sum = Student shall put md5 of instance.cfg here
output = ${buildout:directory}/template.cfg
mode = 0644
[instance-recipe-egg]
recipe = zc.recipe.egg
python = python2.7
eggs = ${instance-recipe:egg}
[versions]
# Use SlapOS patched zc.buildout
zc.buildout = 1.5.3-dev-SlapOS-010
[downloadcache-workaround]
# workaround irritating problem of hexagonit.recipe.cmmi which automatically
# creates download cache, which in turn switches builout to "semi-offline" mode
recipe = plone.recipe.command
# in hexagonit.recipe.cmmi if there is no ${buildout:download-cache} set it resolves
# to ${buildout:directory}/downloads but this variable is available late, that's
# why it is hardcoded only for required case
download-cache = ${buildout:directory}/downloads
command = [ -d ${:download-cache} ] && rm -fr ${:download-cache}/* || exit 0
update-command = ${:command}
stop-on-error = True
<?php
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$i = 0;
$i++;
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'Put here mysql host template key';
$cfg['Servers'][$i]['port'] = 'Put here mysql port template key';
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
/* rajk - for blobstreaming */
$cfg['Servers'][$i]['bs_garbage_threshold'] = 50;
$cfg['Servers'][$i]['bs_repository_threshold'] = '32M';
$cfg['Servers'][$i]['bs_temp_blob_timeout'] = 600;
$cfg['Servers'][$i]['bs_temp_log_threshold'] = '32M';
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
?>
......@@ -31,7 +31,7 @@ location = ${buildout:parts-directory}/${:_buildout_section_name_}
[application-configuration]
location = Student shall put here relative path to application top level directory where configuration shall be created
[instance-recipe]
egg = slapos.cookbook
module = lamp.simple
......@@ -52,11 +52,6 @@ eggs = ${instance-recipe:egg}
[versions]
# Use SlapOS patched zc.buildout
zc.buildout = 1.5.3-dev-SlapOS-010
slapos.cookbook = 0.20
# Temporary fix for slapos-0.50
[lxml-python]
find-links += http://pypi.python.org/pypi/lxml/2.3.1
[downloadcache-workaround]
# workaround irritating problem of hexagonit.recipe.cmmi which automatically
......
[buildout]
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
parts = instance
[instance]
recipe = ${instance-recipe:egg}:${instance-recipe:module}
source = ${application:location}
template = ${application-template:location}/${application-template:filename}
configuration = ${application-configuration:location}
httpd_binary = ${apache:location}/bin/httpd
mysql_binary = ${mariadb:location}/bin/mysql
mysql_install_binary = ${mariadb:location}/bin/mysql_install_db
mysql_upgrade_binary = ${mariadb:location}/bin/mysql_upgrade
mysqld_binary = ${mariadb:location}/libexec/mysqld
[buildout]
versions = versions
parts =
template
apache-php
mariadb
eggs
instance-recipe-egg
downloadcache-workaround
extends =
../../stack/lamp.cfg
../../stack/shacache-client.cfg
[application]
recipe = hexagonit.recipe.download
url = http://punbb.informer.com/download/punbb-1.3.6.tar.gz
md5sum = 9454ef78101028fd5acf2731f77545c2
#If provided tarball does not contain top directory, option shall be changed to false
#strip-top-level-dir = true
[application-template]
recipe = slapos.recipe.download
url = ${:_profile_base_location_}/template/punbb.inc.php.in
#md5sum = Student may put here md5sum of this file, this is good idea
download-only = True
filename = template.in
mode = 0644
location = ${buildout:parts-directory}/${:_buildout_section_name_}
[application-configuration]
location = config.inc.php
[instance-recipe]
egg = slapos.cookbook
module = lamp.simple
[template]
# Default template for the instance.
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg
#md5sum = Student shall put md5 of instance.cfg here
output = ${buildout:directory}/template.cfg
mode = 0644
[instance-recipe-egg]
recipe = zc.recipe.egg
python = python2.7
eggs = ${instance-recipe:egg}
[versions]
# Use SlapOS patched zc.buildout
zc.buildout = 1.5.3-dev-SlapOS-010
[downloadcache-workaround]
# workaround irritating problem of hexagonit.recipe.cmmi which automatically
# creates download cache, which in turn switches builout to "semi-offline" mode
recipe = plone.recipe.command
# in hexagonit.recipe.cmmi if there is no ${buildout:download-cache} set it resolves
# to ${buildout:directory}/downloads but this variable is available late, that's
# why it is hardcoded only for required case
download-cache = ${buildout:directory}/downloads
command = [ -d ${:download-cache} ] && rm -fr ${:download-cache}/* || exit 0
update-command = ${:command}
stop-on-error = True
<?php
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$i = 0;
$i++;
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'Put here mysql host template key';
$cfg['Servers'][$i]['port'] = 'Put here mysql port template key';
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
/* rajk - for blobstreaming */
$cfg['Servers'][$i]['bs_garbage_threshold'] = 50;
$cfg['Servers'][$i]['bs_repository_threshold'] = '32M';
$cfg['Servers'][$i]['bs_temp_blob_timeout'] = 600;
$cfg['Servers'][$i]['bs_temp_log_threshold'] = '32M';
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
?>
......@@ -30,12 +30,10 @@ extends =
../component/glib/buildout.cfg
../component/logrotate/buildout.cfg
../component/python-2.7/buildout.cfg
../component/perl/buildout.cfg
../component/sqlite3/buildout.cfg
../component/xtrabackup/buildout.cfg
../component/rdiff-backup/buildout.cfg
../component/lxml-python/buildout.cfg
../component/zlib/buildout.cfg
../component/stunnel/buildout.cfg
../component/mysql-python/buildout.cfg
[application]
recipe = hexagonit.recipe.download
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment