|
From: <tr...@us...> - 2003-02-16 02:04:20
|
Update of /cvsroot/basedb/basedb/bin
In directory sc8-pr-cvs1:/tmp/cvs-serv9956/bin
Modified Files:
baseftpd.php checkDatabase.php jobController.php startBase.php
stopBase.php
Log Message:
rewrote BaseControl to be much more robust and optionally use flock()
Index: baseftpd.php
===================================================================
RCS file: /cvsroot/basedb/basedb/bin/baseftpd.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** baseftpd.php 4 Feb 2003 18:22:50 -0000 1.2
--- baseftpd.php 16 Feb 2003 02:03:46 -0000 1.3
***************
*** 39,52 ****
$BC = new BaseControl();
- if(!$BC->mayRun())
- die("421 BASE has been shut down\n");
! // Open database connection
! if(!db_connect($config["dbHost"], $config["dbUser"],
! $config["dbPassword"], $config["dbDatabase"]))
{
! die("421 Unable to connect to database\n");
}
- unset($config["dbPassword"]);
$ftpd = new ftpd($_SERVER["argv"][1], $_SERVER["argv"][2]);
--- 39,53 ----
$BC = new BaseControl();
! $start = $BC->startScript();
! if($start == -1)
! die("421 Failed to connect to the database.\r\n");
! else if($start < 0)
! die("421 Internal error in BASE startup\r\n");
! else if(!$start)
{
! die("421 BASE has been shut down: ".
! printable($BC->shutdownMessage())."\r\n");
}
$ftpd = new ftpd($_SERVER["argv"][1], $_SERVER["argv"][2]);
***************
*** 54,60 ****
--- 55,74 ----
while(!feof(STDIN))
{
+ $BC->endScript();
+
$line = rtrim(fgets(STDIN));
if($line == "")
continue;
+
+ $start = $BC->startScript();
+ if($start == -1)
+ die("421 Failed to connect to the database.\r\n");
+ else if($start < 0)
+ die("421 Internal error in BASE startup\r\n");
+ else if(!$start)
+ {
+ die("421 BASE has been shut down: ".
+ printable($BC->shutdownMessage())."\r\n");
+ }
$ftpd->dispatch($line);
Index: checkDatabase.php
===================================================================
RCS file: /cvsroot/basedb/basedb/bin/checkDatabase.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** checkDatabase.php 1 Feb 2003 12:52:50 -0000 1.1
--- checkDatabase.php 16 Feb 2003 02:03:47 -0000 1.2
***************
*** 41,65 ****
$BC = new BaseControl();
! if($BC->mayRun())
! {
! mydie("Error: BASE needs to be shut down for this script to work ".
! "properly.\n");
! }
!
! // Open database connection
! echo "Connecting to database...\n";
! if(!db_connect($config["dbHost"], $config["dbUser"],
! $config["dbPassword"], $config["dbDatabase"]))
{
! mydie("Unable to connect to $config[RDBMS].\n");
}
! unset($config["dbPassword"]);
- if(!$BC->testShutdown())
- {
- mydie("BASE is not fully shut down, but it has to be for this\n".
- "script to work properly.\n");
- }
echo "Processing users and groups...\n";
--- 41,59 ----
$BC = new BaseControl();
! $start = $BC->startScript(true);
! if($start == -1)
! mydie("Failed to connect to the database.\n");
! if($start == -2)
{
! mydie("Error: BASE needs to be shut down first.\n");
}
! else if($start < 0)
! mydie("Internal error in BASE startup.\n");
! else if(!$start)
! mydie("Error: Shutdown hasn't take effect yet.\n");
+ if($config["RDBMS"] != "mysql")
+ mydie("This script only supports MySQL databases for now.\n");
echo "Processing users and groups...\n";
Index: jobController.php
===================================================================
RCS file: /cvsroot/basedb/basedb/bin/jobController.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** jobController.php 1 Feb 2003 12:52:50 -0000 1.1
--- jobController.php 16 Feb 2003 02:03:47 -0000 1.2
***************
*** 37,50 ****
$BC = new BaseControl();
! if(!$BC->mayRun())
die("BASE has been shut down\n");
-
- // Open database connection
- if(!db_connect($config["dbHost"], $config["dbUser"],
- $config["dbPassword"], $config["dbDatabase"]))
- {
- die("Unable to connect to database\n");
- }
- unset($config["dbPassword"]);
$job = new Job();
--- 37,47 ----
$BC = new BaseControl();
! $start = $BC->startScript();
! if($start == -1)
! die("Failed to connect to the database.\n");
! else if($start < 0)
! die("Internal error in BASE startup.\n");
! else if(!$start)
die("BASE has been shut down\n");
$job = new Job();
Index: startBase.php
===================================================================
RCS file: /cvsroot/basedb/basedb/bin/startBase.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** startBase.php 13 Feb 2003 12:23:56 -0000 1.4
--- startBase.php 16 Feb 2003 02:03:47 -0000 1.5
***************
*** 36,44 ****
if(!verifySetup())
! {
! if($BC->mayRun())
! mydie("\nBASE is running but misconfigured\n");
! mydie("\nBASE has not been started\n");
! }
if(!restartBase())
--- 36,40 ----
if(!verifySetup())
! return 1;
if(!restartBase())
***************
*** 55,81 ****
global $config, $BC;
! if($BC->mayRun())
! {
! mydie("BASE is already running. If you did an unclean shutdown ".
! "of BASE\n".
! "(without using stopBase.php), you may want to run ".
! "checkDatabase.php\n");
! }
!
! // Open database connection
! if(!db_connect($config["dbHost"], $config["dbUser"],
! $config["dbPassword"], $config["dbDatabase"]))
{
! mydie("Unable to connect to $config[RDBMS].\n");
}
! unset($config["dbPassword"]);
!
! $state = $BC->getState();
! if($state && $state["pendingTransactions"])
{
! mydie("There are pending transactions according to the database.\n".
! "The stopBase.php script may provide more information, or you\n".
! "can just update the row in table BaseControl after verifying\n".
! "that it's incorrect.\n");
}
--- 51,77 ----
global $config, $BC;
! $start = $BC->startScript(true);
! if($start == -1)
! mydie("BASE cannot be started: unable to connect to the database\n");
! else if($start == -2)
{
! if($config["useFlock"])
! mydie("BASE is already running.\n");
! mydie("BASE is already running. If it claims otherwise, check the\n".
! "BaseControl table as described in the documentation.\n");
}
! else if($start < 0)
! mydie("BASE cannot be started: early startup failed ($start)\n");
! else if(!$start)
{
! if($config["useFlock"])
! {
! mydie("BASE cannot be started: a maintenance script seems to ".
! "be running.\n");
! }
! mydie("BASE cannot be started: a maintenance script seems to ".
! "be running,\n".
! "or the pendingTransactions counter in the BaseControl table ".
! "has been\ncorrupted.\n");
}
***************
*** 133,137 ****
fwrite(STDERR, "Error: The database schema version is $sv,\n".
"but this version of BASE requires schema version 1.2.3\n".
! "Use the migration scripts in bin to correct this.\n");
return 0;
}
--- 129,133 ----
fwrite(STDERR, "Error: The database schema version is $sv,\n".
"but this version of BASE requires schema version 1.2.3\n".
! "Use the migration scripts in 'bin' to correct this.\n");
return 0;
}
Index: stopBase.php
===================================================================
RCS file: /cvsroot/basedb/basedb/bin/stopBase.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** stopBase.php 15 Feb 2003 12:37:38 -0000 1.4
--- stopBase.php 16 Feb 2003 02:03:47 -0000 1.5
***************
*** 33,95 ****
mydie("Usage: ".$_SERVER["argv"][0]." \"message\"\n");
return shutdownBase($_SERVER["argv"][1]) ? 0 : 1;
function shutdownBase($msg)
{
! global $config;
!
! $BC = new BaseControl();
!
[...127 lines suppressed...]
if(!$down)
{
! if($config["useFlock"])
! {
! mydie("Timed out after $maxwait minutes.\n".
! "Manual intervention may be needed to restore referential\n".
! "integrity, if the running script(s) are killed\n");
! }
! else
! {
! mydie("Timed out after $maxwait minutes.\n".
! "Manual intervention may be needed to restore referential\n".
! "integrity. There may be running scripts which could\n".
! "leave things in an undefined state if killed, or the\n".
! "BaseControl table's pendingTransaction column holds the\n".
! "wrong value because of crashed scripts or a previous\n".
! "unclean shutdown.\n");
! }
}
echo "BASE was successfully shut down.\n";
|