Add socket path to database config, to database setup and language file
This commit is contained in:
parent
5dff9e4b89
commit
35bcb17538
@ -166,7 +166,7 @@ class Database {
|
||||
* Read the database config
|
||||
* @throws {Error} If the config is invalid
|
||||
* @typedef {string|undefined} envString
|
||||
* @returns {{type: "sqlite"} | {type:envString, hostname:envString, port:envString, database:envString, username:envString, password:envString}} Database config
|
||||
* @returns {{type: "sqlite"} | {type:envString, hostname:envString, port:envString, database:envString, username:envString, password:envString, socketPath:envString}} Database config
|
||||
*/
|
||||
static readDBConfig() {
|
||||
let dbConfig;
|
||||
@ -186,7 +186,7 @@ class Database {
|
||||
|
||||
/**
|
||||
* @typedef {string|undefined} envString
|
||||
* @param {{type: "sqlite"} | {type:envString, hostname:envString, port:envString, database:envString, username:envString, password:envString}} dbConfig the database configuration that should be written
|
||||
* @param {{type: "sqlite"} | {type:envString, hostname:envString, port:envString, database:envString, username:envString, password:envString, socketPath:envString}} dbConfig the database configuration that should be written
|
||||
* @returns {void}
|
||||
*/
|
||||
static writeDBConfig(dbConfig) {
|
||||
@ -277,6 +277,7 @@ class Database {
|
||||
port: dbConfig.port,
|
||||
user: dbConfig.username,
|
||||
password: dbConfig.password,
|
||||
socketPath: dbConfig.socketPath,
|
||||
});
|
||||
|
||||
// Set to true, so for example "uptime.kuma", becomes `uptime.kuma`, not `uptime`.`kuma`
|
||||
@ -294,6 +295,7 @@ class Database {
|
||||
user: dbConfig.username,
|
||||
password: dbConfig.password,
|
||||
database: dbConfig.dbName,
|
||||
socketPath: dbConfig.socketPath,
|
||||
timezone: "Z",
|
||||
typeCast: function (field, next) {
|
||||
if (field.type === "DATETIME") {
|
||||
|
||||
@ -77,6 +77,7 @@ class SetupDatabase {
|
||||
dbConfig.dbName = process.env.UPTIME_KUMA_DB_NAME;
|
||||
dbConfig.username = process.env.UPTIME_KUMA_DB_USERNAME;
|
||||
dbConfig.password = process.env.UPTIME_KUMA_DB_PASSWORD;
|
||||
dbConfig.socketPath = process.env.UPTIME_KUMA_DB_SOCKET;
|
||||
Database.writeDBConfig(dbConfig);
|
||||
}
|
||||
|
||||
@ -176,14 +177,35 @@ class SetupDatabase {
|
||||
|
||||
// External MariaDB
|
||||
if (dbConfig.type === "mariadb") {
|
||||
if (!dbConfig.hostname) {
|
||||
response.status(400).json("Hostname is required");
|
||||
this.runningSetup = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbConfig.port) {
|
||||
response.status(400).json("Port is required");
|
||||
// If socketPath is not provided, hostname and port are required
|
||||
if(dbConfig.socketPath === undefined || dbConfig.socketPath.length === 0) {
|
||||
if (!dbConfig.hostname) {
|
||||
response.status(400).json("Hostname is required");
|
||||
this.runningSetup = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbConfig.port) {
|
||||
response.status(400).json("Port is required");
|
||||
this.runningSetup = false;
|
||||
return;
|
||||
}
|
||||
} else if (dbConfig.socketPath && dbConfig.socketPath.length > 0) { // Socket path is provided
|
||||
// Checking if the path exists and is a socket
|
||||
if (!fs.existsSync(dbConfig.socketPath)) {
|
||||
response.status(400).json("The path to the Socket does not exist");
|
||||
this.runningSetup = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fs.lstatSync(dbConfig.socketPath).isSocket()) {
|
||||
response.status(400).json("The path provided is not a Socket");
|
||||
this.runningSetup = false;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
response.status(400).json("Either a path to the Socket or Hostname and Port are required");
|
||||
this.runningSetup = false;
|
||||
return;
|
||||
}
|
||||
@ -215,6 +237,7 @@ class SetupDatabase {
|
||||
user: dbConfig.username,
|
||||
password: dbConfig.password,
|
||||
database: dbConfig.dbName,
|
||||
socketPath: dbConfig.socketPath,
|
||||
});
|
||||
await connection.execute("SELECT 1");
|
||||
connection.end();
|
||||
|
||||
@ -1233,5 +1233,6 @@
|
||||
"Unable to get permission to notify": "Unable to get permission to notify (request either denied or ignored).",
|
||||
"Webpush Helptext": "Web push only works with SSL (HTTPS) connections. For iOS devices, webpage must be added to homescreen beforehand.",
|
||||
"minimumIntervalWarning": "Intervals below 20 seconds may result in poor performance.",
|
||||
"lowIntervalWarning": "Are you sure want to set the interval value below 20 seconds? Performance may be degraded, particularly if there are a large number of monitors."
|
||||
"lowIntervalWarning": "Are you sure want to set the interval value below 20 seconds? Performance may be degraded, particularly if there are a large number of monitors.",
|
||||
"socketPath": "Path to socket"
|
||||
}
|
||||
|
||||
@ -76,6 +76,11 @@
|
||||
<label for="floatingInput">{{ $t("Port") }}</label>
|
||||
</div>
|
||||
|
||||
<div class="form-floating mt-3 short">
|
||||
<input id="floatingInput" v-model="dbConfig.socketPath" type="text" class="form-control">
|
||||
<label for="floatingInput">{{ $t("socketPath") }} ({{ $t("Optional") }})</label>
|
||||
</div>
|
||||
|
||||
<div class="form-floating mt-3 short">
|
||||
<input id="floatingInput" v-model="dbConfig.username" type="text" class="form-control" required>
|
||||
<label for="floatingInput">{{ $t("Username") }}</label>
|
||||
@ -117,6 +122,7 @@ export default {
|
||||
username: "",
|
||||
password: "",
|
||||
dbName: "kuma",
|
||||
socketPath: undefined,
|
||||
},
|
||||
info: {
|
||||
needSetup: false,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user