Skip to content

Commit 039b461

Browse files
author
vogelor
committed
rescue-module: now rescue of mysql works fine, even if the admin wanted to NOT rescue mysql
1 parent 849624a commit 039b461

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

interface/web/admin/templates/server_config_rescue_edit.htm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ <h2><tmpl_var name="list_head_txt"></h2>
3030
</div>
3131
</div>
3232
</fieldset>
33+
34+
Information: If you want to shut down mysql you have to disable "rescue mysql" and then wait 2-3 minutes.<br>
35+
if you do not wait 2-3 minutes, rescue will try to restart mysql!
3336

3437
<input type="hidden" name="id" value="{tmpl_var name='id'}">
3538

server/lib/classes/monitor_tools.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ public function monitorServices() {
519519
$server_id = intval($conf['server_id']);
520520

521521
/** get the "active" Services of the server from the DB */
522-
$services = $app->dbmaster->queryOneRecord('SELECT * FROM server WHERE server_id = ' . $server_id);
522+
$services = $app->db->queryOneRecord('SELECT * FROM server WHERE server_id = ' . $server_id);
523523
/*
524524
* If the DB is down, we have to set the db to "yes".
525525
* If we don't do this, then the monitor will NOT monitor, that the db is down and so the

server/mods-available/rescue_core_module.inc.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ private function _doRescue() {
8989
$this->_rescueData = $this->_getRescueData();
9090

9191
/*
92-
* rescue apache if needed
92+
* rescue mysql if needed (maybe apache depends on mysql, so try this first!)
9393
*/
94-
$this->_rescueApache();
94+
$this->_rescueMySql();
9595

9696
/*
97-
* rescue mysql if needed
97+
* rescue apache if needed
9898
*/
99-
$this->_rescueMySql();
99+
$this->_rescueApache();
100100

101101
/*
102102
* The last step is to save the rescue-data
@@ -273,7 +273,6 @@ private function _rescueApache(){
273273

274274

275275
$app->log('Apache is down! Try rescue apache (try:' . $tryCount . ')...', LOGLEVEL_WARN);
276-
// echo 'Apache is down! Try rescue apache (try:' . $tryCount . ')...';
277276

278277
if(is_file($conf['init_scripts'] . '/' . 'httpd')) {
279278
$daemon = 'httpd';
@@ -340,7 +339,6 @@ private function _rescueMySql(){
340339

341340

342341
$app->log('MySQL is down! Try rescue mysql (try:' . $tryCount . ')...', LOGLEVEL_WARN);
343-
// echo 'MySQL is down! Try rescue mysql (try:' . $tryCount . ')...';
344342

345343
if(is_file($conf['init_scripts'] . '/' . 'mysqld')) {
346344
$daemon = 'mysqld';

server/server.php

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
4+
Copyright (c) 2007-2011, Till Brehm, projektfarm Gmbh
55
All rights reserved.
66
77
Redistribution and use in source and binary forms, with or without modification,
@@ -54,33 +54,68 @@
5454
* Try to Load the server configuration from the master-db
5555
*/
5656
if ($app->dbmaster->connect()) {
57-
// get the dalaog_id of the last performed record
5857
$server_db_record = $app->dbmaster->queryOneRecord("SELECT * FROM server WHERE server_id = " . $conf['server_id']);
58+
5959
$conf['last_datalog_id'] = (int) $server_db_record['updated'];
6060
$conf['mirror_server_id'] = (int) $server_db_record['mirror_server_id'];
61+
6162
// Load the ini_parser
6263
$app->uses('ini_parser');
64+
6365
// Get server configuration
6466
$conf['serverconfig'] = $app->ini_parser->parse_ini_string(stripslashes($server_db_record['config']));
67+
6568
// Set the loglevel
6669
$conf['log_priority'] = intval($conf['serverconfig']['server']['loglevel']);
6770

71+
// we do not need this variable anymore
6872
unset($server_db_record);
73+
74+
/*
75+
* Save the rescue-config, maybe we need it (because the database is down)
76+
*/
77+
$tmp['serverconfig']['server']['loglevel'] = $conf['log_priority'];
78+
$tmp['serverconfig']['rescue'] = $conf['serverconfig']['rescue'];
79+
file_put_contents(dirname(__FILE__) . "/temp/rescue_module_serverconfig.ser.txt", serialize($tmp));
80+
unset($tmp);
81+
82+
// protect the file
83+
chmod(dirname(__FILE__) . "/temp/rescue_module_serverconfig.ser.txt", 0600);
84+
6985
} else {
7086
/*
7187
* The master-db is not available.
7288
* Problem: because we need to start the rescue-module (to rescue the DB if this IS the
7389
* server, the master-db is running at) we have to initialize some config...
7490
*/
75-
$conf['last_datalog_id'] = intval('9223372036854775807'); // maxint at 32 and 64 bit systems
76-
$conf['mirror_server_id'] = 0; // no mirror
77-
// Set the loglevel to warning
78-
$conf['log_priority'] = LOGLEVEL_WARN;
91+
92+
/*
93+
* If there is a temp-file with the data we could get from the database, then we use it
94+
*/
95+
$tmp = array();
96+
if (file_exists(dirname(__FILE__) . "/temp/rescue_module_serverconfig.ser.txt")){
97+
$tmp = unserialize(file_get_contents(dirname(__FILE__) . "/temp/rescue_module_serverconfig.ser.txt"));
98+
}
99+
100+
// maxint at 32 and 64 bit systems
101+
$conf['last_datalog_id'] = intval('9223372036854775807');
102+
103+
// no mirror
104+
$conf['mirror_server_id'] = 0;
105+
106+
// Set the loglevel
107+
$conf['log_priority'] = (isset($tmp['serverconfig']['server']['loglevel']))? $tmp['serverconfig']['server']['loglevel'] : LOGLEVEL_ERROR;
79108
/*
80109
* Set the configuration to rescue the database
81110
*/
82-
$conf['serverconfig']['rescue']['try_rescue'] = 'y';
83-
$conf['serverconfig']['rescue']['do_not_try_rescue_mysql'] = 'n';
111+
if (isset($tmp['serverconfig']['rescue'])){
112+
$conf['serverconfig']['rescue'] = $tmp['serverconfig']['rescue'];
113+
}
114+
else{
115+
$conf['serverconfig']['rescue']['try_rescue'] = 'n';
116+
}
117+
// we do not need this variable anymore
118+
unset($tmp);
84119
}
85120

86121

0 commit comments

Comments
 (0)