diff --git a/installedPlugins/.empty b/installedPlugins/.data/.empty similarity index 100% rename from installedPlugins/.empty rename to installedPlugins/.data/.empty diff --git a/src/cli/serve/serve.js b/src/cli/serve/serve.js index 9b73b11720f28..a104eb5eb94f1 100644 --- a/src/cli/serve/serve.js +++ b/src/cli/serve/serve.js @@ -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 ', 'The port to bind to', parseInt) .option('-q, --quiet', 'Prevent all logging except errors') diff --git a/src/cli_plugin/install/index.js b/src/cli_plugin/install/index.js index cb5bdaf69bc69..74f19bef53729 100644 --- a/src/cli_plugin/install/index.js +++ b/src/cli_plugin/install/index.js @@ -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 ') @@ -46,7 +29,7 @@ export default function pluginInstall(program) { .option( '-c, --config ', 'path to the config file', - getDefaultConfigPath() + getConfig() ) .option( '-t, --timeout ', diff --git a/src/cli_plugin/remove/index.js b/src/cli_plugin/remove/index.js index b763e6882fc6d..3ea83a1b7200f 100644 --- a/src/cli_plugin/remove/index.js +++ b/src/cli_plugin/remove/index.js @@ -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 to the config file', - fromRoot('config/kibana.yml') + getConfig() ) .option( '-d, --plugin-dir ', diff --git a/src/server/config/schema.js b/src/server/config/schema.js index 55f4d31bad6c3..bb78856f1c72b 100644 --- a/src/server/config/schema.js +++ b/src/server/config/schema.js @@ -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'), diff --git a/src/server/path/__tests__/index.js b/src/server/path/__tests__/index.js new file mode 100644 index 0000000000000..c709df29dc0e3 --- /dev/null +++ b/src/server/path/__tests__/index.js @@ -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(); + }); +}); diff --git a/src/server/path/index.js b/src/server/path/index.js new file mode 100644 index 0000000000000..e0bd49097c08f --- /dev/null +++ b/src/server/path/index.js @@ -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) +}; diff --git a/tasks/build/installed_plugins.js b/tasks/build/installed_plugins.js index 7d8d6618ff488..5d2fcc4d4ed37 100644 --- a/tasks/build/installed_plugins.js +++ b/tasks/build/installed_plugins.js @@ -1,5 +1,6 @@ module.exports = function (grunt) { grunt.registerTask('_build:installedPlugins', function () { grunt.file.mkdir('build/kibana/installedPlugins'); + grunt.file.mkdir('build/kibana/installedPlugins/.data'); }); }; diff --git a/tasks/build/os_packages.js b/tasks/build/os_packages.js index c739bf122e1c2..7a869ca7a2f77 100644 --- a/tasks/build/os_packages.js +++ b/tasks/build/os_packages.js @@ -44,9 +44,11 @@ export default (grunt) => { '--template-value', `optimizeDir=${packages.path.home}/optimize`, '--template-value', `configDir=${packages.path.conf}`, '--template-value', `pluginsDir=${packages.path.plugins}`, + '--template-value', `dataDir=${packages.path.data}`, //config folder is moved to path.conf, exclude {path.home}/config //uses relative path to --prefix, strip the leading / - '--exclude', `${packages.path.home.slice(1)}/config` + '--exclude', `${packages.path.home.slice(1)}/config`, + '--exclude', `${packages.path.home.slice(1)}/installedPlugins/.data` ]; const debOptions = [ '-t', 'deb', @@ -59,6 +61,7 @@ export default (grunt) => { const args = [ `${buildDir}/=${packages.path.home}/`, `${buildDir}/config/=${packages.path.conf}/`, + `${buildDir}/installedPlugins/.data/=${packages.path.data}/`, `${servicesByName.sysv.outputDir}/etc/=/etc/`, `${servicesByName.systemd.outputDir}/lib/=/lib/` ]; diff --git a/tasks/build/package_scripts/post_install.sh b/tasks/build/package_scripts/post_install.sh index beef49af21753..bc31f19f19953 100644 --- a/tasks/build/package_scripts/post_install.sh +++ b/tasks/build/package_scripts/post_install.sh @@ -15,3 +15,5 @@ if ! user_check "<%= user %>" ; then user_create "<%= user %>" fi chown -R <%= user %>:<%= group %> <%= optimizeDir %> +chown <%= user %>:<%= group %> <%= dataDir %> +chown <%= user %>:<%= group %> <%= pluginsDir %> diff --git a/tasks/build/package_scripts/post_remove.sh b/tasks/build/package_scripts/post_remove.sh index d0ac977cdd3b2..c1499c2940d83 100644 --- a/tasks/build/package_scripts/post_remove.sh +++ b/tasks/build/package_scripts/post_remove.sh @@ -59,4 +59,8 @@ if [ "$REMOVE_DIRS" = "true" ]; then if [ -d "<%= configDir %>" ]; then rmdir --ignore-fail-on-non-empty "<%= configDir %>" fi + + if [ -d "<%= dataDir %>" ]; then + rmdir --ignore-fail-on-non-empty "<%= dataDir %>" + fi fi diff --git a/tasks/config/packages.js b/tasks/config/packages.js index 3162c4bffff33..1c6aef8c2934c 100644 --- a/tasks/config/packages.js +++ b/tasks/config/packages.js @@ -14,6 +14,7 @@ export default (grunt) => { const FOLDER_CONFIG = '/etc/kibana'; const FOLDER_HOME = '/usr/share/kibana'; + const FOLDER_DATA = '/var/lib/kibana'; const FOLDER_PLUGINS = `${FOLDER_HOME}/installedPlugins`; const FILE_KIBANA_CONF = `${FOLDER_CONFIG}/kibana.yml`; @@ -43,6 +44,7 @@ export default (grunt) => { version: VERSION, path: { conf: FOLDER_CONFIG, + data: FOLDER_DATA, plugins: FOLDER_PLUGINS, home: FOLDER_HOME, kibanaBin: FILE_KIBANA_BINARY,