diff --git a/README.md b/README.md index 180a215..ab74ea4 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,10 @@ Read the [documentation](docs/TYPO3.md) for detailed installation instructions a ### Standalone Tasks - [MS Teams Notification](deployer/notification/task/ms_teams.php) - [Database backup](deployer/sync/task/database_backup.php) -- [Database management](docs/DATABASE.md) - [Security check](docs/SECURITY.md) - [Development](docs/DEV.md) - [Debug helper](docs/DEBUG.md) +- [Requirements](docs/REQUIREMENTS.md) ## 💛 Acknowledgements diff --git a/deployer/requirements/task/health.php b/deployer/requirements/task/health.php index ba002b9..0e93d9e 100644 --- a/deployer/requirements/task/health.php +++ b/deployer/requirements/task/health.php @@ -45,23 +45,65 @@ $db = detectDatabaseProduct(); $dbLabel = $db !== null ? $db['label'] : 'Database'; $adminCmd = ($db !== null && $db['product'] === 'mariadb') ? 'mariadb-admin' : 'mysqladmin'; + $dbCredentials = resolveDatabaseCredentials(); $dbChecked = false; - try { - run("$adminCmd ping --silent 2>/dev/null"); - addRequirementRow('Database server', REQUIREMENT_OK, "$dbLabel responding"); - $dbChecked = true; - } catch (RunException) { - // Admin tool not available — fall through to process check + // Try mysqladmin ping with credentials when available + if ($dbCredentials !== null) { + $pingCmd = sprintf( + '%s ping --silent -h %s -P %d -u %s --password=%s 2>/dev/null', + $adminCmd, + escapeshellarg($dbCredentials['host']), + $dbCredentials['port'], + escapeshellarg($dbCredentials['user']), + escapeshellarg($dbCredentials['password']) + ); + + try { + run($pingCmd); + $hostInfo = $dbCredentials['host'] === '127.0.0.1' || $dbCredentials['host'] === 'localhost' + ? 'local' + : $dbCredentials['host']; + addRequirementRow('Database server', REQUIREMENT_OK, "$dbLabel responding ($hostInfo)"); + $dbChecked = true; + } catch (RunException) { + // Credentials available but ping failed — fall through + } } - if (!$dbChecked) { - $dbProcess = isServiceActive('mysqld', 'mariadbd'); + $isRemoteDb = $dbCredentials !== null + && $dbCredentials['host'] !== '127.0.0.1' + && $dbCredentials['host'] !== 'localhost'; + + // Fallback: try mysqladmin ping without credentials (uses ~/.my.cnf or socket) + // Skip for remote hosts — a local socket hit would be a false positive. + if (!$dbChecked && !$isRemoteDb) { + try { + run("$adminCmd ping --silent 2>/dev/null"); + addRequirementRow('Database server', REQUIREMENT_OK, "$dbLabel responding"); + $dbChecked = true; + } catch (RunException) { + // Admin tool not available — fall through to process check + } + } - if ($dbProcess !== null) { - addRequirementRow('Database server', REQUIREMENT_OK, "$dbLabel process running ($dbProcess)"); + // Only check for local processes if the database host is local (or unknown) + if (!$dbChecked) { + if ($isRemoteDb) { + addRequirementRow('Database server', REQUIREMENT_FAIL, sprintf( + 'Cannot reach %s on %s:%d', + $dbLabel, + $dbCredentials['host'], + $dbCredentials['port'] + )); } else { - addRequirementRow('Database server', REQUIREMENT_FAIL, 'No mysqld or mariadbd process found'); + $dbProcess = isServiceActive('mysqld', 'mariadbd'); + + if ($dbProcess !== null) { + addRequirementRow('Database server', REQUIREMENT_OK, "$dbLabel process running ($dbProcess)"); + } else { + addRequirementRow('Database server', REQUIREMENT_FAIL, 'No mysqld or mariadbd process found'); + } } }