Skip to content

Commit 7f845d4

Browse files
chore: update libaio checks and messages
1 parent 2db95fa commit 7f845d4

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

src/libraries/Executor.ts

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { lockFile, waitForLock } from "./FileLock";
1111
import { onExit } from "signal-exit";
1212
import { randomUUID } from "crypto";
1313
import { getInternalEnvVariable } from "../constants";
14+
import etcOSRelease from "./LinuxOSRelease";
1415

1516
class Executor {
1617
logger: Logger;
@@ -296,28 +297,16 @@ class Executor {
296297
})
297298
}
298299

299-
async #setupDataDirectories(options: InternalServerOptions, binaryFilepath: string, datadir: string, retry: boolean): Promise<void> {
300+
async #setupDataDirectories(options: InternalServerOptions, binary: DownloadedMySQLVersion, datadir: string, retry: boolean): Promise<void> {
301+
const binaryFilepath = binary.path
300302
this.logger.log('Created data directory for database at:', datadir)
301303
await fsPromises.mkdir(datadir, {recursive: true})
302304

303-
let stderr: string;
305+
const {error, stderr} = await this.#executeFile(binaryFilepath, ['--no-defaults', `--datadir=${datadir}`, '--initialize-insecure'])
304306

305-
if (binaryFilepath === 'mysqld') {
306-
const {error, stderr: output} = await this.#executeFile('mysqld', ['--no-defaults', `--datadir=${datadir}`, '--initialize-insecure'])
307-
stderr = output
308-
if (error) {
309-
this.logger.error('An error occurred while initializing database with system-installed MySQL:', error)
310-
throw 'An error occurred while initializing database with system-installed MySQL. Please check the console for more information.'
311-
}
312-
} else {
313-
let result: {stderr: string, stdout: string};
314-
try {
315-
result = await this.#executeFile(`${binaryFilepath}`, [`--no-defaults`, `--datadir=${datadir}`, `--initialize-insecure`])
316-
} catch (e) {
317-
this.logger.error('Error occurred from executeFile:', e)
318-
throw e
319-
}
320-
stderr = result?.stderr
307+
if (error) {
308+
this.logger.error('An error occurred while initializing database with the ', binary.installedOnSystem ? 'system-installed MySQL binary:' : 'downloaded MySQL binary:', error)
309+
throw `An error occurred while initializing the MySQL database: ${error}`
321310
}
322311

323312
if (stderr && !stderr.includes('is created with an empty password')) {
@@ -327,26 +316,29 @@ class Executor {
327316
}
328317

329318
if (process.platform === 'linux' && stderr.includes('libaio.so')) {
330-
if (binaryFilepath === 'mysqld') {
331-
throw 'libaio could not be found while running system-installed MySQL. libaio must be installed on this system for MySQL to run. To learn more, please check out https://dev.mysql.com/doc/refman/en/binary-installation.html'
332-
}
333-
334319
if (retry === false) {
335320
this.logger.error('An error occurred while initializing database:', stderr)
336321
throw 'Tried to copy libaio into lib folder and MySQL is still failing to initialize. Please check the console for more information.'
337322
}
338323

339-
if (binaryFilepath.slice(-16) === 'mysql/bin/mysqld') {
324+
if (binary.installedOnSystem) {
325+
throw 'libaio could not be found while running system-installed MySQL. libaio must be installed on this system for MySQL to run. To learn more, please check out https://dev.mysql.com/doc/refman/en/binary-installation.html'
326+
}
327+
328+
// If the below code is running, the version of MySQL that is trying to be executed was downloaded from the CDN by this package and libaio has not yet been attempted to be copied
329+
330+
if (etcOSRelease.NAME === 'Ubuntu' && etcOSRelease.VERSION_ID >= '24.04') {
340331
const {error: lderror, stdout, stderr: ldstderr} = await this.#executeFile('ldconfig', ['-p'])
341332
if (lderror || ldstderr) {
342333
this.logger.error('The following libaio error occurred:', stderr)
343334
this.logger.error('After the libaio error, an ldconfig error occurred:', lderror || ldstderr)
344-
throw 'The ldconfig command failed to run. This command was ran to find libaio because libaio could not be found on the system. libaio is needed for MySQL to run. Do you have ldconfig and libaio installed? Learn more about libaio at Learn more at https://dev.mysql.com/doc/refman/en/binary-installation.html'
335+
throw 'The ldconfig command failed to run. This command was ran to find libaio1t64 because libaio1t64 could not be found on the system. libaio1t64 is needed for MySQL to run. Do you have ldconfig and libaio1t64 installed? Learn more at https://dev.mysql.com/doc/refman/en/binary-installation.html'
345336
}
346337
const libaioFound = stdout.split('\n').filter(lib => lib.includes('libaio.so.1t64'))
347338
if (!libaioFound.length) {
348339
this.logger.error('Error from launching MySQL:', stderr)
349-
throw 'An error occurred while launching MySQL. The most likely cause is that libaio1 and libaio1t64 could not be found. Either libaio1 or libaio1t64 must be installed on this system for MySQL to run. To learn more, please check out https://dev.mysql.com/doc/refman/en/binary-installation.html. Check error in console for more information.'
340+
this.logger.error('Could not find libaio1t64 in this list:', libaioFound)
341+
throw 'An error occurred while launching MySQL because libaio1t64 is not installed on your system. Please install libaio1t64 and then use mysql-memory-server again. To learn more, please check out https://dev.mysql.com/doc/refman/en/binary-installation.html. Check error in console for more information.'
350342
}
351343
const libaioEntry = libaioFound[0]
352344
const libaioPathIndex = libaioEntry.indexOf('=>')
@@ -417,17 +409,17 @@ class Executor {
417409
if (copyError) {
418410
throw 'An error occurred while copying libaio1t64 to the MySQL lib folder. Please check the console for more details.'
419411
}
420-
421-
//Retry setting up directory now that libaio has been copied
422-
this.logger.log('Retrying directory setup')
423-
await fsPromises.rm(datadir, {recursive: true, force: true, maxRetries: 50, retryDelay: 100})
424-
await this.#setupDataDirectories(options, binaryFilepath, datadir, false)
425-
return
426412
}
427413
}
428-
} else {
429-
throw 'Cannot recognize file structure for the MySQL binary folder. This was caused by not being able to find libaio. Try installing libaio. Learn more at https://dev.mysql.com/doc/refman/en/binary-installation.html'
414+
415+
//Retry setting up directory now that libaio has been copied
416+
this.logger.log('Retrying directory setup')
417+
await fsPromises.rm(datadir, {recursive: true, force: true, maxRetries: 50, retryDelay: 100})
418+
await this.#setupDataDirectories(options, binary, datadir, false)
419+
return
430420
}
421+
422+
throw 'You do not have libaio1 installed. Please install the libaio1 package for the downloaded MySQL binary to run. Learn more here: https://dev.mysql.com/doc/refman/en/binary-installation.html'
431423
}
432424
throw stderr
433425
}
@@ -490,7 +482,7 @@ class Executor {
490482
const datadir = normalizePath(`${this.databasePath}/data`)
491483

492484
do {
493-
await this.#setupDataDirectories(options, installedMySQLBinary.path, datadir, true);
485+
await this.#setupDataDirectories(options, installedMySQLBinary, datadir, true);
494486
this.logger.log('Setting up directories was successful')
495487

496488
const port = options.port || GenerateRandomPort()

0 commit comments

Comments
 (0)