feat: implement backend service management for Nginx, PHP, and MySQL with configuration templating and IPC handlers

This commit is contained in:
Ümit Tunç
2026-03-28 16:37:16 +03:00
parent 8abffa741f
commit 91b13513fc
6 changed files with 206 additions and 24 deletions
+38 -14
View File
@@ -34,19 +34,41 @@ export function registerIpcHandlers(): void {
if (serviceName === 'nginx') {
const rootPath = path.join(app.getAppPath(), 'www')
const configPath = await configService.generateConfig('nginx.conf.template', 'nginx.conf', {
PORT: settings.nginxPort,
PHP_PORT: settings.phpPort,
ROOT: rootPath
})
const nginxDir = path.join(binDir, 'nginx')
const binPath = findExecutable(nginxDir, 'nginx.exe')
const logDir = path.join(app.getPath('userData'), 'logs')
if (!binPath) return { success: false, message: 'Nginx executable bulunamadı. Lütfen indirin.' }
const success = await processManager.startService('nginx', binPath, ['-c', configPath])
return { success, message: success ? 'Nginx başlatıldı.' : 'Nginx dosyaları bulunamadı veya port meşgul.' }
// Nginx prefix = directory containing nginx.exe
const nginxPrefix = path.dirname(binPath)
const confDir = path.join(nginxPrefix, 'conf')
// Ensure temp directories exist (Nginx needs these)
const tempDirs = ['temp', 'temp/client_body_temp', 'temp/proxy_temp', 'temp/fastcgi_temp', 'temp/uwsgi_temp', 'temp/scgi_temp', 'logs']
for (const dir of tempDirs) {
const fullDir = path.join(nginxPrefix, dir)
if (!fs.existsSync(fullDir)) {
fs.mkdirSync(fullDir, { recursive: true })
}
}
const configPath = await configService.generateConfig('nginx.conf.template', 'nginx.conf', {
PORT: settings.nginxPort,
PHP_PORT: settings.phpPort,
ROOT: rootPath,
LOG_DIR: logDir.replace(/\\/g, '/'),
CONF_DIR: confDir.replace(/\\/g, '/')
})
// Test config first with prefix
const testResult = await processManager.runOnce(binPath, ['-t', '-p', nginxPrefix, '-c', configPath], 'nginx')
if (!testResult) {
return { success: false, message: 'Nginx konfigürasyon hatası! Log sekmesini kontrol edin.' }
}
const success = await processManager.startService('nginx', binPath, ['-p', nginxPrefix, '-c', configPath], true)
return { success, message: success ? 'Nginx başlatıldı.' : 'Nginx devreye alınamadı (Hata loglarını kontrol edin).' }
}
if (serviceName === 'php') {
@@ -55,10 +77,10 @@ export function registerIpcHandlers(): void {
const extDir = path.join(path.dirname(binPath), 'ext')
const configPath = await configService.generateConfig('php.ini.template', 'php.ini', {
EXT_DIR: extDir.replace(/\\/g, '\\\\') // PHP ini needs escaped backslashes or forward slashes
EXT_DIR: extDir
})
const success = await processManager.startService('php', binPath, ['-b', `127.0.0.1:${settings.phpPort}`, '-c', configPath])
const success = await processManager.startService('php', binPath, ['-b', `127.0.0.1:${settings.phpPort}`, '-c', configPath], false)
return { success, message: success ? 'PHP başlatıldı.' : 'PHP devreye alınamadı (Hata loglarını kontrol edin).' }
}
@@ -75,14 +97,16 @@ export function registerIpcHandlers(): void {
await processManager.runOnce(binPath, ['--initialize-insecure', `--datadir=${dataDir.replace(/\\/g, '/')}`])
}
const logFile = path.join(app.getPath('userData'), 'logs', 'mysql_error.log')
const configPath = await configService.generateConfig('my.ini.template', 'my.ini', {
PORT: settings.mysqlPort,
DATADIR: dataDir,
SOCKET: '/tmp/mysql.sock'
DATADIR: dataDir.replace(/\\/g, '/'),
SOCKET: '/tmp/mysql.sock',
LOG_FILE: logFile.replace(/\\/g, '/')
})
const success = await processManager.startService('mysql', binPath, ['--defaults-file=' + configPath])
return { success, message: success ? 'MySQL başlatıldı.' : 'MySQL dosyaları bulunamadı veya port meşgul.' }
const success = await processManager.startService('mysql', binPath, ['--defaults-file=' + configPath], false)
return { success, message: success ? 'MySQL başlatıldı.' : 'MySQL devreye alınamadı (Hata loglarını kontrol edin).' }
}
return { success: false, message: 'Bilinmeyen servis.' }