Add lamp-generic SR.
[slapos.git] / slapos / recipe / lampgeneric / __init__.py
1 ##############################################################################
2 #
3 # Copyright (c) 2013 Vifib SARL and Contributors. All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsibility of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # guarantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 3
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #
26 ##############################################################################
27
28 import shutil
29 import os
30 import zc.buildout
31
32 from slapos.recipe.librecipe import GenericBaseRecipe
33
34 class Recipe(GenericBaseRecipe):
35 # XXX-Cedric: write docstring
36
37 def install(self):
38 path_list = []
39
40 # Download and unpack application if not already existing
41 htdocs_location = self.options['htdocs']
42 if not (os.path.exists(htdocs_location) and os.listdir(htdocs_location)):
43 try:
44 os.rmdir(htdocs_location)
45 except:
46 pass
47 self.download(htdocs_location)
48
49 # Install php.ini
50 php_ini = self.createFile(os.path.join(self.options['php-ini-dir'],
51 'php.ini'),
52 self.substituteTemplate(self.getTemplateFilename('php.ini.in'),
53 dict(tmp_directory=self.options['tmp-dir']))
54 )
55 path_list.append(php_ini)
56
57 # Install apache
58 apache_config = dict(
59 pid_file=self.options['pid-file'],
60 lock_file=self.options['lock-file'],
61 ip=self.options['ip'],
62 port=self.options['port'],
63 error_log=self.options['error-log'],
64 access_log=self.options['access-log'],
65 document_root=self.options['htdocs'],
66 php_ini_dir=self.options['php-ini-dir'],
67 )
68 httpd_conf = self.createFile(self.options['httpd-conf'],
69 self.substituteTemplate(self.getTemplateFilename('apache.in'),
70 apache_config)
71 )
72 path_list.append(httpd_conf)
73
74 wrapper = self.createWrapper(name=self.options['wrapper'],
75 command=self.options['httpd-binary'],
76 parameters=[
77 '-f',
78 self.options['httpd-conf'],
79 '-DFOREGROUND'
80 ])
81 path_list.append(wrapper)
82
83
84 return path_list