Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
louislam committed Nov 4, 2024
1 parent dfba420 commit 37d8ae8
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions server/embedded-mariadb.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class EmbeddedMariaDB {
throw new Error("Embedded Mariadb supports only 'node' or 'root' user, but the current user is: " + this.username);
}

this.initDB();

this.startChildProcess();

return new Promise((resolve) => {
Expand All @@ -86,40 +88,6 @@ class EmbeddedMariaDB {
return;
}

// Create the mariadb directory if not exists and chown it to the node user
if (!fs.existsSync(this.mariadbDataDir)) {
fs.mkdirSync(this.mariadbDataDir, {
recursive: true,
});
}

// Check the owner of the mariadb directory, and change it if necessary
let stat = fs.statSync(this.mariadbDataDir);
if (stat.uid !== 1000 || stat.gid !== 1000) {
fs.chownSync(this.mariadbDataDir, 1000, 1000);
}

// Check the permission of the mariadb directory, and change it if it is not 755
if (stat.mode !== 0o755) {
fs.chmodSync(this.mariadbDataDir, 0o755);
}

// Also create the run directory if not exists and chown it to the node user
if (!fs.existsSync(this.runDir)) {
fs.mkdirSync(this.runDir, {
recursive: true,
});
}
stat = fs.statSync(this.runDir);
if (stat.uid !== 1000 || stat.gid !== 1000) {
fs.chownSync(this.runDir, 1000, 1000);
}
if (stat.mode !== 0o755) {
fs.chmodSync(this.runDir, 0o755);
}

this.initDB();

this.running = true;
log.info("mariadb", "Starting Embedded MariaDB");
this.childProcess = childProcess.spawn(this.exec, [
Expand Down Expand Up @@ -200,13 +168,31 @@ class EmbeddedMariaDB {
}
}

// Check the owner of the mariadb directory, and change it if necessary
let stat = fs.statSync(this.mariadbDataDir);
if (stat.uid !== 1000 || stat.gid !== 1000) {
fs.chownSync(this.mariadbDataDir, 1000, 1000);
}

// Check the permission of the mariadb directory, and change it if it is not 755
if (stat.mode !== 0o755) {
fs.chmodSync(this.mariadbDataDir, 0o755);
}

if (!fs.existsSync(this.runDir)) {
log.info("mariadb", `Embedded MariaDB: ${this.runDir} is not found, create one now.`);
fs.mkdirSync(this.runDir, {
recursive: true,
});
}

stat = fs.statSync(this.runDir);
if (stat.uid !== 1000 || stat.gid !== 1000) {
fs.chownSync(this.runDir, 1000, 1000);
}
if (stat.mode !== 0o755) {
fs.chmodSync(this.runDir, 0o755);
}
}

/**
Expand Down

0 comments on commit 37d8ae8

Please sign in to comment.