diff --git a/Gruntfile.js b/Gruntfile.js index 045f057cd2dd..3fef79398e4f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -69,7 +69,7 @@ module.exports = function (grunt) { grunt.config.merge(config); - config.userScriptsDir = __dirname + '/build/userScripts'; + config.packageScriptsDir = __dirname + '/tasks/build/package_scripts'; // ensure that these run first, other configs need them config.services = require('./tasks/config/services')(grunt); config.platforms = require('./tasks/config/platforms')(grunt); diff --git a/tasks/build/os_packages.js b/tasks/build/os_packages.js index 5153df3263ad..57831e2d2783 100644 --- a/tasks/build/os_packages.js +++ b/tasks/build/os_packages.js @@ -6,7 +6,7 @@ module.exports = function (grunt) { const exec = require('../utils/exec'); const targetDir = config.get('target'); const version = config.get('pkg.version'); - const userScriptsDir = config.get('userScriptsDir'); + const packageScriptsDir = config.get('packageScriptsDir'); const servicesByName = indexBy(config.get('services'), 'name'); grunt.registerTask('_build:osPackages', function () { @@ -28,8 +28,9 @@ module.exports = function (grunt) { '--vendor', 'Elasticsearch,\ Inc.', '--maintainer', 'Kibana Team\ \', '--license', 'Apache\ 2.0', - '--after-install', resolve(userScriptsDir, 'installer.sh'), - '--after-remove', resolve(userScriptsDir, 'remover.sh'), + '--after-install', resolve(packageScriptsDir, 'post_install.sh'), + '--before-remove', resolve(packageScriptsDir, 'pre_remove.sh'), + '--after-remove', resolve(packageScriptsDir, 'post_remove.sh'), '--config-files', '/opt/kibana/config/kibana.yml' ]; diff --git a/tasks/build/package_scripts/post_install.sh b/tasks/build/package_scripts/post_install.sh new file mode 100644 index 000000000000..68e55325c319 --- /dev/null +++ b/tasks/build/package_scripts/post_install.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +user_check() { + getent passwd "$1" > /dev/null 2>&1 +} + +user_create() { + # Create a system user. A system user is one within the system uid range and + # has no expiration + useradd -r "$1" +} + +if ! user_check "kibana" ; then + user_create "kibana" +fi +chown kibana /opt/kibana/optimize diff --git a/tasks/build/package_scripts/post_remove.sh b/tasks/build/package_scripts/post_remove.sh new file mode 100644 index 000000000000..7dd25450bdaf --- /dev/null +++ b/tasks/build/package_scripts/post_remove.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +user_check() { + getent passwd "$1" > /dev/null 2>&1 +} + +user_remove() { + userdel "$1" +} + +case $1 in + purge|0) + if user_check "kibana" ; then + user_remove "kibana" + fi + ;; +esac diff --git a/tasks/build/package_scripts/pre_remove.sh b/tasks/build/package_scripts/pre_remove.sh new file mode 100644 index 000000000000..b184bc6ce643 --- /dev/null +++ b/tasks/build/package_scripts/pre_remove.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +echo -n "Stopping kibana service..." +if command -v systemctl >/dev/null; then + systemctl --no-reload stop kibana.service +fi +if [ -x /etc/init.d/kibana ]; then + if command -v invoke-rc.d >/dev/null; then + invoke-rc.d kibana stop + else + /etc/init.d/kibana stop + fi +fi +echo " OK" diff --git a/tasks/build/pleaserun.js b/tasks/build/pleaserun.js index 9f99955ad9ca..8b8444235a9d 100644 --- a/tasks/build/pleaserun.js +++ b/tasks/build/pleaserun.js @@ -2,7 +2,6 @@ module.exports = function createServices(grunt) { const { resolve } = require('path'); const { appendFileSync } = require('fs'); const exec = require('../utils/exec'); - const userScriptsDir = grunt.config.get('userScriptsDir'); grunt.registerTask('_build:pleaseRun', function () { // TODO(sissel): Detect if 'pleaserun' is found, and provide a useful error @@ -23,9 +22,5 @@ module.exports = function createServices(grunt) { '/opt/kibana/bin/kibana' ]); }); - - grunt.file.mkdir(userScriptsDir); - exec('please-manage-user', ['--output', userScriptsDir, 'kibana']); - appendFileSync(resolve(userScriptsDir, 'installer.sh'), 'chown kibana:kibana /opt/kibana/optimize'); }); };