mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[config] Add path.conf, path.data
This commit is contained in:
parent
5b19534314
commit
16e8975f3a
7 changed files with 58 additions and 21 deletions
0
installedPlugins/.data/.empty
Normal file
0
installedPlugins/.data/.empty
Normal file
|
@ -3,6 +3,7 @@ import { statSync } from 'fs';
|
|||
import { isWorker } from 'cluster';
|
||||
import { resolve } from 'path';
|
||||
import { fromRoot } from '../../utils';
|
||||
import { getConfig } from '../../server/path';
|
||||
import readYamlConfig from './read_yaml_config';
|
||||
|
||||
let canCluster;
|
||||
|
@ -77,7 +78,7 @@ module.exports = function (program) {
|
|||
'Path to the config file, can be changed with the CONFIG_PATH environment variable as well. ' +
|
||||
'Use mulitple --config args to include multiple config files.',
|
||||
configPathCollector,
|
||||
[ process.env.CONFIG_PATH || fromRoot('config/kibana.yml') ]
|
||||
[ getConfig() ]
|
||||
)
|
||||
.option('-p, --port <port>', 'The port to bind to', parseInt)
|
||||
.option('-q, --quiet', 'Prevent all logging except errors')
|
||||
|
|
|
@ -3,6 +3,7 @@ import fs from 'fs';
|
|||
import install from './install';
|
||||
import Logger from '../lib/logger';
|
||||
import pkg from '../../utils/package_json';
|
||||
import { getConfig } from '../../server/path';
|
||||
import { parse, parseMilliseconds } from './settings';
|
||||
import { find } from 'lodash';
|
||||
|
||||
|
@ -20,24 +21,6 @@ function processCommand(command, options) {
|
|||
install(settings, logger);
|
||||
}
|
||||
|
||||
function getDefaultConfigPath() {
|
||||
const paths = [
|
||||
fromRoot('config/kibana.yml'),
|
||||
'/etc/kibana/kibana.yml'
|
||||
];
|
||||
|
||||
const availablePath = find(paths, configPath => {
|
||||
try {
|
||||
fs.accessSync(configPath, fs.R_OK);
|
||||
return true;
|
||||
} catch (e) {
|
||||
//Check the next path
|
||||
}
|
||||
});
|
||||
|
||||
return availablePath || paths[0];
|
||||
}
|
||||
|
||||
export default function pluginInstall(program) {
|
||||
program
|
||||
.command('install <plugin/url>')
|
||||
|
@ -46,7 +29,7 @@ export default function pluginInstall(program) {
|
|||
.option(
|
||||
'-c, --config <path>',
|
||||
'path to the config file',
|
||||
getDefaultConfigPath()
|
||||
getConfig()
|
||||
)
|
||||
.option(
|
||||
'-t, --timeout <duration>',
|
||||
|
|
|
@ -2,6 +2,7 @@ import { fromRoot } from '../../utils';
|
|||
import remove from './remove';
|
||||
import Logger from '../lib/logger';
|
||||
import { parse } from './settings';
|
||||
import { getConfig } from '../../server/path';
|
||||
|
||||
function processCommand(command, options) {
|
||||
let settings;
|
||||
|
@ -25,7 +26,7 @@ export default function pluginRemove(program) {
|
|||
.option(
|
||||
'-c, --config <path>',
|
||||
'path to the config file',
|
||||
fromRoot('config/kibana.yml')
|
||||
getConfig()
|
||||
)
|
||||
.option(
|
||||
'-d, --plugin-dir <path>',
|
||||
|
|
|
@ -6,6 +6,7 @@ import { randomBytes } from 'crypto';
|
|||
import os from 'os';
|
||||
|
||||
import { fromRoot } from '../../utils';
|
||||
import { getData } from '../path';
|
||||
|
||||
module.exports = () => Joi.object({
|
||||
pkg: Joi.object({
|
||||
|
@ -95,6 +96,10 @@ module.exports = () => Joi.object({
|
|||
initialize: Joi.boolean().default(true)
|
||||
}).default(),
|
||||
|
||||
path: Joi.object({
|
||||
data: Joi.string().default(getData())
|
||||
}).default(),
|
||||
|
||||
optimize: Joi.object({
|
||||
enabled: Joi.boolean().default(true),
|
||||
bundleFilter: Joi.string().default('!tests'),
|
||||
|
|
15
src/server/path/__tests__/index.js
Normal file
15
src/server/path/__tests__/index.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import expect from 'expect.js';
|
||||
import path from '../';
|
||||
import { accessSync, R_OK} from 'fs';
|
||||
|
||||
describe('Default path finder', function () {
|
||||
it('should find a kibana.yml', () => {
|
||||
const configPath = path.getConfig();
|
||||
expect(() => accessSync(configPath, R_OK)).to.not.throwError();
|
||||
});
|
||||
|
||||
it('should find a data directory', () => {
|
||||
const dataPath = path.getData();
|
||||
expect(() => accessSync(dataPath, R_OK)).to.not.throwError();
|
||||
});
|
||||
});
|
32
src/server/path/index.js
Normal file
32
src/server/path/index.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { accessSync, R_OK} from 'fs';
|
||||
import { find } from 'lodash';
|
||||
import { fromRoot } from '../../utils';
|
||||
|
||||
const CONFIG_PATHS = [
|
||||
process.env.CONFIG_PATH,
|
||||
fromRoot('config/kibana.yml'),
|
||||
'/etc/kibana/kibana.yml'
|
||||
].filter(Boolean);
|
||||
|
||||
const DATA_PATHS = [
|
||||
process.env.DATA_PATH,
|
||||
fromRoot('installedPlugins/.data'),
|
||||
'/var/lib/kibana'
|
||||
].filter(Boolean);
|
||||
|
||||
function findFile(paths) {
|
||||
const availablePath = find(paths, configPath => {
|
||||
try {
|
||||
accessSync(configPath, R_OK);
|
||||
return true;
|
||||
} catch (e) {
|
||||
//Check the next path
|
||||
}
|
||||
});
|
||||
return availablePath || paths[0];
|
||||
}
|
||||
|
||||
export default {
|
||||
getConfig: () => findFile(CONFIG_PATHS),
|
||||
getData: () => findFile(DATA_PATHS)
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue