2002-10-03 18:33:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// test.inc
|
|
|
|
//
|
|
|
|
// A set of classes for testing BOINC.
|
|
|
|
// These classes let you create multiple projects and multiple hosts
|
|
|
|
// (all running on a single machine),
|
|
|
|
// add applications and work units, run the system,
|
|
|
|
// and verify that the results are correct.
|
|
|
|
//
|
|
|
|
// See doc/test.html for details
|
|
|
|
|
2003-04-01 07:34:08 +00:00
|
|
|
define("RESULT_STATE_OVER", 5);
|
2002-10-06 00:43:55 +00:00
|
|
|
|
2003-01-07 01:02:08 +00:00
|
|
|
ob_end_flush(); // let us see what's going on
|
|
|
|
|
2002-10-03 18:33:46 +00:00
|
|
|
// get an enviroment variable, and abort script if missing
|
|
|
|
//
|
|
|
|
function get_env_var($name) {
|
|
|
|
$x = getenv($name);
|
|
|
|
if ($x == null) {
|
|
|
|
echo "Environment variable $name not defined\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_db_script($script, $db_name) {
|
|
|
|
$db_dir = get_env_var("BOINC_SRC_DIR")."/db";
|
|
|
|
$x = "sed -e s/BOINC_DB_NAME/$db_name/ $db_dir/$script | mysql";
|
2003-01-15 23:54:24 +00:00
|
|
|
//echo $x;
|
2002-10-03 18:33:46 +00:00
|
|
|
PassThru($x);
|
|
|
|
}
|
|
|
|
|
2003-01-13 23:37:56 +00:00
|
|
|
// expand a macro in a file
|
|
|
|
//
|
|
|
|
function macro_substitute($macro, $replacement, $infile, $outfile) {
|
|
|
|
$x = "sed -e s/$macro/$replacement/ $infile > $outfile";
|
2003-01-15 23:54:24 +00:00
|
|
|
//echo $x;
|
2003-01-13 23:37:56 +00:00
|
|
|
PassThru($x);
|
|
|
|
}
|
|
|
|
|
|
|
|
// make a file executable
|
|
|
|
//
|
|
|
|
function make_executable($name) {
|
|
|
|
PassThru("chmod uog+x $name");
|
|
|
|
}
|
|
|
|
|
2003-02-21 01:38:16 +00:00
|
|
|
// given a project URL,
|
|
|
|
// return the name of the account file
|
|
|
|
//
|
|
|
|
function account_file_name($url) {
|
|
|
|
$x = strstr($url, "http://");
|
|
|
|
if ($x) {
|
|
|
|
$x = substr($x, strlen("http://"));
|
|
|
|
} else {
|
|
|
|
$x = $url;
|
|
|
|
}
|
|
|
|
$encoded_name = strtr($x, "/", "_");
|
|
|
|
return "account_".$encoded_name.".xml";
|
|
|
|
}
|
|
|
|
|
2002-10-03 18:33:46 +00:00
|
|
|
function db_open($db_name) {
|
|
|
|
$retval = mysql_connect();
|
|
|
|
if (!$retval) {
|
|
|
|
echo "mysql_connect() failed\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$retval = mysql_select_db($db_name);
|
|
|
|
if (!$retval) {
|
|
|
|
echo "mysql_select_db() failed\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function db_query($query) {
|
|
|
|
if (!mysql_query($query)) {
|
|
|
|
echo "mysql_query failed: $query\n";
|
|
|
|
echo mysql_error();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_tool($cmd) {
|
|
|
|
$tool_dir = get_env_var("BOINC_SRC_DIR")."/tools/";
|
|
|
|
$cmd = $tool_dir.$cmd;
|
2002-12-06 07:33:45 +00:00
|
|
|
echo "$cmd\n";
|
2002-10-03 18:33:46 +00:00
|
|
|
PassThru($cmd);
|
|
|
|
}
|
|
|
|
|
2002-10-14 23:10:12 +00:00
|
|
|
function create_keys() {
|
|
|
|
$key_dir = get_env_var("BOINC_KEY_DIR");
|
|
|
|
$lib_dir = get_env_var("BOINC_SRC_DIR")."/lib";
|
|
|
|
PassThru("$lib_dir/crypt_prog -genkey 1024 $key_dir/upload_private $key_dir/upload_public");
|
|
|
|
PassThru("$lib_dir/crypt_prog -genkey 1024 $key_dir/code_sign_private $key_dir/code_sign_public");
|
|
|
|
}
|
|
|
|
|
2003-02-12 18:51:05 +00:00
|
|
|
class Platform {
|
|
|
|
var $name;
|
|
|
|
var $user_friendly_name;
|
|
|
|
|
|
|
|
function Platform($name, $ufn) {
|
|
|
|
$this->name = $name;
|
|
|
|
$this->user_friendly_name = $ufn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-03 18:33:46 +00:00
|
|
|
class App {
|
|
|
|
var $name;
|
|
|
|
|
|
|
|
function App($name) {
|
|
|
|
$this->name = $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class App_Version {
|
|
|
|
var $app;
|
|
|
|
var $version;
|
2003-02-12 18:51:05 +00:00
|
|
|
var $exec_dir;
|
2003-05-08 17:13:57 +00:00
|
|
|
var $exec_names; // array of filenames;
|
|
|
|
// defaults to one element: $app->name
|
2003-02-12 18:51:05 +00:00
|
|
|
var $platform;
|
2002-10-03 18:33:46 +00:00
|
|
|
|
|
|
|
function App_Version($app) {
|
2003-05-08 17:13:57 +00:00
|
|
|
$this->exec_names = array();
|
2002-10-03 18:33:46 +00:00
|
|
|
$this->app = $app;
|
|
|
|
$this->version = 1;
|
2003-02-12 18:51:05 +00:00
|
|
|
$x = get_env_var("BOINC_PLATFORM");
|
|
|
|
$this->platform= new Platform($x, $x);
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Project {
|
2003-02-14 22:59:25 +00:00
|
|
|
var $short_name;
|
|
|
|
var $long_name;
|
2002-10-03 18:33:46 +00:00
|
|
|
var $users;
|
|
|
|
var $apps;
|
|
|
|
var $app_versions;
|
2003-02-12 18:51:05 +00:00
|
|
|
var $platforms;
|
2002-10-03 18:33:46 +00:00
|
|
|
var $project_dir;
|
|
|
|
var $db_name;
|
2002-10-10 21:45:08 +00:00
|
|
|
var $db_passwd;
|
2002-10-03 18:33:46 +00:00
|
|
|
var $generate_keys;
|
|
|
|
var $shmem_key;
|
|
|
|
var $key_dir;
|
|
|
|
var $download_url;
|
|
|
|
var $scheduler_url;
|
|
|
|
var $upload_url;
|
|
|
|
var $user_name;
|
|
|
|
var $master_url;
|
2002-10-04 00:16:41 +00:00
|
|
|
var $resource_share;
|
2002-12-24 03:03:45 +00:00
|
|
|
var $source_dir;
|
2003-02-12 23:06:49 +00:00
|
|
|
var $project_php_file;
|
2003-02-24 21:31:36 +00:00
|
|
|
var $project_prefs_php_file;
|
2002-10-03 18:33:46 +00:00
|
|
|
|
|
|
|
function Project() {
|
2003-02-14 22:59:25 +00:00
|
|
|
$this->short_name = "test";
|
|
|
|
$this->long_name = "test";
|
2002-10-03 18:33:46 +00:00
|
|
|
$this->users = array();
|
|
|
|
$this->apps = array();
|
|
|
|
$this->app_versions = array();
|
2003-02-12 18:51:05 +00:00
|
|
|
$this->platforms = array();
|
2002-10-10 21:45:08 +00:00
|
|
|
$this->db_passwd = "";
|
2002-10-03 18:33:46 +00:00
|
|
|
$this->generate_keys = false;
|
2002-10-15 21:55:48 +00:00
|
|
|
$this->shmem_key = get_env_var("BOINC_SHMEM_KEY");
|
2002-10-04 00:16:41 +00:00
|
|
|
$this->resource_share = 1;
|
2002-12-24 03:03:45 +00:00
|
|
|
$this->source_dir = get_env_var("BOINC_SRC_DIR");
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_user($user) {
|
|
|
|
array_push($this->users, $user);
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_app($app) {
|
|
|
|
array_push($this->apps, $app);
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_app_version($app_version) {
|
|
|
|
array_push($this->app_versions, $app_version);
|
|
|
|
}
|
|
|
|
|
2003-02-12 18:51:05 +00:00
|
|
|
function add_platform($platform) {
|
|
|
|
array_push($this->platforms, $platform);
|
2002-10-10 21:45:08 +00:00
|
|
|
}
|
|
|
|
|
2002-10-03 18:33:46 +00:00
|
|
|
// Set up the database and directory structures for a project
|
|
|
|
//
|
2003-02-12 18:51:05 +00:00
|
|
|
function install($scheduler_file = null) {
|
2002-12-24 03:03:45 +00:00
|
|
|
$source_dir = $this->source_dir;
|
2002-10-03 18:33:46 +00:00
|
|
|
$base_dir = get_env_var("BOINC_PROJECTS_DIR");
|
2003-02-14 22:59:25 +00:00
|
|
|
$cgi_url = get_env_var("BOINC_CGI_URL")."/".$this->short_name;
|
|
|
|
$this->download_url = get_env_var("BOINC_HTML_URL")."/".$this->short_name."/download";
|
2002-11-12 17:01:16 +00:00
|
|
|
$this->upload_url = $cgi_url."/file_upload_handler";
|
2002-12-02 04:29:40 +00:00
|
|
|
$this->scheduler_url = $cgi_url."/cgi";
|
2003-02-14 22:59:25 +00:00
|
|
|
$this->project_dir = $base_dir."/".$this->short_name;
|
2003-02-21 01:38:16 +00:00
|
|
|
$this->master_url = get_env_var("BOINC_HTML_URL")."/".$this->short_name."/";
|
2002-10-03 18:33:46 +00:00
|
|
|
PassThru("rm -rf $this->project_dir");
|
|
|
|
PassThru("mkdir $this->project_dir");
|
2002-10-09 04:56:41 +00:00
|
|
|
// make the CGI writeable in case scheduler writes req/reply files
|
|
|
|
PassThru("mkdir $this->project_dir/cgi; chmod uog+w $this->project_dir/cgi");
|
2002-10-03 18:33:46 +00:00
|
|
|
PassThru("mkdir $this->project_dir/upload; chmod uog+w $this->project_dir/upload");
|
|
|
|
PassThru("mkdir $this->project_dir/download");
|
|
|
|
PassThru("mkdir $this->project_dir/keys");
|
|
|
|
PassThru("mkdir $this->project_dir/html_ops");
|
|
|
|
PassThru("mkdir $this->project_dir/html_user");
|
2003-02-14 18:28:43 +00:00
|
|
|
PassThru("ln -s $this->project_dir/download $this->project_dir/html_user/download");
|
2002-10-03 18:33:46 +00:00
|
|
|
|
|
|
|
if ($this->generate_keys) {
|
2002-12-02 04:29:40 +00:00
|
|
|
echo "KEY GENERATION NOT IMPLEMENTED YET\n";
|
2002-10-03 18:33:46 +00:00
|
|
|
} else {
|
|
|
|
$this->key_dir = get_env_var("BOINC_KEY_DIR");
|
|
|
|
PassThru("cp $this->key_dir/* $this->project_dir/keys");
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up the database
|
|
|
|
//
|
|
|
|
$this->user_name = get_env_var("BOINC_USER_NAME");
|
2002-11-19 19:37:01 +00:00
|
|
|
if (!$this->db_name)
|
2003-02-14 22:59:25 +00:00
|
|
|
$this->db_name = $this->user_name."_".$this->short_name;
|
2002-10-03 18:33:46 +00:00
|
|
|
run_db_script("drop.sql", $this->db_name);
|
|
|
|
run_db_script("schema.sql", $this->db_name);
|
|
|
|
run_db_script("constraints.sql", $this->db_name);
|
|
|
|
|
|
|
|
db_open($this->db_name);
|
2003-02-14 22:59:25 +00:00
|
|
|
db_query("insert into project(short_name, long_name) values('$this->short_name', '$this->long_name')");
|
2002-10-03 18:33:46 +00:00
|
|
|
|
|
|
|
for ($i=0; $i<sizeof($this->users); $i++) {
|
|
|
|
$user = $this->users[$i];
|
|
|
|
$now = time(0);
|
2003-02-21 01:38:16 +00:00
|
|
|
$pp = null;
|
|
|
|
if ($user->project_prefs) {
|
|
|
|
$pp = "<project_preferences>\n$user->project_prefs</project_preferences>\n";
|
|
|
|
}
|
2003-02-26 00:47:57 +00:00
|
|
|
$gp = null;
|
|
|
|
if ($user->global_prefs) {
|
|
|
|
$gp = "<global_preferences>\n$user->global_prefs</global_preferences>\n";
|
|
|
|
}
|
2003-03-20 02:05:25 +00:00
|
|
|
db_query("insert into user values (0, $now, '$user->email_addr', '$user->name', '$user->authenticator', 'Peru', '12345', 0, 0, 0, '$gp', '$pp', 0, 'home', '', 0, 1)");
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "adding apps\n";
|
|
|
|
for ($i=0; $i<sizeof($this->apps); $i++) {
|
|
|
|
$app = $this->apps[$i];
|
2002-10-10 21:45:08 +00:00
|
|
|
$now = time(0);
|
2002-10-03 18:33:46 +00:00
|
|
|
db_query("insert into app(name, create_time) values ('$app->name', $now)");
|
|
|
|
}
|
|
|
|
|
2002-10-10 21:45:08 +00:00
|
|
|
echo "adding platforms\n";
|
2003-02-12 18:51:05 +00:00
|
|
|
for ($i=0; $i<sizeof($this->app_versions); $i++) {
|
|
|
|
$app_version = $this->app_versions[$i];
|
|
|
|
$p = $app_version->platform;
|
|
|
|
$found = false;
|
|
|
|
for ($j=0; $j<sizeof($this->platforms); $j++) {
|
|
|
|
if (strcmp($this->platforms[$j]->name, $p->name) == 0) {
|
|
|
|
$found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$found) {
|
|
|
|
array_push($this->platforms, $app_version->platform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ($i=0; $i<sizeof($this->platforms); $i++) {
|
|
|
|
$platform = $this->platforms[$i];
|
|
|
|
run_tool("add platform -db_name $this->db_name -platform_name $platform->name -user_friendly_name '$platform->user_friendly_name'");
|
2002-10-10 21:45:08 +00:00
|
|
|
}
|
|
|
|
|
2002-10-03 18:33:46 +00:00
|
|
|
echo "adding app versions\n";
|
|
|
|
for ($i=0; $i<sizeof($this->app_versions); $i++) {
|
|
|
|
$app_version = $this->app_versions[$i];
|
|
|
|
$app = $app_version->app;
|
2003-02-12 18:51:05 +00:00
|
|
|
if ($app_version->exec_dir == null) {
|
|
|
|
if ($app->name == "core client") {
|
|
|
|
$app_version->exec_dir = "$source_dir/client";
|
|
|
|
} else {
|
|
|
|
$app_version->exec_dir = "$source_dir/apps";
|
|
|
|
}
|
|
|
|
}
|
2003-05-08 17:13:57 +00:00
|
|
|
if (sizeof($app_version->exec_names) == 0) {
|
2003-02-12 18:51:05 +00:00
|
|
|
if ($app->name == "core client") {
|
2003-05-08 17:13:57 +00:00
|
|
|
$app_version->exec_names[0] = sprintf("boinc_%s.%s_%s", get_env_var("BOINC_MAJOR_VERSION"), get_env_var("BOINC_MINOR_VERSION"), $app_version->platform->name);
|
2003-02-12 18:51:05 +00:00
|
|
|
} else {
|
2003-05-08 17:13:57 +00:00
|
|
|
$app_version->exec_names[0] = $app->name;
|
2003-02-12 18:51:05 +00:00
|
|
|
}
|
2002-11-09 20:26:50 +00:00
|
|
|
}
|
2003-02-12 18:51:05 +00:00
|
|
|
|
|
|
|
$p = $app_version->platform;
|
2003-05-08 17:13:57 +00:00
|
|
|
$x = "add app_version -db_name $this->db_name -app_name '$app->name' -platform_name $p->name -version $app_version->version -download_dir $this->project_dir/download -download_url $this->download_url -code_sign_keyfile $this->key_dir/code_sign_private -exec_dir $app_version->exec_dir -exec_files";
|
2003-05-10 00:52:36 +00:00
|
|
|
for ($j=0; $j<sizeof($app_version->exec_names); $j++) {
|
|
|
|
$x = $x." ".$app_version->exec_names[$j];
|
2003-05-08 17:13:57 +00:00
|
|
|
}
|
|
|
|
run_tool($x);
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
2002-12-02 04:29:40 +00:00
|
|
|
|
2002-11-22 22:10:13 +00:00
|
|
|
// copy the user and administrative PHP files to the project dir,
|
|
|
|
//
|
2003-02-24 21:31:36 +00:00
|
|
|
PassThru("cp -f $source_dir/html_user/* $this->project_dir/html_user >> /dev/null 2>&1");
|
|
|
|
PassThru("cp -f $source_dir/tools/country_select $this->project_dir/html_user >> /dev/null 2>&1");
|
|
|
|
PassThru("cp -f $source_dir/html_ops/* $this->project_dir/html_ops >> /dev/null 2>&1");
|
2003-02-12 23:06:49 +00:00
|
|
|
if ($this->project_php_file) {
|
|
|
|
PassThru("cp -f $source_dir/html_user/$this->project_php_file $this->project_dir/html_user/project.inc");
|
|
|
|
}
|
2003-02-24 21:31:36 +00:00
|
|
|
if ($this->project_prefs_php_file) {
|
|
|
|
PassThru("cp -f $source_dir/html_user/$this->project_prefs_php_file $this->project_dir/html_user/project_specific_prefs.inc");
|
|
|
|
}
|
2002-10-03 18:33:46 +00:00
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
// Copy the sched server in the cgi directory with the
|
|
|
|
// cgi names given $source_dir/html_usr/schedulers.txt
|
|
|
|
//
|
|
|
|
if ($scheduler_file == null) {
|
|
|
|
$scheduler_file = "schedulers.txt";
|
|
|
|
$f = fopen("$this->project_dir/html_user/schedulers.txt", "w");
|
|
|
|
fputs($f,"<scheduler>".$this->scheduler_url."</scheduler>\n");
|
|
|
|
fclose($f);
|
|
|
|
} else {
|
|
|
|
$f = fopen("$this->project_dir/html_user/$scheduler_file", "r");
|
2003-02-12 18:51:05 +00:00
|
|
|
while (true) {
|
2002-12-02 04:29:40 +00:00
|
|
|
$scheduler_url = fgets($f, 1000);
|
|
|
|
if($scheduler_url == false) break;
|
2003-02-12 18:51:05 +00:00
|
|
|
$temp = substr($scheduler_url, 0, strrpos($scheduler_url, '<'));
|
|
|
|
$cgi_name = substr($temp, strrpos($temp, '/')+1, strlen($temp) - strrpos($temp, '/'));
|
2002-12-02 04:29:40 +00:00
|
|
|
PassThru("cp $source_dir/sched/cgi $this->project_dir/cgi/$cgi_name");
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose($f);
|
|
|
|
}
|
2002-11-22 22:10:13 +00:00
|
|
|
|
2003-02-12 18:51:05 +00:00
|
|
|
// copy all the backend programs to the CGI directory
|
|
|
|
//
|
2002-10-03 18:33:46 +00:00
|
|
|
PassThru("cp $source_dir/sched/cgi $this->project_dir/cgi/");
|
|
|
|
PassThru("cp $source_dir/sched/file_upload_handler $this->project_dir/cgi/");
|
2002-10-09 04:56:41 +00:00
|
|
|
PassThru("cp $source_dir/sched/make_work $this->project_dir/cgi/");
|
2002-10-03 18:33:46 +00:00
|
|
|
PassThru("cp $source_dir/sched/feeder $this->project_dir/cgi/");
|
2003-03-12 21:37:50 +00:00
|
|
|
PassThru("cp $source_dir/sched/timeout_check $this->project_dir/cgi/");
|
2002-10-19 17:14:08 +00:00
|
|
|
PassThru("cp $source_dir/sched/validate_test $this->project_dir/cgi/");
|
2002-12-18 01:34:51 +00:00
|
|
|
PassThru("cp $source_dir/sched/file_deleter $this->project_dir/cgi/");
|
|
|
|
PassThru("cp $source_dir/sched/assimilator $this->project_dir/cgi/");
|
2003-02-12 18:51:05 +00:00
|
|
|
PassThru("cp $source_dir/sched/start_servers $this->project_dir/cgi/");
|
|
|
|
|
|
|
|
// write the server config file
|
|
|
|
//
|
2003-03-29 07:25:12 +00:00
|
|
|
$this->append_config("<config>\n" .
|
|
|
|
"<db_name>$this->db_name</db_name>\n" .
|
|
|
|
"<db_passwd>$this->db_passwd</db_passwd>\n" .
|
|
|
|
"<shmem_key>$this->shmem_key</shmem_key>\n" .
|
|
|
|
"<key_dir>$this->key_dir</key_dir>\n" .
|
|
|
|
"<download_url>$this->download_url</download_url>\n" .
|
|
|
|
"<download_dir>$this->project_dir/download</download_dir>\n" .
|
|
|
|
"<upload_url>$this->upload_url</upload_url>\n" .
|
|
|
|
"<upload_dir>$this->project_dir/upload</upload_dir>\n" .
|
|
|
|
"<user_name>$this->user_name</user_name>\n" .
|
|
|
|
"</config>\n");
|
2002-10-03 18:33:46 +00:00
|
|
|
|
2003-02-12 18:51:05 +00:00
|
|
|
// put a file with the database name and other info
|
|
|
|
// in each HTML directory
|
2002-10-03 18:33:46 +00:00
|
|
|
//
|
2003-03-26 01:03:11 +00:00
|
|
|
$f = fopen("$this->project_dir/html_user/.htconfig.xml", "w");
|
2002-11-09 20:26:50 +00:00
|
|
|
fputs($f, "<db_name>$this->db_name</db_name>\n");
|
|
|
|
fputs($f, "<db_passwd>$this->db_name</db_passwd>\n");
|
|
|
|
fputs($f, "<download_url>$this->download_url</download_url>\n");
|
2002-11-12 17:01:16 +00:00
|
|
|
fputs($f, "<cgi_url>$cgi_url</cgi_url>\n");
|
2002-10-03 18:33:46 +00:00
|
|
|
fclose($f);
|
2003-03-26 01:03:11 +00:00
|
|
|
PassThru("cp $this->project_dir/html_user/.htconfig.xml $this->project_dir/html_ops");
|
2002-10-03 18:33:46 +00:00
|
|
|
|
2003-02-12 18:51:05 +00:00
|
|
|
// edit "index.php" in the user HTML directory to have
|
|
|
|
// the right file as the source for scheduler_urls;
|
|
|
|
// default is schedulers.txt
|
|
|
|
//
|
2002-11-22 22:10:13 +00:00
|
|
|
$x = "sed -e s/FILE_NAME/$scheduler_file/ $this->project_dir/html_user/index.php > temp; mv temp $this->project_dir/html_user/index.php";
|
2002-12-02 04:29:40 +00:00
|
|
|
PassThru($x);
|
2002-10-03 18:33:46 +00:00
|
|
|
|
|
|
|
// create symbolic links to the CGI and HTML directories
|
|
|
|
//
|
|
|
|
$cgi_dir = get_env_var("BOINC_CGI_DIR");
|
|
|
|
$cgi_url = get_env_var("BOINC_CGI_URL");
|
|
|
|
$html_dir = get_env_var("BOINC_HTML_DIR");
|
|
|
|
$html_url = get_env_var("BOINC_HTML_URL");
|
2003-02-14 22:59:25 +00:00
|
|
|
PassThru("rm -f $cgi_dir/$this->short_name");
|
|
|
|
PassThru("ln -s $this->project_dir/cgi $cgi_dir/$this->short_name");
|
|
|
|
PassThru("rm -f $html_dir/$this->short_name");
|
|
|
|
PassThru("ln -s $this->project_dir/html_user $html_dir/$this->short_name");
|
|
|
|
$x = "ln -s $this->project_dir/html_ops ".$html_dir."/".$this->short_name."_admin";
|
2003-02-12 23:06:49 +00:00
|
|
|
PassThru($x);
|
2002-10-04 05:30:44 +00:00
|
|
|
|
|
|
|
// show the URLs for user and admin sites
|
|
|
|
//
|
2003-02-18 23:07:48 +00:00
|
|
|
echo "Master URL: $this->master_url\n";
|
|
|
|
$admin_url = $html_url."/".$this->short_name."_admin/index.php";
|
|
|
|
echo "Admin URL: $admin_url\n";
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
2002-11-16 00:35:53 +00:00
|
|
|
|
2003-02-25 19:25:53 +00:00
|
|
|
// Adds http password protection to the html_ops directory
|
|
|
|
//
|
|
|
|
function http_password($user,$password) {
|
|
|
|
$f = fopen($this->project_dir."/html_ops/.htaccess", "w");
|
|
|
|
fputs($f,"AuthName \"$this->long_name Administration\"\n");
|
|
|
|
fputs($f,"AuthType Basic\n");
|
|
|
|
fputs($f,"AuthUserFile $this->project_dir/html_ops/.htpasswd\n\n");
|
|
|
|
fputs($f,"require valid-user\n");
|
|
|
|
fclose($f);
|
|
|
|
|
|
|
|
PassThru("htpasswd -bc $this->project_dir/html_ops/.htpasswd $user $password");
|
|
|
|
}
|
2003-03-29 07:25:12 +00:00
|
|
|
|
2003-02-12 18:51:05 +00:00
|
|
|
// moves the master web page to temp
|
2002-12-02 04:29:40 +00:00
|
|
|
// This is used to test exponential backoff on the client side.
|
|
|
|
//
|
2002-12-24 03:03:45 +00:00
|
|
|
function delete_masterindex() {
|
2002-12-02 04:29:40 +00:00
|
|
|
PassThru("mv $this->project_dir/html_user/index.php $this->project_dir/html_user/temp");
|
|
|
|
}
|
2002-11-16 00:35:53 +00:00
|
|
|
|
2003-02-12 18:51:05 +00:00
|
|
|
// moves temp back to the master web page
|
2002-12-02 04:29:40 +00:00
|
|
|
// This is used to test exponential backoff on the client side.
|
|
|
|
//
|
2002-12-24 03:03:45 +00:00
|
|
|
function reestablish_masterindex() {
|
2002-12-02 04:29:40 +00:00
|
|
|
PassThru("mv $this->project_dir/html_user/temp $this->project_dir/html_user/index.php");
|
|
|
|
|
|
|
|
}
|
2002-11-16 00:35:53 +00:00
|
|
|
|
2003-02-12 18:51:05 +00:00
|
|
|
// delete the sched server for this project
|
2002-12-02 04:29:40 +00:00
|
|
|
// This is used to test exponential backoff on the client side.
|
|
|
|
//
|
2002-12-24 03:03:45 +00:00
|
|
|
function delete_scheduler($cgi_num = null) {
|
2002-12-02 04:29:40 +00:00
|
|
|
PassThru("rm $this->project_dir/cgi/cgi$cgi_num");
|
|
|
|
}
|
2002-11-16 00:35:53 +00:00
|
|
|
|
2003-02-12 18:51:05 +00:00
|
|
|
// copies the sched server back into the CGI directory.
|
2002-12-02 04:29:40 +00:00
|
|
|
// This is used to test exponential backoff on the client side.
|
|
|
|
//
|
2002-12-24 03:03:45 +00:00
|
|
|
function reinstall_scheduler($cgi_num=null) {
|
|
|
|
PassThru("cp $this->source_dir/sched/cgi $this->project_dir/cgi/cgi$cgi_num");
|
2002-12-02 04:29:40 +00:00
|
|
|
}
|
2002-11-16 00:35:53 +00:00
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
// moves the download directory to temp.
|
2002-12-24 03:03:45 +00:00
|
|
|
// This is used to test exponential backoff
|
2002-12-02 04:29:40 +00:00
|
|
|
//
|
2002-12-24 03:03:45 +00:00
|
|
|
function delete_downloaddir($download_dir_num = null) {
|
2002-12-02 04:29:40 +00:00
|
|
|
PassThru("mv $this->project_dir/download$download_dir_num $this->project_dir/download_moved$download_dir_num");
|
|
|
|
|
|
|
|
}
|
2002-11-16 00:35:53 +00:00
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
// reinstalls the download directory.
|
2002-12-24 03:03:45 +00:00
|
|
|
// This is used to test exponential backoff
|
2002-12-02 04:29:40 +00:00
|
|
|
//
|
2002-12-24 03:03:45 +00:00
|
|
|
function reinstall_downloaddir($download_dir_num = null) {
|
2002-12-02 04:29:40 +00:00
|
|
|
PassThru("mv $this->project_dir/download_moved$download_dir_num $this->project_dir/download$download_dir_num");
|
|
|
|
}
|
2002-11-22 22:10:13 +00:00
|
|
|
|
2002-12-24 03:03:45 +00:00
|
|
|
function remove_file_upload_handler($handler_num = null) {
|
2002-12-02 04:29:40 +00:00
|
|
|
PassThru("rm $this->project_dir/cgi/file_upload_handler$handler_num");
|
|
|
|
}
|
|
|
|
|
2002-12-24 03:03:45 +00:00
|
|
|
function reinstall_file_upload_handler($handler_num = null) {
|
|
|
|
PassThru("cp $this->source_dir/sched/file_upload_handler $this->project_dir/cgi/file_upload_handler$handler_num");
|
2002-12-02 04:29:40 +00:00
|
|
|
}
|
|
|
|
|
2003-03-29 07:25:12 +00:00
|
|
|
function start_servers() {
|
|
|
|
PassThru("cd $this->project_dir/cgi; ./start_servers >> start_servers.out 2>&1");
|
2003-02-12 23:06:49 +00:00
|
|
|
}
|
|
|
|
|
2003-03-29 07:25:12 +00:00
|
|
|
function install_feeder() {
|
|
|
|
$this->append_config("<start>./feeder -asynch >> feeder.out 2>&1</start>\n");
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-29 07:25:12 +00:00
|
|
|
function install_timeout_check($app, $nerror = 5,$ndet = 5, $nredundancy = 5){
|
|
|
|
$this->append_config("<start>./timeout_check -app $app->name -nerror $nerror -ndet $ndet -nredundancy $nredundancy -asynch >> timeout_check.out 2>&1</start>\n");
|
2002-12-18 01:02:01 +00:00
|
|
|
}
|
|
|
|
|
2003-03-29 07:25:12 +00:00
|
|
|
function install_make_work($work,$cushion,$redundancy){
|
2002-10-14 23:10:12 +00:00
|
|
|
$result_template_path = realpath($work->result_template);
|
2003-03-29 07:25:12 +00:00
|
|
|
$this->append_config("<start>./make_work -asynch -cushion $cushion -redundancy $redundancy -result_template $result_template_path -wu_name $work->wu_template >> make_work.out 2>&1</start>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function deinstall_make_work() {
|
|
|
|
$this->remove_config("make_work");
|
2002-10-09 04:56:41 +00:00
|
|
|
}
|
|
|
|
|
2002-12-03 18:57:40 +00:00
|
|
|
// run the validator asynchronously
|
|
|
|
//
|
2003-03-29 07:25:12 +00:00
|
|
|
function install_validate($app, $quorum) {
|
|
|
|
$this->append_config("<start>./validate_test -asynch -app $app->name -quorum $quorum >> validate.out 2>&1</start>\n");
|
2002-10-19 17:14:08 +00:00
|
|
|
}
|
|
|
|
|
2002-12-03 18:57:40 +00:00
|
|
|
// do one pass of validation
|
|
|
|
//
|
|
|
|
function validate($app, $quorum) {
|
2003-03-29 07:25:12 +00:00
|
|
|
PassThru("cd $this->project_dir/cgi; ./validate_test -one_pass -app $app->name -quorum $quorum >> validate.out 2>&1");
|
2002-12-03 18:57:40 +00:00
|
|
|
}
|
2002-12-19 01:01:20 +00:00
|
|
|
|
2003-03-29 07:25:12 +00:00
|
|
|
function install_file_delete(){
|
|
|
|
$this->append_config("<start>./file_deleter -asynch >> file_deleter.out 2>&1</start>\n");
|
2002-12-19 01:01:20 +00:00
|
|
|
}
|
|
|
|
|
2002-12-18 01:34:51 +00:00
|
|
|
// do one pass of file_deleter
|
|
|
|
//
|
|
|
|
function file_delete() {
|
2003-03-29 07:25:12 +00:00
|
|
|
PassThru("cd $this->project_dir/cgi; ./file_deleter -one_pass >> file_deleter.out 2>&1");
|
2002-12-18 01:34:51 +00:00
|
|
|
}
|
2002-12-19 01:01:20 +00:00
|
|
|
|
2003-03-29 07:25:12 +00:00
|
|
|
function install_assimilator($app) {
|
|
|
|
$this->append_config("<start>./assimilator -asynch -app $app->name >> assimilator.out 2>&1</start>\n");
|
2002-12-19 01:01:20 +00:00
|
|
|
}
|
|
|
|
|
2002-12-18 01:34:51 +00:00
|
|
|
// do one pass of assimilator
|
|
|
|
//
|
|
|
|
function assimilate($app) {
|
2003-03-29 07:25:12 +00:00
|
|
|
PassThru("cd $this->project_dir/cgi; ./assimilator -one_pass -app $app->name >> assimilator.out 2>&1");
|
2002-12-18 01:34:51 +00:00
|
|
|
}
|
|
|
|
|
2002-12-24 03:03:45 +00:00
|
|
|
// start collecting data for stripcharts
|
|
|
|
//
|
|
|
|
function start_stripchart() {
|
|
|
|
$source_dir = $this->source_dir;
|
|
|
|
PassThru("cp $source_dir/stripchart/stripchart.cgi $this->project_dir/cgi/");
|
|
|
|
PassThru("cp $source_dir/stripchart/stripchart $this->project_dir/cgi/");
|
|
|
|
PassThru("cp $source_dir/stripchart/stripchart.cnf $this->project_dir/cgi/");
|
2003-01-13 23:37:56 +00:00
|
|
|
PassThru("cp $source_dir/stripchart/samples/looper $this->project_dir/cgi/");
|
2003-01-23 08:07:48 +00:00
|
|
|
PassThru("cp $source_dir/stripchart/samples/db_looper $this->project_dir/cgi/");
|
2002-12-24 03:03:45 +00:00
|
|
|
PassThru("cp $source_dir/stripchart/samples/datafiles $this->project_dir/cgi/");
|
|
|
|
PassThru("cp $source_dir/stripchart/samples/get_load $this->project_dir/cgi/");
|
2003-01-23 08:07:48 +00:00
|
|
|
PassThru("cp $source_dir/stripchart/samples/dir_size $this->project_dir/cgi/");
|
|
|
|
macro_substitute("BOINC_DB_NAME", $this->db_name, "$source_dir/stripchart/samples/db_count", "$this->project_dir/cgi/db_count");
|
|
|
|
make_executable("$this->project_dir/cgi/db_count");
|
2003-01-13 23:37:56 +00:00
|
|
|
PassThru("cd $this->project_dir/cgi; looper get_load 1 > get_load_out &");
|
2003-01-23 08:07:48 +00:00
|
|
|
PassThru("cd $this->project_dir/cgi; db_looper 'result' 1 > count_results_out &");
|
|
|
|
PassThru("cd $this->project_dir/cgi; db_looper 'workunit where assimilate_state=2' 1 > assimilated_wus_out &");
|
|
|
|
PassThru("cd $this->project_dir/cgi; looper 'dir_size ../download' 1 > download_size_out &");
|
|
|
|
PassThru("cd $this->project_dir/cgi; looper 'dir_size ../upload' 1 > upload_size_out &");
|
2002-12-24 03:03:45 +00:00
|
|
|
}
|
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
// this should stop the feeder and any other daemons
|
|
|
|
//
|
2002-10-03 18:33:46 +00:00
|
|
|
function stop() {
|
2002-10-09 04:56:41 +00:00
|
|
|
$f = fopen($this->project_dir."/cgi/stop_server", "w");
|
2002-10-03 18:33:46 +00:00
|
|
|
fputs($f, "<quit/>\n");
|
|
|
|
fclose($f);
|
|
|
|
}
|
|
|
|
|
2003-03-29 07:25:12 +00:00
|
|
|
// append the line to the config file
|
|
|
|
function append_config($line) {
|
|
|
|
touch($this->project_dir."/cgi/.htconfig.xml");
|
|
|
|
$f_old = fopen($this->project_dir."/cgi/.htconfig.xml", "r");
|
|
|
|
$f_new = fopen($this->project_dir."/cgi/.htconfig.tmp", "w");
|
|
|
|
$appended = false;
|
|
|
|
while(!feof($f_old)) {
|
|
|
|
$in_line = fgets($f_old);
|
|
|
|
if (strstr($in_line, "</config>")) {
|
|
|
|
fputs($f_new, $line);
|
|
|
|
$appended = true;
|
|
|
|
}
|
|
|
|
fputs($f_new, $in_line);
|
|
|
|
}
|
|
|
|
if (!$appended) fputs($f_new, $line);
|
|
|
|
fclose($f_old);
|
|
|
|
fclose($f_new);
|
|
|
|
rename($this->project_dir."/cgi/.htconfig.tmp", $this->project_dir."/cgi/.htconfig.xml");
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove any line containing the pattern from the config file
|
|
|
|
function remove_config($pattern) {
|
|
|
|
touch($this->project_dir."/cgi/.htconfig.xml");
|
|
|
|
$f_old = fopen($this->project_dir."/cgi/.htconfig.xml", "r");
|
|
|
|
$f_new = fopen($this->project_dir."/cgi/.htconfig.tmp", "w");
|
|
|
|
while(!feof($f_old)) {
|
|
|
|
$in_line = fgets($f_old);
|
|
|
|
if (!strstr($in_line, $pattern))
|
|
|
|
fputs($f_new, $in_line);
|
|
|
|
}
|
|
|
|
fclose($f_old);
|
|
|
|
fclose($f_new);
|
|
|
|
rename($this->project_dir."/cgi/.htconfig.tmp", $this->project_dir."/cgi/.htconfig.xml");
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the stop_server trigger
|
|
|
|
//
|
|
|
|
function restart() {
|
|
|
|
unlink($this->project_dir."/cgi/stop_server");
|
|
|
|
}
|
|
|
|
|
2002-10-06 00:43:55 +00:00
|
|
|
function check_results($ntarget, $result) {
|
|
|
|
$n = 0;
|
2002-10-03 18:33:46 +00:00
|
|
|
db_open($this->db_name);
|
2002-10-06 00:43:55 +00:00
|
|
|
$result = mysql_query("select * from result");
|
2002-10-03 18:33:46 +00:00
|
|
|
while ($x = mysql_fetch_object($result)) {
|
2002-10-06 00:43:55 +00:00
|
|
|
$n++;
|
2003-04-01 07:34:08 +00:00
|
|
|
if ($result->server_state != null && $result->server_state != $x->server_state) {
|
|
|
|
echo "ERROR: result $x->id: unexpected state $x->server_state\n";
|
2002-10-06 00:43:55 +00:00
|
|
|
}
|
|
|
|
if ($result->stderr_out != null) {
|
|
|
|
if (substr($result->stderr_out, $x->stderr_out)==0) {
|
|
|
|
echo "ERROR: result $x->id: unexpected stderr_out $x->stderr_out\n";
|
|
|
|
}
|
|
|
|
}
|
2002-11-09 20:26:50 +00:00
|
|
|
if ($result->exit_state != null && $result->exit_status != $x->exit_status) {
|
|
|
|
echo "ERROR: result $x->id: unexpected exit_status $x->exit_status\n";
|
2002-10-06 00:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($n != $ntarget) {
|
|
|
|
echo "ERROR: expected $ntarget results, found $n.\n";
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-10 21:45:08 +00:00
|
|
|
function num_wus_left() {
|
|
|
|
db_open($this->db_name);
|
2003-03-29 07:25:12 +00:00
|
|
|
$result = mysql_query("select count(*) as cnt from result where server_state=2");
|
2002-10-10 21:45:08 +00:00
|
|
|
$count = mysql_fetch_object($result);
|
|
|
|
return $count->cnt;
|
|
|
|
}
|
|
|
|
|
2002-10-04 05:30:44 +00:00
|
|
|
function num_results_done() {
|
|
|
|
db_open($this->db_name);
|
2003-03-29 07:25:12 +00:00
|
|
|
$result = mysql_query("select count(*) as cnt from result where server_state=4");
|
2002-10-10 21:45:08 +00:00
|
|
|
$count = mysql_fetch_object($result);
|
|
|
|
return $count->cnt;
|
2002-10-04 05:30:44 +00:00
|
|
|
}
|
|
|
|
|
2002-10-03 18:33:46 +00:00
|
|
|
function compare_file($result, $correct) {
|
|
|
|
PassThru("diff $this->project_dir/upload/$result $correct", $retval);
|
|
|
|
if ($retval) {
|
2003-01-07 01:02:08 +00:00
|
|
|
echo "File mismatch: $result $correct\n";
|
2002-10-03 18:33:46 +00:00
|
|
|
} else {
|
2003-01-07 01:02:08 +00:00
|
|
|
echo "Files match: $result $correct\n";
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-21 01:38:16 +00:00
|
|
|
// represents an account on a particular project
|
|
|
|
//
|
2002-10-03 18:33:46 +00:00
|
|
|
class User {
|
|
|
|
var $name;
|
2002-10-03 20:41:23 +00:00
|
|
|
var $email_addr;
|
2002-10-03 18:33:46 +00:00
|
|
|
var $authenticator;
|
2003-02-21 01:38:16 +00:00
|
|
|
var $project_prefs;
|
|
|
|
var $project;
|
2002-10-03 18:33:46 +00:00
|
|
|
|
|
|
|
function User() {
|
|
|
|
$this->name = "John";
|
|
|
|
$this->email_addr = "john@boinc.org";
|
|
|
|
$this->authenticator = "3f7b90793a0175ad0bda68684e8bd136";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Host {
|
|
|
|
var $name;
|
2003-02-21 01:38:16 +00:00
|
|
|
var $users;
|
2002-10-03 18:33:46 +00:00
|
|
|
var $projects;
|
|
|
|
var $host_dir;
|
2002-10-04 00:16:41 +00:00
|
|
|
var $global_prefs;
|
|
|
|
var $log_flags;
|
2002-10-03 18:33:46 +00:00
|
|
|
|
2003-02-21 01:38:16 +00:00
|
|
|
function Host() {
|
2002-10-03 18:33:46 +00:00
|
|
|
$this->name = "test";
|
2003-02-21 01:38:16 +00:00
|
|
|
$this->users = array();
|
2002-10-03 18:33:46 +00:00
|
|
|
$this->projects = array();
|
2002-10-04 00:16:41 +00:00
|
|
|
$this->global_prefs = null;
|
|
|
|
$this->log_flags = null;
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
|
|
|
|
2003-02-21 01:38:16 +00:00
|
|
|
function add_user($user, $project) {
|
|
|
|
array_push($this->users, $user);
|
2002-10-03 18:33:46 +00:00
|
|
|
array_push($this->projects, $project);
|
|
|
|
}
|
|
|
|
|
|
|
|
function install() {
|
|
|
|
$base_dir = get_env_var("BOINC_HOSTS_DIR");
|
|
|
|
$this->host_dir = $base_dir."/".$this->name;
|
|
|
|
PassThru("rm -rf $this->host_dir");
|
|
|
|
PassThru("mkdir $this->host_dir");
|
|
|
|
|
|
|
|
// create account files
|
|
|
|
//
|
|
|
|
echo "creating account files\n";
|
2003-02-21 01:38:16 +00:00
|
|
|
for ($i=0; $i<sizeof($this->users); $i++) {
|
|
|
|
$user = $this->users[$i];
|
2002-10-03 18:33:46 +00:00
|
|
|
$project = $this->projects[$i];
|
2003-02-21 01:38:16 +00:00
|
|
|
$filename = account_file_name($project->master_url);
|
|
|
|
echo "writing $this->host_dir/$filename\n";
|
|
|
|
$f = fopen($this->host_dir."/".$filename, "w");
|
2002-10-03 18:33:46 +00:00
|
|
|
fputs($f, "<account>\n");
|
|
|
|
fputs($f, " <master_url>$project->master_url</master_url>\n");
|
|
|
|
fputs($f, " <authenticator>$user->authenticator</authenticator>\n");
|
2003-02-21 01:38:16 +00:00
|
|
|
fputs($f, $user->project_prefs);
|
2002-10-03 18:33:46 +00:00
|
|
|
fputs($f, "</account>\n");
|
|
|
|
fclose($f);
|
|
|
|
}
|
|
|
|
|
2002-10-04 00:16:41 +00:00
|
|
|
// copy log flags, if any
|
2002-10-03 18:33:46 +00:00
|
|
|
//
|
2002-10-04 00:16:41 +00:00
|
|
|
if ($this->log_flags != null) {
|
|
|
|
PassThru("cp $this->log_flags $this->host_dir/log_flags.xml");
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy global prefs, if any
|
|
|
|
//
|
|
|
|
if ($this->global_prefs != null) {
|
|
|
|
PassThru("cp $this->global_prefs.xml $this->host_dir/global_prefs.xml");
|
|
|
|
}
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
2002-11-08 23:53:56 +00:00
|
|
|
|
2003-02-21 01:38:16 +00:00
|
|
|
function kill($boinc_pid) {
|
|
|
|
if ($boinc_pid) {
|
|
|
|
PassThru("kill -9 $boinc_pid");
|
2002-12-02 04:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// forks a new process to run this host with the given $args.
|
|
|
|
// the pid returned is the pid of the newly forked php process.
|
|
|
|
// NOTE: to kill the newly started host,
|
|
|
|
// get_new_boincpid() must be called and kill() must be called on it.
|
|
|
|
//
|
2002-11-08 23:53:56 +00:00
|
|
|
function run_asynch($args) {
|
2002-12-02 04:29:40 +00:00
|
|
|
$pid = pcntl_fork();
|
|
|
|
if ($pid == -1) {
|
|
|
|
return -1;
|
|
|
|
} else if ($pid) {
|
|
|
|
return $pid; // we are the parent
|
|
|
|
} else { //we are the child
|
|
|
|
echo "\nRunning core client asynch\n";
|
|
|
|
$source_dir = get_env_var("BOINC_SRC_DIR");
|
|
|
|
$platform = get_env_var("BOINC_PLATFORM");
|
|
|
|
$exec_name = sprintf("boinc_%s.%s_%s", get_env_var("BOINC_MAJOR_VERSION"), get_env_var("BOINC_MINOR_VERSION"), $platform);
|
|
|
|
PassThru("cd $this->host_dir; $source_dir/client/$exec_name $args > client.out");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//returns a pid for a boinc process running in the system
|
|
|
|
// that is different from $client_pid.
|
|
|
|
// This call blocks until such process is started.
|
|
|
|
//
|
|
|
|
function get_new_client_pid($client_pid) {
|
|
|
|
while(true) {
|
|
|
|
$pid = exec("pgrep -n boinc");
|
|
|
|
if(($pid != null) && ($pid != $client_pid)) {
|
|
|
|
return $pid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-13 23:37:56 +00:00
|
|
|
function run($args=null) {
|
2002-12-02 04:29:40 +00:00
|
|
|
echo "\nRunning core client\n";
|
|
|
|
$source_dir = get_env_var("BOINC_SRC_DIR");
|
|
|
|
$platform = get_env_var("BOINC_PLATFORM");
|
|
|
|
$exec_name = sprintf("boinc_%s.%s_%s", get_env_var("BOINC_MAJOR_VERSION"), get_env_var("BOINC_MINOR_VERSION"), $platform);
|
|
|
|
PassThru("cd $this->host_dir; $source_dir/client/$exec_name $args > client.out");
|
|
|
|
}
|
|
|
|
|
2002-10-04 05:30:44 +00:00
|
|
|
// read a CPU time file written by the client.
|
|
|
|
// This is sort of a kludge.
|
|
|
|
//
|
|
|
|
function read_cpu_time_file($file_name) {
|
2002-12-02 04:29:40 +00:00
|
|
|
$time_file = fopen($this->host_dir/$file_name, "r");
|
2002-10-04 05:30:44 +00:00
|
|
|
if($time_file == NULL) return 0;
|
|
|
|
fscanf($time_file, "%f", $app_time);
|
|
|
|
fclose($f);
|
|
|
|
return $app_time;
|
|
|
|
}
|
|
|
|
|
2002-10-06 00:43:55 +00:00
|
|
|
function check_file_present($project, $filename) {
|
2003-04-01 07:34:08 +00:00
|
|
|
$enc_url = str_replace("http://", "", $project->master_url);
|
|
|
|
$enc_url = str_replace("/", "_", $enc_url);
|
2002-10-06 00:43:55 +00:00
|
|
|
$path= "$this->host_dir/projects/$enc_url/$filename";
|
|
|
|
if (!file_exists($path)) {
|
|
|
|
echo "ERROR: file $path doesn't exist\n";
|
|
|
|
}
|
|
|
|
}
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Work {
|
|
|
|
var $app;
|
|
|
|
var $wu_template;
|
|
|
|
var $result_template;
|
2002-12-05 19:13:06 +00:00
|
|
|
var $redundancy;
|
2002-10-03 18:33:46 +00:00
|
|
|
var $input_files;
|
2002-10-04 05:30:44 +00:00
|
|
|
var $rsc_iops;
|
|
|
|
var $rsc_fpops;
|
|
|
|
var $rsc_disk;
|
2002-11-07 19:31:34 +00:00
|
|
|
var $delay_bound;
|
2002-12-02 04:29:40 +00:00
|
|
|
|
2002-10-04 00:16:41 +00:00
|
|
|
function Work($app) {
|
2002-10-03 18:33:46 +00:00
|
|
|
$this->app = $app;
|
|
|
|
$this->input_files = array();
|
2003-02-13 22:48:15 +00:00
|
|
|
$this->rsc_iops = 1.8e12;
|
|
|
|
$this->rsc_fpops = 1e13;
|
|
|
|
$this->rsc_disk = 1e6;
|
2002-11-07 19:31:34 +00:00
|
|
|
$this->delay_bound = 1000;
|
2002-12-05 19:13:06 +00:00
|
|
|
$this->redundancy = 1;
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
|
|
|
|
2002-10-04 00:16:41 +00:00
|
|
|
function install($project) {
|
2002-10-03 18:33:46 +00:00
|
|
|
$app = $this->app;
|
|
|
|
for ($i=0; $i<sizeof($this->input_files); $i++) {
|
|
|
|
$x = $this->input_files[$i];
|
|
|
|
PassThru("cp $x $project->project_dir/download");
|
|
|
|
}
|
2002-12-03 18:57:40 +00:00
|
|
|
|
2002-12-24 03:03:45 +00:00
|
|
|
// simulate multiple data servers by making symbolic links
|
|
|
|
// to the download directory
|
|
|
|
//
|
2002-12-02 04:29:40 +00:00
|
|
|
$f = fopen($this->wu_template,"r");
|
|
|
|
while(true) {
|
|
|
|
$temp = fgets($f,1000);
|
|
|
|
if($temp == false) break;
|
|
|
|
$temp = stristr($temp,"<DOWNLOAD_URL/>");
|
|
|
|
if($temp) {
|
|
|
|
$pos = strpos($temp,">");
|
|
|
|
if($temp[$pos + 2] != "<") {
|
|
|
|
$append = substr($temp, $pos+1,strpos($temp,"/<") - $pos -1);
|
|
|
|
}
|
|
|
|
PassThru("ln -s $project->project_dir/download $project->project_dir/download$append");
|
2002-12-03 18:57:40 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-02 04:29:40 +00:00
|
|
|
|
2002-12-24 03:03:45 +00:00
|
|
|
// simulate multiple data servers by making copies of
|
|
|
|
// the file upload handler
|
|
|
|
//
|
2002-12-02 04:29:40 +00:00
|
|
|
fclose($f);
|
|
|
|
$source_dir = get_env_var("BOINC_SRC_DIR");
|
|
|
|
$append = null;
|
|
|
|
$f = fopen($this->result_template,"r");
|
|
|
|
while(true) {
|
|
|
|
$temp = fgets($f,1000);
|
|
|
|
if($temp == false) break;
|
|
|
|
$temp = stristr($temp,"<url>");
|
|
|
|
if($temp) {
|
|
|
|
$upload_url = strip_tags($temp,"<UPLOAD_URL/>");
|
|
|
|
|
|
|
|
if(strip_tags($upload_url)) {
|
|
|
|
$append = strip_tags($upload_url);
|
|
|
|
|
|
|
|
PassThru("cp $source_dir/sched/file_upload_handler $project->project_dir/cgi/file_upload_handler$append");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($f);
|
2002-12-24 03:03:45 +00:00
|
|
|
|
2003-02-13 22:48:15 +00:00
|
|
|
$cmd = "create_work -db_name $project->db_name -download_dir $project->project_dir/download -upload_url $project->upload_url -download_url $project->download_url -keyfile $project->key_dir/upload_private -appname $app->name -rsc_iops $this->rsc_iops -rsc_fpops $this->rsc_fpops -rsc_disk $this->rsc_disk -wu_template $this->wu_template -result_template $this->result_template -redundancy $this->redundancy -wu_name $this->wu_template -delay_bound $this->delay_bound";
|
2002-12-03 18:57:40 +00:00
|
|
|
|
2002-10-03 18:33:46 +00:00
|
|
|
for ($i=0; $i<sizeof($this->input_files); $i++) {
|
|
|
|
$x = $this->input_files[$i];
|
|
|
|
$cmd = $cmd." ".$x;
|
|
|
|
}
|
|
|
|
run_tool($cmd);
|
|
|
|
}
|
|
|
|
}
|