feat: implement IPC handlers for Nginx, PHP, and MySQL service management
This commit is contained in:
+48
-5
@@ -60,13 +60,12 @@ export function registerIpcHandlers(): void {
|
||||
const phpPort = portMappingService.getPhpPort(p.phpVersion)
|
||||
const normalizedPath = p.path.replace(/\\/g, '/')
|
||||
return `
|
||||
location /${p.host} {
|
||||
alias "${normalizedPath}";
|
||||
location /${p.host}/ {
|
||||
alias "${normalizedPath}/";
|
||||
index index.php index.html;
|
||||
try_files $uri $uri/ /${p.host}/index.php?$query_string;
|
||||
|
||||
location ~ ^/${p.host}/(.+\\.php)$ {
|
||||
alias "${normalizedPath}/$1";
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass 127.0.0.1:${phpPort};
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME $request_filename;
|
||||
@@ -140,7 +139,22 @@ export function registerIpcHandlers(): void {
|
||||
if (!fs.existsSync(dataDir) || fs.readdirSync(dataDir).length === 0) {
|
||||
if (!fs.existsSync(dataDir)) fs.mkdirSync(dataDir, { recursive: true })
|
||||
console.log(`Initializing MySQL data directory for ${serviceName}...`)
|
||||
await processManager.runOnce(binPath, ['--initialize-insecure', `--datadir=${dataDir.replace(/\\/g, '/')}`])
|
||||
|
||||
try {
|
||||
// Try modern initialization first (5.7+)
|
||||
await processManager.runOnce(binPath, ['--initialize-insecure', `--datadir=${dataDir.replace(/\\/g, '/')}`])
|
||||
} catch (err) {
|
||||
console.log(`Modern init failed, trying template copy for ${serviceName}...`)
|
||||
// Fallback for 5.6: Copy default 'data' folder from binary dir if it exists
|
||||
const templateDataDir = path.join(mysqlDir, 'data')
|
||||
if (fs.existsSync(templateDataDir)) {
|
||||
// Recursively copy template data (mysql, performance_schema, etc.)
|
||||
fs.cpSync(templateDataDir, dataDir, { recursive: true })
|
||||
console.log(`Successfully copied template data for ${serviceName}`)
|
||||
} else {
|
||||
throw new Error(`MySQL initialization failed and no template data found at ${templateDataDir}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mysqlPort = mysqlId ? (settings.mysqlPorts?.[mysqlId] || '3306') : settings.mysqlPort
|
||||
@@ -155,6 +169,15 @@ export function registerIpcHandlers(): void {
|
||||
})
|
||||
|
||||
const success = await processManager.startService(serviceName, binPath, ['--defaults-file=' + configPath], false)
|
||||
|
||||
if (success) {
|
||||
// Quick health check for MySQL
|
||||
await new Promise(r => setTimeout(r, 1500))
|
||||
if (!processManager.isServiceRunning(serviceName)) {
|
||||
return { success: false, message: `${mysqlVersion || ''} MySQL başlatıldı ancak çalışma hatası verdi. Lütfen logları ve port çakışmalarını kontrol edin.` }
|
||||
}
|
||||
}
|
||||
|
||||
return { success, message: success ? `${mysqlVersion || ''} MySQL başlatıldı.` : `${mysqlVersion || ''} MySQL devreye alınamadı.` }
|
||||
}
|
||||
|
||||
@@ -310,4 +333,24 @@ export function registerIpcHandlers(): void {
|
||||
event.sender.send('pma:progress', p)
|
||||
})
|
||||
})
|
||||
|
||||
ipcMain.handle('services:reset-data', async (_event, serviceName: string) => {
|
||||
try {
|
||||
await processManager.forceKillAll(serviceName)
|
||||
|
||||
const versionMatch = serviceName.match(/^mysql:(.+)$/)
|
||||
const mysqlVersion = versionMatch ? versionMatch[1] : null
|
||||
const mysqlId = mysqlVersion ? `mysql-${mysqlVersion}` : null
|
||||
|
||||
if (!mysqlId) return { success: false, message: 'Geçersiz servis adı.' }
|
||||
|
||||
const dataDir = path.join(configService.getBasePath(), 'data', mysqlId)
|
||||
if (fs.existsSync(dataDir)) {
|
||||
fs.rmSync(dataDir, { recursive: true, force: true })
|
||||
}
|
||||
return { success: true, message: `${serviceName} verileri sıfırlandı. Tekrar başlatmayı deneyebilirsiniz.` }
|
||||
} catch (error: any) {
|
||||
return { success: false, message: `Sıfırlama hatası: ${error.message}` }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user