Skip to content

Commit

Permalink
Backport PR #7457
Browse files Browse the repository at this point in the history
---------

**Commit 1:**
[build] Add data directory that plugins can write to.  Closes #7157

* Original sha: 5b19534
* Authored by Jonathan Budzenski <[email protected]> on 2016-06-14T16:50:40Z

**Commit 2:**
[config] Add path.conf, path.data

* Original sha: 16e8975
* Authored by Jonathan Budzenski <[email protected]> on 2016-06-16T16:17:51Z
  • Loading branch information
jbudz committed Jun 21, 2016
1 parent da702b4 commit 4cff3db
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 3 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion src/cli/plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const installer = require('./plugin_installer');
const remover = require('./plugin_remover');
const lister = require('./plugin_lister');
const pluginLogger = require('./plugin_logger');
const getConfig = require('../../server/path').getConfig;

export default function pluginCli(program) {
function processCommand(command, options) {
Expand Down Expand Up @@ -43,7 +44,7 @@ export default function pluginCli(program) {
.option(
'-c, --config <path>',
'Path to the config file',
fromRoot('config/kibana.yml')
getConfig()
)
.option(
'-t, --timeout <duration>',
Expand Down
3 changes: 2 additions & 1 deletion src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let { resolve } = require('path');
let cwd = process.cwd();
let src = require('requirefrom')('src');
let fromRoot = src('utils/fromRoot');
const getConfig = require('../../server/path').getConfig;

let canCluster;
try {
Expand Down Expand Up @@ -35,7 +36,7 @@ module.exports = function (program) {
.option(
'-c, --config <path>',
'Path to the config file, can be changed with the CONFIG_PATH environment variable as well',
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')
.option('-Q, --silent', 'Prevent all logging')
Expand Down
5 changes: 5 additions & 0 deletions src/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let path = require('path');
let utils = require('requirefrom')('src/utils');
let fromRoot = utils('fromRoot');
const randomBytes = require('crypto').randomBytes;
const getData = require('../path').getData;

module.exports = () => Joi.object({
pkg: Joi.object({
Expand Down Expand Up @@ -84,6 +85,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'),
Expand Down
15 changes: 15 additions & 0 deletions src/server/path/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
31 changes: 31 additions & 0 deletions src/server/path/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { accessSync, R_OK} from 'fs';
import { find } from 'lodash';
import fromRoot from '../../utils/fromRoot';

const CONFIG_PATHS = [
process.env.CONFIG_PATH,
fromRoot('config/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)
};
1 change: 1 addition & 0 deletions tasks/build/installedPlugins.js
Original file line number Diff line number Diff line change
@@ -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');
});
};
6 changes: 5 additions & 1 deletion tasks/build/osPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export default (grunt) => {
'--template-value', `user=${config.user}`,
'--template-value', `group=${config.group}`,
'--template-value', `optimizeDir=${config.path.home}/optimize`,
'--template-value', `pluginsDir=${config.path.plugins}`
'--template-value', `pluginsDir=${config.path.plugins}`,
'--template-value', `dataDir=${config.path.data}`,
//uses relative path to --prefix, strip the leading /
'--exclude', `${config.path.home.slice(1)}/installedPlugins/.data`
];
const debOptions = [
'-t', 'deb',
Expand All @@ -54,6 +57,7 @@ export default (grunt) => {
];
const args = [
`${buildDir}/=${config.path.home}/`,
`${buildDir}/installedPlugins/.data/=${config.path.data}/`,
`${servicesByName.sysv.outputDir}/etc/=/etc/`,
`${servicesByName.systemd.outputDir}/lib/=/lib/`
];
Expand Down
2 changes: 2 additions & 0 deletions tasks/build/package_scripts/post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
4 changes: 4 additions & 0 deletions tasks/build/package_scripts/post_remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ if [ "$REMOVE_DIRS" = "true" ]; then
if [ -d "<%= pluginsDir %>" ]; then
rm -rf "<%= pluginsDir %>"
fi

if [ -d "<%= dataDir %>" ]; then
rmdir --ignore-fail-on-non-empty "<%= dataDir %>"
fi
fi
2 changes: 2 additions & 0 deletions tasks/config/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default (grunt) => {

const FOLDER_CONFIG = '/opt/kibana/config';
const FOLDER_HOME = '/opt/kibana';
const FOLDER_DATA = '/var/lib/kibana';
const FOLDER_PLUGINS = `${FOLDER_HOME}/installedPlugins`;

const FILE_KIBANA_CONF = `${FOLDER_CONFIG}/kibana.yml`;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4cff3db

Please sign in to comment.