Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] UUID: Change UUID file naming to ensure that multiple running instances of Kibana use separate data directory #8205

Merged
merged 3 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Promise from 'bluebird';
import { mkdirp as mkdirpNode } from 'mkdirp';
import manageUuid from './server/lib/manage_uuid';
import ingest from './server/routes/api/ingest';
import search from './server/routes/api/search';
import settings from './server/routes/api/settings';
import scripts from './server/routes/api/scripts';
import * as systemApi from './server/lib/system_api';

const mkdirp = Promise.promisify(mkdirpNode);

module.exports = function (kibana) {
const kbnBaseUrl = '/app/kibana';
return new kibana.Plugin({
Expand Down Expand Up @@ -85,6 +89,18 @@ module.exports = function (kibana) {
},
},

preInit: async function (server) {
try {
// Create the data directory (recursively, if the a parent dir doesn't exist).
// If it already exists, does nothing.
await mkdirp(server.config().get('path.data'));
} catch (err) {
server.log(['error', 'init'], err);
// Stop the server startup with a fatal error
throw err;
}
},

init: function (server, options) {
// uuid
manageUuid(server);
Expand Down
20 changes: 13 additions & 7 deletions src/core_plugins/kibana/server/lib/manage_uuid.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ const FILE_ENCODING = 'utf8';

export default async function manageUuid(server) {
const config = server.config();
const serverPort = server.info.port;
const serverHostname = config.get('server.host');
const fileName = `${serverHostname}:${serverPort}`;
const fileName = 'uuid';
const uuidFile = pathJoin(config.get('path.data'), fileName);

async function detectUuid() {
const readFile = Promise.promisify(readFileCallback);
try {
const result = await readFile(uuidFile);
return result.toString(FILE_ENCODING);
} catch (e) {
return false;
} catch (err) {
if (err.code === 'ENOENT') {
// non-existant uuid file is ok
return false;
}
server.log(['error', 'read-uuid'], err);
// Note: this will most likely be logged as an Unhandled Rejection
throw err;
}
}

async function writeUuid(uuid) {
const writeFile = Promise.promisify(writeFileCallback);
try {
return await writeFile(uuidFile, uuid, { encoding: FILE_ENCODING });
} catch (e) {
return false;
} catch (err) {
server.log(['error', 'write-uuid'], err);
// Note: this will most likely be logged as an Unhandled Rejection
throw err;
}
}

Expand Down