feat: implement IPC service management for Nginx, PHP, and MySQL processes with dynamic configuration generation

This commit is contained in:
Ümit Tunç
2026-03-28 22:20:06 +03:00
parent 86f829e4ed
commit de880b19dc
5 changed files with 38 additions and 11 deletions
+6 -2
View File
@@ -32,5 +32,9 @@ yarn-error.log*
# Service generated files
generated_configs/
mysql_data/
phpmyadmin/
data/
phpmyadmin/
logs/
bin/
*.exe
*.dll
+1 -1
View File
@@ -46,7 +46,7 @@ extension_dir = "{{EXT_DIR}}"
[ExtensionList]
extension=curl
extension=fileinfo
extension=gd
extension={{GD_EXT}}
extension=gettext
extension=mbstring
extension=exif
+1 -1
View File
@@ -1 +1 @@
60544
39708
+7 -4
View File
@@ -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, '/')
})
+23 -3
View File
@@ -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))
}
})