Skip to content

Commit 5d0065f

Browse files
kibanamachinejbudz
andauthored
[deb/rpm] Generate os package specific kibana.yml (#98213) (#110734)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Jonathan Budzenski <jon@budzenski.me>
1 parent e64892a commit 5d0065f

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

src/dev/build/build_distributables.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export async function buildDistributables(log: ToolingLog, options: BuildOptions
105105
// control w/ --skip-archives
106106
await run(Tasks.CreateArchives);
107107
}
108+
109+
if (options.createDebPackage || options.createRpmPackage) {
110+
await run(Tasks.CreatePackageConfig);
111+
}
108112
if (options.createDebPackage) {
109113
// control w/ --deb or --skip-os-packages
110114
await run(Tasks.CreateDebPackage);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { readFileSync, writeFileSync } from 'fs';
10+
import { resolve } from 'path';
11+
import { Build, Config, mkdirp } from '../../lib';
12+
13+
export async function createOSPackageKibanaYML(config: Config, build: Build) {
14+
const configReadPath = config.resolveFromRepo('config', 'kibana.yml');
15+
const configWriteDir = config.resolveFromRepo('build', 'os_packages', 'config');
16+
const configWritePath = resolve(configWriteDir, 'kibana.yml');
17+
18+
await mkdirp(configWriteDir);
19+
20+
let kibanaYML = readFileSync(configReadPath, { encoding: 'utf8' });
21+
22+
[
23+
[/#pid.file:.*/g, 'pid.file: /run/kibana/kibana.pid'],
24+
[/#logging.dest:.*/g, 'logging.dest: /var/log/kibana/kibana.log'],
25+
].forEach((options) => {
26+
const [regex, setting] = options;
27+
const diff = kibanaYML;
28+
const match = kibanaYML.search(regex) >= 0;
29+
if (match) {
30+
if (typeof setting === 'string') {
31+
kibanaYML = kibanaYML.replace(regex, setting);
32+
}
33+
}
34+
35+
if (!diff.localeCompare(kibanaYML)) {
36+
throw new Error(
37+
`OS package configuration unmodified. Verify match for ${regex} is available`
38+
);
39+
}
40+
});
41+
42+
try {
43+
writeFileSync(configWritePath, kibanaYML, { flag: 'wx' });
44+
} catch (err) {
45+
if (err.code === 'EEXIST') {
46+
return;
47+
}
48+
throw err;
49+
}
50+
}

src/dev/build/tasks/os_packages/create_os_package_tasks.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
import { Task } from '../../lib';
1010
import { runFpm } from './run_fpm';
1111
import { runDockerGenerator } from './docker_generator';
12+
import { createOSPackageKibanaYML } from './create_os_package_kibana_yml';
13+
14+
export const CreatePackageConfig: Task = {
15+
description: 'Creating OS package kibana.yml',
16+
17+
async run(config, log, build) {
18+
await createOSPackageKibanaYML(config, build);
19+
},
20+
};
1221

1322
export const CreateDebPackage: Task = {
1423
description: 'Creating deb package',

src/dev/build/tasks/os_packages/run_fpm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export async function runFpm(
125125
`${resolveWithTrailingSlash(fromBuild('.'))}=/usr/share/kibana/`,
126126

127127
// copy the config directory to /etc/kibana
128+
`${config.resolveFromRepo('build/os_packages/config/kibana.yml')}=/etc/kibana/kibana.yml`,
128129
`${resolveWithTrailingSlash(fromBuild('config'))}=/etc/kibana/`,
129130

130131
// copy the data directory at /var/lib/kibana

src/dev/build/tasks/os_packages/service_templates/systemd/etc/systemd/system/kibana.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Environment=KBN_PATH_CONF=/etc/kibana
1515
EnvironmentFile=-/etc/default/kibana
1616
EnvironmentFile=-/etc/sysconfig/kibana
1717

18-
ExecStart=/usr/share/kibana/bin/kibana --logging.dest="/var/log/kibana/kibana.log" --pid.file="/run/kibana/kibana.pid"
18+
ExecStart=/usr/share/kibana/bin/kibana
1919

2020
Restart=on-failure
2121
RestartSec=3

0 commit comments

Comments
 (0)