Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Douglas
slapos
Commits
693e8a42
Commit
693e8a42
authored
Oct 26, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't overwrite database; retrieve randomly generated admin password
parent
7a4cbf56
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
8 deletions
+98
-8
slapos/recipe/drupal/__init__.py
slapos/recipe/drupal/__init__.py
+93
-5
software/drupal/instance-custom.cfg.in
software/drupal/instance-custom.cfg.in
+2
-0
software/drupal/settings.php.in
software/drupal/settings.php.in
+1
-1
software/drupal/software.cfg
software/drupal/software.cfg
+2
-2
No files found.
slapos/recipe/drupal/__init__.py
View file @
693e8a42
...
...
@@ -27,10 +27,27 @@
import
os
import
subprocess
import
tempfile
import
textwrap
from
slapos.recipe.librecipe
import
GenericBaseRecipe
# XXX
# Current issues:
# - drush connects to mysql with the password on command line
# see http://stackoverflow.com/questions/6607675/shell-script-password-security-of-command-line-parameters
# it could use a socket, but we are on a different instance than mysql
# - the admin_password is not published yet.
# - using slapproxy, sometimes this recipe is not able to connect to mysql (tunnel down).
# restarting from supervisor usually solves it.
#
def
chown_set
(
path
,
mode
):
prev_mode
=
os
.
stat
(
path
).
st_mode
os
.
chmod
(
path
,
prev_mode
|
mode
)
class
InitRecipe
(
GenericBaseRecipe
):
"""
\
...
...
@@ -38,19 +55,90 @@ class InitRecipe(GenericBaseRecipe):
- Call the 'drush' command to install a Drupal site and initial database schema.
Database connection parameters are taken from the provided settings.php file.
If the database is not empty (ie contains at least one table) the drush script is not called.
"""
def
install
(
self
):
drush_binary
=
self
.
options
[
'drush-binary'
]
htdocs
=
self
.
options
[
'htdocs'
]
settings_php
=
self
.
options
[
'settings-php'
]
if
not
settings_php
.
startswith
(
'/'
):
settings_php
=
os
.
path
.
join
(
htdocs
,
settings_php
)
os
.
chdir
(
htdocs
)
output
=
subprocess
.
check_output
([
drush_binary
,
if
self
.
is_db_empty
(
php_binary
=
self
.
options
[
'php-binary'
],
settings_php
=
settings_php
):
drush_output
=
subprocess
.
check_output
([
drush_binary
,
'-y'
,
'site-install'
,
'--account-name=admin'
,
'--account-pass=admin'
])
'--account-name=admin'
],
stderr
=
subprocess
.
STDOUT
)
self
.
options
[
'admin_password'
]
=
self
.
extract_password
(
drush_output
)
# drush removes the 'w' bit from both the settings file and its
# directory.
# we restore them, otherwise buildout will see the file as changed
# and try to remove it and reinstall the apachephp recipe.
for
path
in
[
settings_php
,
os
.
path
.
dirname
(
settings_php
)]:
chown_set
(
path
,
0200
)
# XXX return what?
return
[]
def
extract_password
(
self
,
drush_output
):
return
re
.
search
(
'User password: (
\
S+)
'
, drush_output).groups()[0]
def is_db_empty(self, php_binary, settings_php):
with tempfile.NamedTemporaryFile() as fout:
settings_dirname, settings_filename = os.path.split(settings_php)
fout.write(textwrap.dedent("""
\
#!%(php_binary)s
<?php
ini_set('
include_path
',ini_get('
include_path
').'
:
%
(
settings_dirname
)
s
:
');
require('
%
(
settings_filename
)
s
');
# taken from drupal: includes/mysql/database.inc
$connection_options = $databases['
default
']['
default
'];
$dsn = '
mysql
:
host
=
' . $connection_options['
host
'] . '
;
port
=
' . (empty($connection_options['
port
']) ? 3306 : $connection_options['
port
']);
$dsn .= '
;
dbname
=
' . $connection_options['
database
'];
$db = new PDO($dsn, $connection_options['
username
'], $connection_options['
password
']);
$tables = $db->query('
SHOW
TABLES
')->fetchAll();
if (count($tables) > 0) {
exit(10);
} else {
exit(0);
}
""" % {
'
php_binary
': php_binary,
'
settings_dirname
': settings_dirname,
'
settings_filename
': settings_filename
}))
fout.flush()
try:
output = subprocess.check_call([php_binary, '
-
f', fout.name])
except subprocess.CalledProcessError as exc:
if exc.returncode == 10:
# the database already contains some tables.
return False
return True
software/drupal/instance-custom.cfg.in
View file @
693e8a42
...
...
@@ -3,6 +3,8 @@
[drupal-init]
recipe = slapos.cookbook:drupal_init
drush-binary = ${apache-php:location}/bin/drush
php-binary = ${apache-php:location}/bin/php
settings-php = ${application-configuration:location}
htdocs = $${rootdirectory:srv}/www
dependency = $${apache-php:recipe}
software/drupal/settings.php.in
View file @
693e8a42
...
...
@@ -280,7 +280,7 @@ $drupal_hash_salt = '';
* To see what PHP settings are possible, including whether they can be set at
* runtime (by using ini_set()), read the PHP documentation:
* http://www.php.net/manual/en/ini.list.php
* See drupal_
initialize_variables
() in includes/bootstrap.inc for required
* See drupal_
environment_initialize
() in includes/bootstrap.inc for required
* runtime settings and the .htaccess file for non-runtime settings. Settings
* defined there should not be duplicated here so as to avoid conflict issues.
*/
...
...
software/drupal/software.cfg
View file @
693e8a42
...
...
@@ -15,7 +15,7 @@ md5sum = 352497b2df94b5308e31cb8da020b631
[application-template]
recipe = slapos.recipe.download
url = ${:_profile_base_location_}/settings.php.in
md5sum =
b4dfbdb950c25c93a8c3f9f78e9bff6e
md5sum =
393813c5660590dfde74f835afa3389a
download-only = True
filename = template.in
mode = 0644
...
...
@@ -33,7 +33,7 @@ part-list = drupal-init
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-custom.cfg.in
output = ${buildout:directory}/instance-custom.cfg
md5sum =
bd071532528120f5da1fb6050d4c80e8
md5sum =
86a6e065a8e01416f0c028a0571615db
mode = 0644
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment