[deb/rpm] Generate os package specific kibana.yml (#98213)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
634c272edd
commit
40b91c97ce
|
@ -105,6 +105,10 @@ export async function buildDistributables(log: ToolingLog, options: BuildOptions
|
|||
// control w/ --skip-archives
|
||||
await run(Tasks.CreateArchives);
|
||||
}
|
||||
|
||||
if (options.createDebPackage || options.createRpmPackage) {
|
||||
await run(Tasks.CreatePackageConfig);
|
||||
}
|
||||
if (options.createDebPackage) {
|
||||
// control w/ --deb or --skip-os-packages
|
||||
await run(Tasks.CreateDebPackage);
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import { Build, Config, mkdirp } from '../../lib';
|
||||
|
||||
export async function createOSPackageKibanaYML(config: Config, build: Build) {
|
||||
const configReadPath = config.resolveFromRepo('config', 'kibana.yml');
|
||||
const configWriteDir = config.resolveFromRepo('build', 'os_packages', 'config');
|
||||
const configWritePath = resolve(configWriteDir, 'kibana.yml');
|
||||
|
||||
await mkdirp(configWriteDir);
|
||||
|
||||
let kibanaYML = readFileSync(configReadPath, { encoding: 'utf8' });
|
||||
|
||||
[
|
||||
[/#pid.file:.*/g, 'pid.file: /run/kibana/kibana.pid'],
|
||||
[/#logging.dest:.*/g, 'logging.dest: /var/log/kibana/kibana.log'],
|
||||
].forEach((options) => {
|
||||
const [regex, setting] = options;
|
||||
const diff = kibanaYML;
|
||||
const match = kibanaYML.search(regex) >= 0;
|
||||
if (match) {
|
||||
if (typeof setting === 'string') {
|
||||
kibanaYML = kibanaYML.replace(regex, setting);
|
||||
}
|
||||
}
|
||||
|
||||
if (!diff.localeCompare(kibanaYML)) {
|
||||
throw new Error(
|
||||
`OS package configuration unmodified. Verify match for ${regex} is available`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
writeFileSync(configWritePath, kibanaYML, { flag: 'wx' });
|
||||
} catch (err) {
|
||||
if (err.code === 'EEXIST') {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
|
@ -9,6 +9,15 @@
|
|||
import { Task } from '../../lib';
|
||||
import { runFpm } from './run_fpm';
|
||||
import { runDockerGenerator } from './docker_generator';
|
||||
import { createOSPackageKibanaYML } from './create_os_package_kibana_yml';
|
||||
|
||||
export const CreatePackageConfig: Task = {
|
||||
description: 'Creating OS package kibana.yml',
|
||||
|
||||
async run(config, log, build) {
|
||||
await createOSPackageKibanaYML(config, build);
|
||||
},
|
||||
};
|
||||
|
||||
export const CreateDebPackage: Task = {
|
||||
description: 'Creating deb package',
|
||||
|
|
|
@ -123,6 +123,7 @@ export async function runFpm(
|
|||
`${resolveWithTrailingSlash(fromBuild('.'))}=/usr/share/kibana/`,
|
||||
|
||||
// copy the config directory to /etc/kibana
|
||||
`${config.resolveFromRepo('build/os_packages/config/kibana.yml')}=/etc/kibana/kibana.yml`,
|
||||
`${resolveWithTrailingSlash(fromBuild('config'))}=/etc/kibana/`,
|
||||
|
||||
// copy the data directory at /var/lib/kibana
|
||||
|
|
|
@ -15,7 +15,7 @@ Environment=KBN_PATH_CONF=/etc/kibana
|
|||
EnvironmentFile=-/etc/default/kibana
|
||||
EnvironmentFile=-/etc/sysconfig/kibana
|
||||
|
||||
ExecStart=/usr/share/kibana/bin/kibana --logging.dest="/var/log/kibana/kibana.log" --pid.file="/run/kibana/kibana.pid"
|
||||
ExecStart=/usr/share/kibana/bin/kibana
|
||||
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
|
|
Loading…
Reference in a new issue