Commit f3f9937d authored by anarcat's avatar anarcat Committed by anarcat

Merge remote branch 'ceres/production'

I had to move the D7 private stuff out of the platform section,
otherwise files were created for the sites/all dir

Conflicts:
	platform/provision_drupal.drush.inc
parents f1c188c5 4c71611b
......@@ -225,31 +225,20 @@ function _provision_drupal_create_directories($url, $profile = NULL) {
"sites/$url/themes" => 02775,
"sites/$url/modules" => 02775,
"sites/$url/libraries" => 02775, # http://drupal.org/node/496240
// d7 support
"sites/$url/private" => 0755,
"sites/$url/private/files" => 02770,
"sites/$url/private/temp" => 02770,
);
$chown = array();
$chgrp = array();
// special case: platform. do not handle files dir
if ($url != 'all') {
$mkdir["sites/$url/files"] = 02770;
$mkdir["sites/$url/files/tmp"] = 02770;
$mkdir["sites/$url/files/images"] = 02770;
$mkdir["sites/$url/files/pictures"] = 02770;
# the owner/group of those directories will be changed
$chown["sites/$url/files"] = drush_get_option('script_user');
$chown["sites/$url/files/tmp"] = drush_get_option('script_user');
$chown["sites/$url/files/images"] = drush_get_option('script_user');
$chown["sites/$url/files/pictures"] = drush_get_option('script_user');
$chgrp["sites/$url/files"] = drush_get_option('web_group');
$chgrp["sites/$url/files/tmp"] = drush_get_option('web_group');
$chgrp["sites/$url/files/images"] = drush_get_option('web_group');
$chgrp["sites/$url/files/pictures"] = drush_get_option('web_group');
// d7 support
$mkdir["sites/$url/private"] = 0755;
$mkdir["sites/$url/private/files"] = 02770;
$mkdir["sites/$url/private/temp"] = 02770;
$chown["sites/$url/private"] = drush_get_option('script_user');
$chown["sites/$url/private/files"] = drush_get_option('script_user');
$chown["sites/$url/private/temp"] = drush_get_option('script_user');
$chgrp["sites/$url/private/files"] = drush_get_option('web_group');
$chgrp["sites/$url/private/temp"] = drush_get_option('web_group');
}
......
......@@ -48,6 +48,21 @@ if ($name['name'] == 'root') {
include_once('provision.inc');
include_once('provision.path.inc');
/**
* implementation of hook_drush_init().
*
* This will abort any process running drush if the load is critical.
*
* @see provision_load_critical()
*/
function provision_drush_init() {
$load = sys_getloadavg();
if (provision_load_critical($load)) {
drush_log(dt("load on system too heavy (@load), aborting", array('@load' => join(" ", $load))));
exit(1);
}
}
/**
* Implementation of hook_drush_command().
*/
......@@ -231,3 +246,73 @@ function _provision_default_web_group() {
return null;
}
/**
* determine the number of CPU on the machine
*
* This tries a best guess at the number of CPUs running on the system. This is
* useful for calculating sane load threshold.
*
* On Linux, this parses /proc/cpuinfo and looks for lines like this:
*
* processor : 0
* ...
* processor : 1
* processor : n
*
* The number of CPUs on the system is n+1, we just count the number of lines.
*
* Other systems remain to be implemented, and would be best implemetend
* through a PECL (or similar) extension that would use the POSIX sysconf
* interface, as such:
*
* ncpus = sysconf(_SC_NPROCESSORS_ONLN);
*
* If no method can be found to figure out the number of CPUs, this will return
* FALSE.
*
* @see provision_load_critical()
* @todo implement for other systems than Linux
*/
function provision_count_cpus() {
$ncpus = FALSE;
# this should work on Linux with a /proc filesystem
$cpuinfo = file_get_contents("/proc/cpuinfo");
if ($cpuinfo !== FALSE) {
if (preg_match_all("/^processor.*:.*[0-9]+$/m", $cpuinfo, $matches)) {
$ncpus = count(array_pop($matches));
}
}
return $ncpus;
}
/**
* determine if overall load of the machine is critical
*
* We use the "average system load" of the system as a metric, as available
* through 'uptime' or in PHP sys_getloadavg() since 5.1. The load is usually
* defined as "the number of processes in the system run queue"
*
* It's not a really reliable metric, but it's the best shot we've got without
* getting into real specific details about I/O, CPU or memory load that are
* going to be even tougher to evaluate.
*
* We base our evaluation on the number of CPUs on the servers. If there are
* more than 5 processes waiting per CPU, we abort completely. If we ignore the
* number of available CPUs, we assume a critical limit is a load of 10.
*
* @see sys_getloadavg()
*/
function provision_load_critical($load = null, $threshold = null) {
if (is_null($load)) {
$load = sys_getloadavg();
}
if (is_null($threshold)) {
if ($ncpus = provision_count_cpus()) {
$threshold = $ncpus * 5;
} else {
// can't determine the number of CPU, we hardcode at load 10
$threshold = 10;
}
}
return ($load[0] > $threshold);
}
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