CC-5802: Upgrade application.ini file
Used a transaction for upgrades. If upgrading the application.ini file fails, the database upgrades will get rolled back.
This commit is contained in:
parent
42f3bb17e1
commit
6890dcc3bc
|
@ -16,81 +16,88 @@ class UpgradeController extends Zend_Controller_Action
|
||||||
if (!$this->verifyAirtimeVersion()) {
|
if (!$this->verifyAirtimeVersion()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Disable Airtime UI
|
|
||||||
//create a temporary maintenance notification file
|
|
||||||
//when this file is on the server, zend framework redirects all
|
|
||||||
//requests to the maintenance page and sets a 503 response code
|
|
||||||
$maintenanceFile = '/tmp/maintenance.txt';
|
|
||||||
$file = fopen($maintenanceFile, 'w');
|
|
||||||
fclose($file);
|
|
||||||
|
|
||||||
//Begin upgrade
|
|
||||||
$filename = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf";
|
|
||||||
$values = parse_ini_file($filename, true);
|
|
||||||
|
|
||||||
$username = $values['database']['dbuser'];
|
|
||||||
$password = $values['database']['dbpass'];
|
|
||||||
$host = $values['database']['host'];
|
|
||||||
$database = $values['database']['dbname'];
|
|
||||||
$dir = __DIR__;
|
|
||||||
|
|
||||||
passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_$airtime_upgrade_version/upgrade.sql $database 2>&1 | grep -v \"will create implicit index\"");
|
|
||||||
|
|
||||||
$musicDir = CcMusicDirsQuery::create()
|
|
||||||
->filterByType('stor')
|
|
||||||
->filterByExists(true)
|
|
||||||
->findOne();
|
|
||||||
$storPath = $musicDir->getDirectory();
|
|
||||||
|
|
||||||
$freeSpace = disk_free_space($storPath);
|
|
||||||
$totalSpace = disk_total_space($storPath);
|
|
||||||
|
|
||||||
Application_Model_Preference::setDiskUsage($totalSpace - $freeSpace);
|
|
||||||
|
|
||||||
$iniFile = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."application.ini" : "/usr/share/airtime/application/configs/application.ini";
|
$con = Propel::getConnection();
|
||||||
|
$con->beginTransaction();
|
||||||
//update application.ini
|
try {
|
||||||
$newLines = "resources.frontController.moduleDirectory = APPLICATION_PATH '/modules'\n".
|
//Disable Airtime UI
|
||||||
"resources.frontController.plugins.putHandler = 'Zend_Controller_Plugin_PutHandler'\n".
|
//create a temporary maintenance notification file
|
||||||
";load everything in the modules directory including models\n".
|
//when this file is on the server, zend framework redirects all
|
||||||
"resources.modules[] = ''\n";
|
//requests to the maintenance page and sets a 503 response code
|
||||||
|
$maintenanceFile = '/tmp/maintenance.txt';
|
||||||
|
$file = fopen($maintenanceFile, 'w');
|
||||||
|
fclose($file);
|
||||||
|
|
||||||
|
//Begin upgrade
|
||||||
|
$filename = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf";
|
||||||
|
$values = parse_ini_file($filename, true);
|
||||||
|
|
||||||
|
$username = $values['database']['dbuser'];
|
||||||
|
$password = $values['database']['dbpass'];
|
||||||
|
$host = $values['database']['host'];
|
||||||
|
$database = $values['database']['dbname'];
|
||||||
|
$dir = __DIR__;
|
||||||
|
|
||||||
|
passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_$airtime_upgrade_version/upgrade.sql $database 2>&1 | grep -v \"will create implicit index\"");
|
||||||
|
|
||||||
|
$musicDir = CcMusicDirsQuery::create()
|
||||||
|
->filterByType('stor')
|
||||||
|
->filterByExists(true)
|
||||||
|
->findOne();
|
||||||
|
$storPath = $musicDir->getDirectory();
|
||||||
|
|
||||||
|
$freeSpace = disk_free_space($storPath);
|
||||||
|
$totalSpace = disk_total_space($storPath);
|
||||||
|
|
||||||
|
Application_Model_Preference::setDiskUsage($totalSpace - $freeSpace);
|
||||||
|
|
||||||
|
$iniFile = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."application.ini" : "/usr/share/airtime/application/configs/application.ini";
|
||||||
|
|
||||||
|
//update application.ini
|
||||||
|
$newLines = "resources.frontController.moduleDirectory = APPLICATION_PATH '/modules'\n".
|
||||||
|
"resources.frontController.plugins.putHandler = 'Zend_Controller_Plugin_PutHandler'\n".
|
||||||
|
";load everything in the modules directory including models\n".
|
||||||
|
"resources.modules[] = ''\n";
|
||||||
|
|
||||||
|
$currentIniFile = file_get_contents($iniFile);
|
||||||
|
|
||||||
|
/* We want to add the new lines immediately after the first line, '[production]'
|
||||||
|
* We read the first line into $beginning, and the rest of the file into $end.
|
||||||
|
* Then overwrite the current application.ini file with $beginning, $newLines, and $end
|
||||||
|
*/
|
||||||
|
$lines = explode("\n", $currentIniFile);
|
||||||
|
$beginning = implode("\n", array_slice($lines, 0,1));
|
||||||
|
|
||||||
|
//check that first line is '[production]'
|
||||||
|
if ($beginning != '[production]') {
|
||||||
|
throw new Exception('Upgrade to Airtime 2.5.3 FAILED. Could not upgrade application.ini - Invalid format');
|
||||||
|
}
|
||||||
|
$end = implode("\n", array_slice($lines, 1));
|
||||||
|
|
||||||
|
if (!is_writeable($iniFile)) {
|
||||||
|
throw new Exception('Upgrade to Airtime 2.5.3 FAILED. Could not upgrade application.ini - Permission denied.');
|
||||||
|
}
|
||||||
|
$file = new SplFileObject($iniFile, "w");
|
||||||
|
$file->fwrite($beginning."\n".$newLines.$end);
|
||||||
|
|
||||||
|
//delete maintenance.txt to give users access back to Airtime
|
||||||
|
unlink($maintenanceFile);
|
||||||
|
|
||||||
|
//TODO: clear out the cache
|
||||||
|
|
||||||
$currentIniFile = file_get_contents($iniFile);
|
$con->commit();
|
||||||
|
|
||||||
/* We want to add the new lines immediately after the first line, '[production]'
|
$this->getResponse()
|
||||||
* We read the first line into $beginning, and the rest of the file into $end.
|
->setHttpResponseCode(200)
|
||||||
* Then overwrite the current application.ini file with $beginning, $newLines, and $end
|
->appendBody("Upgrade to Airtime 2.5.3 OK");
|
||||||
*/
|
|
||||||
$lines = explode("\n", $currentIniFile);
|
|
||||||
$beginning = implode("\n", array_slice($lines, 0,1));
|
|
||||||
|
|
||||||
//check that first line is '[production]'
|
} catch(Exception $e) {
|
||||||
if ($beginning != '[production]') {
|
$con->rollback();
|
||||||
|
unlink($maintenanceFile);
|
||||||
$this->getResponse()
|
$this->getResponse()
|
||||||
->setHttpResponseCode(400)
|
->setHttpResponseCode(400)
|
||||||
->appendBody('Upgrade to Airtime 2.5.3 FAILED. Could not upgrade application.ini');
|
->appendBody($e->getMessage());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
$end = implode("\n", array_slice($lines, 1));
|
|
||||||
|
|
||||||
if (!is_writeable($iniFile)) {
|
|
||||||
$this->getResponse()
|
|
||||||
->setHttpResponseCode(400)
|
|
||||||
->appendBody('Upgrade to Airtime 2.5.3 FAILED. Could not upgrade application.ini');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$file = new SplFileObject($iniFile, "w");
|
|
||||||
$file->fwrite($beginning."\n".$newLines.$end);
|
|
||||||
|
|
||||||
//delete maintenance.txt to give users access back to Airtime
|
|
||||||
unlink($maintenanceFile);
|
|
||||||
|
|
||||||
//TODO: clear out the cache
|
|
||||||
|
|
||||||
$this->getResponse()
|
|
||||||
->setHttpResponseCode(200)
|
|
||||||
->appendBody("Upgrade to Airtime 2.5.3 OK");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function verifyAuth()
|
private function verifyAuth()
|
||||||
|
|
Loading…
Reference in New Issue