From de880b19dc4a0a5c2bd194a6ccccb66620d156f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Sat, 28 Mar 2026 22:20:06 +0300 Subject: [PATCH] feat: implement IPC service management for Nginx, PHP, and MySQL processes with dynamic configuration generation --- .gitignore | 8 ++++++-- config/php.ini.template | 2 +- logs/nginx.pid | 2 +- src/main/ipc/index.ts | 11 +++++++---- src/main/services/ProcessManager.ts | 26 +++++++++++++++++++++++--- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 82ef7fd..ab59bd2 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,9 @@ yarn-error.log* # Service generated files generated_configs/ -mysql_data/ -phpmyadmin/ \ No newline at end of file +data/ +phpmyadmin/ +logs/ +bin/ +*.exe +*.dll diff --git a/config/php.ini.template b/config/php.ini.template index 6a3da4f..4eb0c0b 100644 --- a/config/php.ini.template +++ b/config/php.ini.template @@ -46,7 +46,7 @@ extension_dir = "{{EXT_DIR}}" [ExtensionList] extension=curl extension=fileinfo -extension=gd +extension={{GD_EXT}} extension=gettext extension=mbstring extension=exif diff --git a/logs/nginx.pid b/logs/nginx.pid index 3529c0b..ebd1b4f 100644 --- a/logs/nginx.pid +++ b/logs/nginx.pid @@ -1 +1 @@ -60544 +39708 diff --git a/src/main/ipc/index.ts b/src/main/ipc/index.ts index 0f123bf..71a8351 100644 --- a/src/main/ipc/index.ts +++ b/src/main/ipc/index.ts @@ -107,8 +107,11 @@ export function registerIpcHandlers(): void { const phpPort = phpVersion ? portMappingService.getPhpPort(phpVersion) : settings.phpPort const extDir = path.join(path.dirname(binPath), 'ext') + const gdExtName = fs.existsSync(path.join(extDir, 'php_gd2.dll')) ? 'gd2' : 'gd' + const configPath = await configService.generateConfig('php.ini.template', `php_${phpVersion || 'default'}.ini`, { - EXT_DIR: extDir + EXT_DIR: extDir, + GD_EXT: gdExtName }) const success = await processManager.startService(serviceName, binPath, ['-b', `127.0.0.1:${phpPort}`, '-c', configPath], false) @@ -121,8 +124,8 @@ export function registerIpcHandlers(): void { const mysqlId = mysqlVersion ? `mysql-${mysqlVersion}` : null const dataDir = mysqlId - ? path.join(configService.getBasePath(), `mysql_data_${mysqlId}`) - : path.join(configService.getBasePath(), 'mysql_data') + ? path.join(configService.getBasePath(), 'data', mysqlId) + : path.join(configService.getBasePath(), 'data', 'default') const mysqlDir = mysqlId ? path.join(binDir, mysqlId) : binDir const binPath = findExecutable(mysqlDir, 'mysqld.exe') @@ -147,7 +150,7 @@ export function registerIpcHandlers(): void { const configPath = await configService.generateConfig('my.ini.template', `my_${mysqlId || 'default'}.ini`, { PORT: mysqlPort, DATADIR: dataDir.replace(/\\/g, '/'), - SOCKET: `/tmp/${serviceName}.sock`, + SOCKET: `/tmp/${sanitizedServiceName}.sock`, LOG_FILE: logFile.replace(/\\/g, '/') }) diff --git a/src/main/services/ProcessManager.ts b/src/main/services/ProcessManager.ts index f1a1fd5..ea382a7 100644 --- a/src/main/services/ProcessManager.ts +++ b/src/main/services/ProcessManager.ts @@ -74,6 +74,12 @@ export class ProcessManager { if (name) this.addLog(name, out) }) + child.on('error', (err) => { + console.error(`[INIT ERROR:${name || '?'}] ${err.message}`) + if (name) this.addLog(name, `RunOnce Error: ${err.message}`) + resolve(false) + }) + child.stderr?.on('data', (data) => { const err = data.toString() console.error(`[INIT ERROR:${name || '?'}] ${err}`) @@ -160,6 +166,11 @@ export class ProcessManager { windowsHide: true, shell: false }) + kill.on('error', (err) => { + this.addLog(name, `PID Kill error: ${err.message}`) + this.processes.delete(name) + resolve(true) + }) kill.on('close', () => { this.processes.delete(name) resolve(true) @@ -176,18 +187,27 @@ export class ProcessManager { // For versioned mysql, we try to find by command line (contains data directory name) const mysqlId = name.replace('mysql:', 'mysql-') this.addLog(name, `Attempting to kill specific MySQL instance: ${mysqlId}`) - // Using wmic to find and kill - const wmic = spawn('wmic', ['process', 'where', `name='mysqld.exe' and commandline like '%mysql_data_${mysqlId}%'`, 'call', 'terminate'], { + // Using powershell to find and kill as wmic is deprecated/missing on some Win11 + const psCommand = `Get-CimInstance Win32_Process -Filter "name = 'mysqld.exe' AND CommandLine LIKE '%mysql_data_${mysqlId}%'" | Invoke-CimMethod -MethodName Terminate` + const ps = spawn('powershell', ['-Command', psCommand], { windowsHide: true, shell: false }) - wmic.on('close', () => resolve(true)) + ps.on('error', (err) => { + this.addLog(name, `PowerShell kill error: ${err.message}`) + resolve(true) + }) + ps.on('close', () => resolve(true)) } else { this.addLog(name, `Force killing all ${executableName} processes...`) const tk = spawn('taskkill', ['/F', '/IM', executableName, '/T'], { windowsHide: true, shell: false }) + tk.on('error', (err) => { + this.addLog(name, `Taskkill error: ${err.message}`) + resolve(true) + }) tk.on('close', () => resolve(true)) } })