feat: implement PortMappingService and add dynamic PHP configuration template with IPC handlers
This commit is contained in:
+20
-5
@@ -212,7 +212,11 @@ export function registerIpcHandlers(): void {
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
const dbBinary = isWindows ? 'mariadbd.exe' : 'mariadbd';
|
||||
const installBinary = isWindows ? 'mariadb-install-db.exe' : 'mariadb-install-db';
|
||||
const mysqlInstallBinary = isWindows ? 'mysql_install_db.exe' : 'mysql_install_db';
|
||||
|
||||
let binPath = findExecutable(dbBinDir, dbBinary) || findExecutable(dbBinDir, isWindows ? 'mysqld.exe' : 'mysqld');
|
||||
let installPath = findExecutable(dbBinDir, installBinary) || findExecutable(dbBinDir, mysqlInstallBinary);
|
||||
|
||||
if (!binPath) return { success: false, message: 'MariaDB executable bulunamadı. Lütfen indirin.' }
|
||||
|
||||
@@ -226,16 +230,27 @@ export function registerIpcHandlers(): void {
|
||||
// Also kill anything else listening on the same port
|
||||
await processManager.killByPort(serviceName, dbPort)
|
||||
|
||||
// Initialize if data directory is empty
|
||||
if (!fs.existsSync(dataDir) || fs.readdirSync(dataDir).length === 0) {
|
||||
// Initialize if data directory is empty or missing system tables
|
||||
const systemDbDir = path.join(dataDir, 'mysql')
|
||||
if (!fs.existsSync(dataDir) || fs.readdirSync(dataDir).length === 0 || !fs.existsSync(systemDbDir)) {
|
||||
if (!fs.existsSync(dataDir)) fs.mkdirSync(dataDir, { recursive: true })
|
||||
console.log(`Initializing MariaDB data directory for ${serviceName}...`)
|
||||
|
||||
try {
|
||||
// Try MariaDB/Modern MySQL initialization first (5.7+/10.x+)
|
||||
await processManager.runOnce(binPath, ['--initialize-insecure', `--datadir=${dataDir.replace(/\\/g, '/')}`])
|
||||
const normalizedDataDir = dataDir.replace(/\\/g, '/')
|
||||
if (installPath) {
|
||||
console.log(`Using install tool: ${installPath}`)
|
||||
// MariaDB specific installation
|
||||
await processManager.runOnce(installPath, [
|
||||
`--datadir=${normalizedDataDir}`
|
||||
])
|
||||
} else {
|
||||
console.log(`Using server init: ${binPath}`)
|
||||
// MySQL 5.7+ / modern MariaDB fallback
|
||||
await processManager.runOnce(binPath, ['--initialize-insecure', `--datadir=${normalizedDataDir}`])
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(`Modern init failed, trying template copy for ${serviceName}...`)
|
||||
console.log(`Initialization tool failed, trying template copy for ${serviceName}...`)
|
||||
// Fallback: Copy default 'data' folder from binary dir if it exists
|
||||
const templateDataDir = path.join(dbBinDir, 'data')
|
||||
if (fs.existsSync(templateDataDir)) {
|
||||
|
||||
@@ -23,9 +23,16 @@ export class PortMappingService {
|
||||
try {
|
||||
this.portMap = JSON.parse(fs.readFileSync(this.configFile, 'utf-8'))
|
||||
|
||||
const phpPorts = Object.values(this.portMap.php)
|
||||
const phpPorts = Object.values(this.portMap.php || {})
|
||||
if (phpPorts.length > 0) this.nextPhpPort = Math.max(...phpPorts) + 1
|
||||
|
||||
// Backward compatibility: switch mysql to mariadb
|
||||
if (!this.portMap.mariadb) {
|
||||
this.portMap.mariadb = (this.portMap as any).mysql || {}
|
||||
delete (this.portMap as any).mysql
|
||||
this.save()
|
||||
}
|
||||
|
||||
const mariaDbPorts = Object.values(this.portMap.mariadb)
|
||||
if (mariaDbPorts.length > 0) this.nextMariaDbPort = Math.max(...mariaDbPorts) + 1
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user