2018-02-14 01:49:53 -05:00
/ *
* Licensed to Elasticsearch under one or more contributor
* license agreements . See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership . Elasticsearch licenses this file to you under
* the Apache License , Version 2.0 ( the "License" ) ; you may
* not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http: //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing ,
* software distributed under the License is distributed on an
* "AS IS" BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND , either express or implied . See the License for the
* /
2018-02-21 20:46:40 -05:00
import org.elasticsearch.gradle.LoggedExec
2018-02-14 01:49:53 -05:00
import org.elasticsearch.gradle.MavenFilteringHack
2019-10-21 10:09:12 -04:00
import org.elasticsearch.gradle.OS
2020-01-27 16:48:40 -05:00
import org.elasticsearch.gradle.info.BuildParams
import org.redline_rpm.header.Flags
2018-02-14 01:49:53 -05:00
2018-04-24 12:10:51 -04:00
import java.nio.file.Files
import java.nio.file.Path
import java.util.regex.Matcher
import java.util.regex.Pattern
2018-02-14 01:49:53 -05:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Deb and rpm configuration *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
2018-02-21 20:46:40 -05:00
* The general strategy here is to build a directory on disk that contains
* stuff that needs to be copied into the distributions . This is
2018-02-14 01:49:53 -05:00
* important for two reasons:
* 1 . ospackage wants to copy the directory permissions that it sees off of the
* filesystem . If you ask it to create a directory that doesn ' t already
* exist on disk it petulantly creates it with 0755 permissions , no matter
* how hard you try to convince it otherwise .
* 2 . Convincing ospackage to pick up an empty directory as part of a set of
* directories on disk is reasonably easy . Convincing it to just create an
* empty directory requires more wits than I have .
* 3 . ospackage really wants to suck up some of the debian control scripts
* directly from the filesystem . It doesn ' t want to process them through
* MavenFilteringHack or any other copy - style action .
*
* The following commands are useful when it comes to check the user / group
* and files permissions set within the RPM and DEB packages:
*
* rpm - qlp - - dump path /to/ elasticsearch . rpm
* dpkg - c path /to/ elasticsearch . deb
* /
2019-12-09 14:34:35 -05:00
plugins {
id "nebula.ospackage-base" version "8.0.3"
2018-02-14 01:49:53 -05:00
}
2019-03-29 08:24:52 -04:00
void addProcessFilesTask ( String type , boolean oss , boolean jdk ) {
String packagingFiles = "build/packaging/${oss ? 'oss-' : ''}${jdk ? '' : 'no-jdk-'}${type}"
2018-02-21 20:46:40 -05:00
2019-03-29 08:24:52 -04:00
String taskName = "process${oss ? 'Oss' : ''}${jdk ? '' : 'NoJdk'}${type.capitalize()}Files"
2019-03-15 03:55:15 -04:00
task ( taskName , type: Copy ) {
2018-02-14 01:49:53 -05:00
into packagingFiles
2018-02-23 11:03:17 -05:00
with copySpec {
from 'src/common'
from "src/${type}"
2019-03-29 08:24:52 -04:00
MavenFilteringHack . filter ( it , expansionsForDistribution ( type , oss , jdk ) )
2018-02-21 20:46:40 -05:00
}
2018-02-14 01:49:53 -05:00
2019-01-15 13:19:32 -05:00
into ( 'etc/elasticsearch' ) {
2019-03-29 08:24:52 -04:00
with configFiles ( type , oss , jdk )
2018-02-23 11:03:17 -05:00
}
2019-03-29 08:24:52 -04:00
MavenFilteringHack . filter ( it , expansionsForDistribution ( type , oss , jdk ) )
2018-02-14 01:49:53 -05:00
2018-02-21 20:46:40 -05:00
doLast {
// create empty dirs, we set the permissions when configuring the packages
mkdir "${packagingFiles}/var/log/elasticsearch"
mkdir "${packagingFiles}/var/lib/elasticsearch"
mkdir "${packagingFiles}/usr/share/elasticsearch/plugins"
2019-01-25 11:11:48 -05:00
// bare empty dir for /etc/elasticsearch
mkdir "${packagingFiles}/elasticsearch"
2018-02-21 20:46:40 -05:00
}
2018-02-14 01:49:53 -05:00
}
2018-02-21 20:46:40 -05:00
}
2019-11-14 06:01:23 -05:00
2019-03-29 08:24:52 -04:00
addProcessFilesTask ( 'deb' , true , true )
addProcessFilesTask ( 'deb' , true , false )
addProcessFilesTask ( 'deb' , false , true )
addProcessFilesTask ( 'deb' , false , false )
addProcessFilesTask ( 'rpm' , true , true )
addProcessFilesTask ( 'rpm' , true , false )
addProcessFilesTask ( 'rpm' , false , true )
addProcessFilesTask ( 'rpm' , false , false )
2018-02-14 01:49:53 -05:00
2018-02-21 20:46:40 -05:00
// Common configuration that is package dependent. This can't go in ospackage
// since we have different templated files that need to be consumed, but the structure
// is the same
2019-03-15 03:55:15 -04:00
Closure commonPackageConfig ( String type , boolean oss , boolean jdk ) {
2018-02-21 20:46:40 -05:00
return {
2019-10-21 10:09:12 -04:00
onlyIf {
OS . current ( ) . equals ( OS . WINDOWS ) = = false
}
2019-03-29 08:24:52 -04:00
dependsOn "process${oss ? 'Oss' : ''}${jdk ? '' : 'NoJdk'}${type.capitalize()}Files"
2018-02-23 11:03:17 -05:00
packageName "elasticsearch${oss ? '-oss' : ''}"
2019-11-14 06:01:23 -05:00
arch ( type = = 'deb' ? 'amd64' : 'X86_64' )
2018-02-21 20:46:40 -05:00
// Follow elasticsearch's file naming convention
2019-03-15 03:55:15 -04:00
String jdkString = jdk ? "" : "no-jdk-"
String prefix = "${oss ? 'oss-' : ''}${jdk ? '' : 'no-jdk-'}${type}"
2018-02-23 11:03:17 -05:00
destinationDir = file ( "${prefix}/build/distributions" )
2019-12-09 14:34:35 -05:00
// SystemPackagingTask overrides default archive task convention mappings, but doesn't provide a setter so we have to override the convention mapping itself
conventionMapping . archiveFile = { objects . fileProperty ( ) . fileValue ( file ( "${destinationDir}/${packageName}-${project.version}-${jdkString}${archString}.${type}" ) ) }
2019-03-29 08:24:52 -04:00
String packagingFiles = "build/packaging/${oss ? 'oss-' : ''}${jdk ? '' : 'no-jdk-'}${type}"
2018-02-14 01:49:53 -05:00
String scripts = "${packagingFiles}/scripts"
preInstall file ( "${scripts}/preinst" )
postInstall file ( "${scripts}/postinst" )
preUninstall file ( "${scripts}/prerm" )
postUninstall file ( "${scripts}/postrm" )
2018-03-17 07:48:40 -04:00
if ( type = = 'rpm' ) {
postTrans file ( "${scripts}/posttrans" )
}
2018-02-14 01:49:53 -05:00
2018-02-21 20:46:40 -05:00
// top level "into" directive is not inherited from ospackage for some reason, so we must
// specify it again explicitly for copying common files
into ( '/usr/share/elasticsearch' ) {
into ( 'bin' ) {
2019-03-29 08:24:52 -04:00
with binFiles ( type , oss , jdk )
2018-02-21 20:46:40 -05:00
}
2018-04-10 16:58:49 -04:00
from ( rootProject . projectDir ) {
2019-12-19 15:56:06 -05:00
include 'README.asciidoc'
2018-05-23 23:15:19 -04:00
fileMode 0644
2018-04-10 16:58:49 -04:00
}
2018-05-25 07:56:35 -04:00
into ( 'lib' ) {
2018-07-23 14:28:24 -04:00
with libFiles ( oss )
2018-05-25 07:56:35 -04:00
}
2018-02-23 11:03:17 -05:00
into ( 'modules' ) {
2019-04-19 14:34:16 -04:00
with modulesFiles ( oss , 'linux' )
2018-07-23 14:28:24 -04:00
}
2019-03-15 03:55:15 -04:00
if ( jdk ) {
into ( 'jdk' ) {
2019-05-08 10:16:13 -04:00
with jdkFiles ( project , 'linux' )
2019-03-15 03:55:15 -04:00
}
2019-03-08 14:04:18 -05:00
}
2018-07-23 14:28:24 -04:00
// we need to specify every intermediate directory in these paths so the package managers know they are explicitly
// intended to manage them; otherwise they may be left behind on uninstallation. duplicate calls of the same
// directory are fine
eachFile { FileCopyDetails fcp - >
String [ ] segments = fcp . relativePath . segments
for ( int i = segments . length - 2 ; i > 2 ; - - i ) {
2019-12-09 14:34:35 -05:00
if ( type = = 'rpm' ) {
directory ( '/' + segments [ 0 . . i ] . join ( '/' ) , 0755 )
}
2019-03-07 13:53:44 -05:00
if ( segments [ - 2 ] = = 'bin' | | segments [ - 1 ] = = 'jspawnhelper' ) {
2018-07-23 14:28:24 -04:00
fcp . mode = 0755
} else {
fcp . mode = 0644
2018-02-23 11:03:17 -05:00
}
}
}
2018-02-14 01:49:53 -05:00
}
2018-04-24 12:10:51 -04:00
// license files
if ( type = = 'deb' ) {
into ( "/usr/share/doc/${packageName}" ) {
from "${packagingFiles}/copyright"
fileMode 0644
}
} else {
assert type = = 'rpm'
into ( '/usr/share/elasticsearch' ) {
from ( rootProject . file ( 'licenses' ) ) {
include oss ? 'APACHE-LICENSE-2.0.txt' : 'ELASTIC-LICENSE.txt'
rename { 'LICENSE.txt' }
}
2018-05-23 23:15:19 -04:00
fileMode 0644
2018-04-24 12:10:51 -04:00
}
}
2018-02-21 20:46:40 -05:00
// ========= config files =========
2018-02-14 01:49:53 -05:00
configurationFile '/etc/elasticsearch/elasticsearch.yml'
configurationFile '/etc/elasticsearch/jvm.options'
configurationFile '/etc/elasticsearch/log4j2.properties'
2018-11-30 08:16:23 -05:00
if ( oss = = false ) {
configurationFile '/etc/elasticsearch/role_mapping.yml'
configurationFile '/etc/elasticsearch/roles.yml'
configurationFile '/etc/elasticsearch/users'
configurationFile '/etc/elasticsearch/users_roles'
}
2019-11-14 06:01:23 -05:00
from ( "${packagingFiles}" ) {
dirMode 02750
into ( '/etc' )
permissionGroup 'elasticsearch'
includeEmptyDirs true
createDirectoryEntry true
include ( "elasticsearch" ) // empty dir, just to add directory entry
}
from ( "${packagingFiles}/etc/elasticsearch" ) {
into ( '/etc/elasticsearch' )
2019-01-15 13:19:32 -05:00
dirMode 02750
2018-02-14 01:49:53 -05:00
fileMode 0660
permissionGroup 'elasticsearch'
includeEmptyDirs true
createDirectoryEntry true
fileType CONFIG | NOREPLACE
2018-02-21 20:46:40 -05:00
}
2019-03-29 08:24:52 -04:00
String envFile = expansionsForDistribution ( type , oss , jdk ) [ 'path.env' ]
2018-02-21 20:46:40 -05:00
configurationFile envFile
into ( new File ( envFile ) . getParent ( ) ) {
fileType CONFIG | NOREPLACE
2019-01-15 13:19:32 -05:00
permissionGroup 'elasticsearch'
2018-02-21 20:46:40 -05:00
fileMode 0660
from "${packagingFiles}/env/elasticsearch"
2018-02-14 01:49:53 -05:00
}
2018-02-21 20:46:40 -05:00
// ========= systemd =========
2018-02-14 01:49:53 -05:00
into ( '/usr/lib/tmpfiles.d' ) {
from "${packagingFiles}/systemd/elasticsearch.conf"
2018-05-23 23:15:19 -04:00
fileMode 0644
2018-02-14 01:49:53 -05:00
}
into ( '/usr/lib/systemd/system' ) {
fileType CONFIG | NOREPLACE
from "${packagingFiles}/systemd/elasticsearch.service"
2018-05-23 23:15:19 -04:00
fileMode 0644
2018-02-14 01:49:53 -05:00
}
into ( '/usr/lib/sysctl.d' ) {
fileType CONFIG | NOREPLACE
from "${packagingFiles}/systemd/sysctl/elasticsearch.conf"
2018-05-23 23:15:19 -04:00
fileMode 0644
2018-02-14 01:49:53 -05:00
}
Password-protected Keystore Feature Branch PR (#51123) (#51510)
* Reload secure settings with password (#43197)
If a password is not set, we assume an empty string to be
compatible with previous behavior.
Only allow the reload to be broadcast to other nodes if TLS is
enabled for the transport layer.
* Add passphrase support to elasticsearch-keystore (#38498)
This change adds support for keystore passphrases to all subcommands
of the elasticsearch-keystore cli tool and adds a subcommand for
changing the passphrase of an existing keystore.
The work to read the passphrase in Elasticsearch when
loading, which will be addressed in a different PR.
Subcommands of elasticsearch-keystore can handle (open and create)
passphrase protected keystores
When reading a keystore, a user is only prompted for a passphrase
only if the keystore is passphrase protected.
When creating a keystore, a user is allowed (default behavior) to create one with an
empty passphrase
Passphrase can be set to be empty when changing/setting it for an
existing keystore
Relates to: #32691
Supersedes: #37472
* Restore behavior for force parameter (#44847)
Turns out that the behavior of `-f` for the add and add-file sub
commands where it would also forcibly create the keystore if it
didn't exist, was by design - although undocumented.
This change restores that behavior auto-creating a keystore that
is not password protected if the force flag is used. The force
OptionSpec is moved to the BaseKeyStoreCommand as we will presumably
want to maintain the same behavior in any other command that takes
a force option.
* Handle pwd protected keystores in all CLI tools (#45289)
This change ensures that `elasticsearch-setup-passwords` and
`elasticsearch-saml-metadata` can handle a password protected
elasticsearch.keystore.
For setup passwords the user would be prompted to add the
elasticsearch keystore password upon running the tool. There is no
option to pass the password as a parameter as we assume the user is
present in order to enter the desired passwords for the built-in
users.
For saml-metadata, we prompt for the keystore password at all times
even though we'd only need to read something from the keystore when
there is a signing or encryption configuration.
* Modify docs for setup passwords and saml metadata cli (#45797)
Adds a sentence in the documentation of `elasticsearch-setup-passwords`
and `elasticsearch-saml-metadata` to describe that users would be
prompted for the keystore's password when running these CLI tools,
when the keystore is password protected.
Co-Authored-By: Lisa Cawley <lcawley@elastic.co>
* Elasticsearch keystore passphrase for startup scripts (#44775)
This commit allows a user to provide a keystore password on Elasticsearch
startup, but only prompts when the keystore exists and is encrypted.
The entrypoint in Java code is standard input. When the Bootstrap class is
checking for secure keystore settings, it checks whether or not the keystore
is encrypted. If so, we read one line from standard input and use this as the
password. For simplicity's sake, we allow a maximum passphrase length of 128
characters. (This is an arbitrary limit and could be increased or eliminated.
It is also enforced in the keystore tools, so that a user can't create a
password that's too long to enter at startup.)
In order to provide a password on standard input, we have to account for four
different ways of starting Elasticsearch: the bash startup script, the Windows
batch startup script, systemd startup, and docker startup. We use wrapper
scripts to reduce systemd and docker to the bash case: in both cases, a
wrapper script can read a passphrase from the filesystem and pass it to the
bash script.
In order to simplify testing the need for a passphrase, I have added a
has-passwd command to the keystore tool. This command can run silently, and
exit with status 0 when the keystore has a password. It exits with status 1 if
the keystore doesn't exist or exists and is unencrypted.
A good deal of the code-change in this commit has to do with refactoring
packaging tests to cleanly use the same tests for both the "archive" and the
"package" cases. This required not only moving tests around, but also adding
some convenience methods for an abstraction layer over distribution-specific
commands.
* Adjust docs for password protected keystore (#45054)
This commit adds relevant parts in the elasticsearch-keystore
sub-commands reference docs and in the reload secure settings API
doc.
* Fix failing Keystore Passphrase test for feature branch (#50154)
One problem with the passphrase-from-file tests, as written, is that
they would leave a SystemD environment variable set when they failed,
and this setting would cause elasticsearch startup to fail for other
tests as well. By using a try-finally, I hope that these tests will fail
more gracefully.
It appears that our Fedora and Ubuntu environments may be configured to
store journald information under /var rather than under /run, so that it
will persist between boots. Our destructive tests that read from the
journal need to account for this in order to avoid trying to limit the
output we check in tests.
* Run keystore management tests on docker distros (#50610)
* Add Docker handling to PackagingTestCase
Keystore tests need to be able to run in the Docker case. We can do this
by using a DockerShell instead of a plain Shell when Docker is running.
* Improve ES startup check for docker
Previously we were checking truncated output for the packaged JDK as
an indication that Elasticsearch had started. With new preliminary
password checks, we might get a false positive from ES keystore
commands, so we have to check specifically that the Elasticsearch
class from the Bootstrap package is what's running.
* Test password-protected keystore with Docker (#50803)
This commit adds two tests for the case where we mount a
password-protected keystore into a Docker container and provide a
password via a Docker environment variable.
We also fix a logging bug where we were logging the identifier for an
array of strings rather than the contents of that array.
* Add documentation for keystore startup prompting (#50821)
When a keystore is password-protected, Elasticsearch will prompt at
startup. This commit adds documentation for this prompt for the archive,
systemd, and Docker cases.
Co-authored-by: Lisa Cawley <lcawley@elastic.co>
* Warn when unable to upgrade keystore on debian (#51011)
For Red Hat RPM upgrades, we warn if we can't upgrade the keystore. This
commit brings the same logic to the code for Debian packages. See the
posttrans file for gets executed for RPMs.
* Restore handling of string input
Adds tests that were mistakenly removed. One of these tests proved
we were not handling the the stdin (-x) option correctly when no
input was added. This commit restores the original approach of
reading stdin one char at a time until there is no more (-1, \r, \n)
instead of using readline() that might return null
* Apply spotless reformatting
* Use '--since' flag to get recent journal messages
When we get Elasticsearch logs from journald, we want to fetch only log
messages from the last run. There are two reasons for this. First, if
there are many logs, we might get a string that's too large for our
utility methods. Second, when we're looking for a specific message or
error, we almost certainly want to look only at messages from the last
execution.
Previously, we've been trying to do this by clearing out the physical
files under the journald process. But there seems to be some contention
over these directories: if journald writes a log file in between when
our deletion command deletes the file and when it deletes the log
directory, the deletion will fail.
It seems to me that we might be able to use journald's "--since" flag to
retrieve only log messages from the last run, and that this might be
less likely to fail due to race conditions in file deletion.
Unfortunately, it looks as if the "--since" flag has a granularity of
one-second. I've added a two-second sleep to make sure that there's a
sufficient gap between the test that will read from journald and the
test before it.
* Use new journald wrapper pattern
* Update version added in secure settings request
Co-authored-by: Lisa Cawley <lcawley@elastic.co>
Co-authored-by: Ioannis Kakavas <ikakavas@protonmail.com>
2020-01-28 05:32:32 -05:00
into ( '/usr/share/elasticsearch/bin' ) {
from "${packagingFiles}/systemd/systemd-entrypoint"
fileMode 0755
}
2018-02-21 20:46:40 -05:00
// ========= sysV init =========
2018-02-14 01:49:53 -05:00
configurationFile '/etc/init.d/elasticsearch'
into ( '/etc/init.d' ) {
fileMode 0750
fileType CONFIG | NOREPLACE
from "${packagingFiles}/init.d/elasticsearch"
}
2018-02-21 20:46:40 -05:00
// ========= empty dirs =========
// NOTE: these are created under packagingFiles as empty, but the permissions are set here
Closure copyEmptyDir = { path , u , g , mode - >
File file = new File ( path )
into ( file . parent ) {
2018-02-22 14:30:49 -05:00
from "${packagingFiles}/${file.parent}"
2018-02-21 20:46:40 -05:00
include file . name
2018-02-14 01:49:53 -05:00
includeEmptyDirs true
createDirectoryEntry true
user u
permissionGroup g
dirMode mode
}
}
2019-01-15 13:19:32 -05:00
copyEmptyDir ( '/var/log/elasticsearch' , 'elasticsearch' , 'elasticsearch' , 02750 )
copyEmptyDir ( '/var/lib/elasticsearch' , 'elasticsearch' , 'elasticsearch' , 02750 )
2018-02-21 20:46:40 -05:00
copyEmptyDir ( '/usr/share/elasticsearch/plugins' , 'root' , 'root' , 0755 )
2018-03-22 18:20:46 -04:00
// the oss package conflicts with the default distribution and vice versa
conflicts ( 'elasticsearch' + ( oss ? '' : '-oss' ) )
2019-03-29 17:20:53 -04:00
into '/usr/share/elasticsearch'
with noticeFile ( oss , jdk )
2018-02-21 20:46:40 -05:00
}
}
apply plugin: 'nebula.ospackage-base'
// this is package indepdendent configuration
ospackage {
maintainer 'Elasticsearch Team <info@elastic.co>'
2019-05-08 15:09:02 -04:00
summary 'Distributed RESTful search engine built for the cloud'
packageDescription '' '
2018-02-21 20:46:40 -05:00
Reference documentation can be found at
https: //www.elastic.co/guide/en/elasticsearch/reference/current/index.html
and the 'Elasticsearch: The Definitive Guide' book can be found at
https: //www.elastic.co/guide/en/elasticsearch/guide/current/index.html
2019-05-08 15:09:02 -04:00
'' ' . stripIndent ( ) . trim ( )
2018-02-21 20:46:40 -05:00
url 'https://www.elastic.co/'
// signing setup
2020-01-27 16:48:40 -05:00
if ( project . hasProperty ( 'signing.password' ) & & BuildParams . isSnapshotBuild ( ) = = false ) {
2018-02-21 20:46:40 -05:00
signingKeyId = project . hasProperty ( 'signing.keyId' ) ? project . property ( 'signing.keyId' ) : 'D88E42B4'
signingKeyPassphrase = project . property ( 'signing.password' )
signingKeyRingFile = project . hasProperty ( 'signing.secretKeyRingFile' ) ?
2019-11-14 06:01:23 -05:00
project . file ( project . property ( 'signing.secretKeyRingFile' ) ) :
new File ( new File ( System . getProperty ( 'user.home' ) , '.gnupg' ) , 'secring.gpg' )
2018-02-21 20:46:40 -05:00
}
2019-05-08 15:09:02 -04:00
// version found on oldest supported distro, centos-6
requires ( 'coreutils' , '8.4' , GREATER | EQUAL )
2018-02-21 20:46:40 -05:00
fileMode 0644
dirMode 0755
user 'root'
permissionGroup 'root'
into '/usr/share/elasticsearch'
}
2019-03-15 03:55:15 -04:00
Closure commonDebConfig ( boolean oss , boolean jdk ) {
2018-02-23 11:03:17 -05:00
return {
2019-03-15 03:55:15 -04:00
configure ( commonPackageConfig ( 'deb' , oss , jdk ) )
2018-02-21 20:46:40 -05:00
2018-04-23 20:24:23 -04:00
// jdeb does not provide a way to set the License control attribute, and ospackage
// silently ignores setting it. Instead, we set the license as "custom field"
2018-04-09 18:20:01 -04:00
if ( oss ) {
2018-04-23 20:24:23 -04:00
customFields [ 'License' ] = 'ASL-2.0'
2018-04-09 18:20:01 -04:00
} else {
2018-04-23 20:24:23 -04:00
customFields [ 'License' ] = 'Elastic-License'
2018-04-09 18:20:01 -04:00
}
2018-04-26 14:51:48 -04:00
version = project . version . replace ( '-' , '~' )
2018-02-23 11:03:17 -05:00
packageGroup 'web'
2019-05-08 15:09:02 -04:00
// versions found on oldest supported distro, centos-6
requires ( 'bash' , '4.1' , GREATER | EQUAL )
requires ( 'lsb-base' , '4' , GREATER | EQUAL )
2018-02-23 11:03:17 -05:00
requires 'libc6'
requires 'adduser'
2018-02-21 20:46:40 -05:00
2018-02-23 11:03:17 -05:00
into ( '/usr/share/lintian/overrides' ) {
from ( 'src/deb/lintian/elasticsearch' )
2019-05-08 15:09:02 -04:00
if ( oss ) {
rename ( 'elasticsearch' , 'elasticsearch-oss' )
}
2018-02-23 11:03:17 -05:00
}
2018-02-21 20:46:40 -05:00
}
}
2018-02-23 11:03:17 -05:00
task buildDeb ( type: Deb ) {
2019-03-15 03:55:15 -04:00
configure ( commonDebConfig ( false , true ) )
2018-02-23 11:03:17 -05:00
}
task buildOssDeb ( type: Deb ) {
2019-03-15 03:55:15 -04:00
configure ( commonDebConfig ( true , true ) )
}
task buildNoJdkDeb ( type: Deb ) {
configure ( commonDebConfig ( false , false ) )
}
task buildOssNoJdkDeb ( type: Deb ) {
configure ( commonDebConfig ( true , false ) )
2018-02-23 11:03:17 -05:00
}
2019-03-15 03:55:15 -04:00
Closure commonRpmConfig ( boolean oss , boolean jdk ) {
2018-02-23 11:03:17 -05:00
return {
2019-03-15 03:55:15 -04:00
configure ( commonPackageConfig ( 'rpm' , oss , jdk ) )
2018-02-23 11:03:17 -05:00
2018-04-09 18:20:01 -04:00
if ( oss ) {
2018-04-23 11:49:54 -04:00
license 'ASL 2.0'
2018-04-09 18:20:01 -04:00
} else {
2018-04-23 11:49:54 -04:00
license 'Elastic License'
2018-04-09 18:20:01 -04:00
}
2018-02-23 11:03:17 -05:00
packageGroup 'Application/Internet'
requires '/bin/bash'
2019-02-28 15:35:23 -05:00
obsoletes packageName , '7.0.0' , Flags . LESS
2018-02-23 11:03:17 -05:00
prefix '/usr'
packager 'Elasticsearch'
version = project . version . replace ( '-' , '_' )
release = '1'
os 'LINUX'
distribution 'Elasticsearch'
vendor 'Elasticsearch'
// TODO ospackage doesn't support icon but we used to have one
// without this the rpm will have parent dirs of any files we copy in, eg /etc/elasticsearch
addParentDirs false
2018-02-21 20:46:40 -05:00
}
}
task buildRpm ( type: Rpm ) {
2019-03-15 03:55:15 -04:00
configure ( commonRpmConfig ( false , true ) )
2018-02-14 01:49:53 -05:00
}
2018-02-23 11:03:17 -05:00
task buildOssRpm ( type: Rpm ) {
2019-03-15 03:55:15 -04:00
configure ( commonRpmConfig ( true , true ) )
}
task buildNoJdkRpm ( type: Rpm ) {
configure ( commonRpmConfig ( false , false ) )
}
task buildOssNoJdkRpm ( type: Rpm ) {
configure ( commonRpmConfig ( true , false ) )
2018-02-21 20:46:40 -05:00
}
2018-04-24 12:10:51 -04:00
Closure dpkgExists = { it - > new File ( '/bin/dpkg-deb' ) . exists ( ) | | new File ( '/usr/bin/dpkg-deb' ) . exists ( ) | | new File ( '/usr/local/bin/dpkg-deb' ) . exists ( ) }
Closure rpmExists = { it - > new File ( '/bin/rpm' ) . exists ( ) | | new File ( '/usr/bin/rpm' ) . exists ( ) | | new File ( '/usr/local/bin/rpm' ) . exists ( ) }
Closure debFilter = { f - > f . name . endsWith ( '.deb' ) }
2018-02-21 20:46:40 -05:00
// This configures the default artifact for the distribution specific
// subprojects. We have subprojects because Gradle project substitutions
// can only bind to the default configuration of a project
subprojects {
apply plugin: 'distribution'
String buildTask = "build${it.name.replaceAll(/-[a-z]/) { it.substring(1).toUpperCase() }.capitalize()}"
ext . buildDist = parent . tasks . getByName ( buildTask )
artifacts {
'default' buildDist
}
2019-09-27 02:03:15 -04:00
if ( dpkgExists ( ) | | rpmExists ( ) ) {
// sanity checks if packages can be extracted
final File extractionDir = new File ( buildDir , 'extracted' )
File packageExtractionDir
if ( project . name . contains ( 'deb' ) ) {
packageExtractionDir = new File ( extractionDir , 'deb-extracted' )
} else {
assert project . name . contains ( 'rpm' )
packageExtractionDir = new File ( extractionDir , 'rpm-extracted' )
2018-02-23 11:03:17 -05:00
}
2019-09-27 02:03:15 -04:00
task checkExtraction ( type: LoggedExec ) {
dependsOn buildDist
doFirst {
project . delete ( extractionDir )
extractionDir . mkdirs ( )
}
2018-02-23 11:03:17 -05:00
}
2019-09-27 02:03:15 -04:00
check . dependsOn checkExtraction
if ( project . name . contains ( 'deb' ) ) {
checkExtraction {
onlyIf dpkgExists
commandLine 'dpkg-deb' , '-x' , "${-> buildDist.outputs.files.filter(debFilter).singleFile}" , packageExtractionDir
}
} else {
assert project . name . contains ( 'rpm' )
checkExtraction {
onlyIf rpmExists
final File rpmDatabase = new File ( extractionDir , 'rpm-database' )
commandLine 'rpm' ,
2019-11-14 06:01:23 -05:00
'--badreloc' ,
'--nodeps' ,
'--noscripts' ,
'--notriggers' ,
'--dbpath' ,
rpmDatabase ,
'--relocate' ,
"/=${packageExtractionDir}" ,
'-i' ,
"${-> buildDist.outputs.files.singleFile}"
2019-09-27 02:03:15 -04:00
}
2018-02-23 11:03:17 -05:00
}
2018-04-24 12:10:51 -04:00
2019-09-27 02:03:15 -04:00
task checkLicense {
dependsOn buildDist , checkExtraction
}
check . dependsOn checkLicense
if ( project . name . contains ( 'deb' ) ) {
checkLicense {
onlyIf dpkgExists
doLast {
Path copyrightPath
String expectedLicense
String licenseFilename
if ( project . name . contains ( 'oss-' ) ) {
copyrightPath = packageExtractionDir . toPath ( ) . resolve ( "usr/share/doc/elasticsearch-oss/copyright" )
expectedLicense = "ASL-2.0"
licenseFilename = "APACHE-LICENSE-2.0.txt"
} else {
copyrightPath = packageExtractionDir . toPath ( ) . resolve ( "usr/share/doc/elasticsearch/copyright" )
expectedLicense = "Elastic-License"
licenseFilename = "ELASTIC-LICENSE.txt"
}
final List < String > header = Arrays . asList ( "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/" ,
2019-11-14 06:01:23 -05:00
"Copyright: Elasticsearch B.V. <info@elastic.co>" ,
"License: " + expectedLicense )
2019-09-27 02:03:15 -04:00
final List < String > licenseLines = Files . readAllLines ( rootDir . toPath ( ) . resolve ( "licenses/" + licenseFilename ) )
final List < String > expectedLines = header + licenseLines . collect { " " + it }
assertLinesInFile ( copyrightPath , expectedLines )
2018-04-24 12:10:51 -04:00
}
}
2019-09-27 02:03:15 -04:00
} else {
assert project . name . contains ( 'rpm' )
checkLicense {
onlyIf rpmExists
doLast {
String licenseFilename
if ( project . name . contains ( 'oss-' ) ) {
licenseFilename = "APACHE-LICENSE-2.0.txt"
} else {
licenseFilename = "ELASTIC-LICENSE.txt"
}
final List < String > licenseLines = Files . readAllLines ( rootDir . toPath ( ) . resolve ( "licenses/" + licenseFilename ) )
final Path licensePath = packageExtractionDir . toPath ( ) . resolve ( "usr/share/elasticsearch/LICENSE.txt" )
assertLinesInFile ( licensePath , licenseLines )
2018-04-24 12:10:51 -04:00
}
}
}
2019-09-27 02:03:15 -04:00
task checkNotice {
dependsOn buildDist , checkExtraction
onlyIf {
( project . name . contains ( 'deb' ) & & dpkgExists . call ( it ) ) | | ( project . name . contains ( 'rpm' ) & & rpmExists . call ( it ) )
}
doLast {
final List < String > noticeLines = Arrays . asList ( "Elasticsearch" , "Copyright 2009-2018 Elasticsearch" )
final Path noticePath = packageExtractionDir . toPath ( ) . resolve ( "usr/share/elasticsearch/NOTICE.txt" )
assertLinesInFile ( noticePath , noticeLines )
}
2018-04-24 12:10:51 -04:00
}
2019-09-27 02:03:15 -04:00
check . dependsOn checkNotice
2018-04-24 12:10:51 -04:00
2019-09-27 02:03:15 -04:00
task checkLicenseMetadata ( type: LoggedExec ) {
dependsOn buildDist , checkExtraction
}
check . dependsOn checkLicenseMetadata
if ( project . name . contains ( 'deb' ) ) {
checkLicenseMetadata { LoggedExec exec - >
onlyIf dpkgExists
final ByteArrayOutputStream output = new ByteArrayOutputStream ( )
exec . commandLine 'dpkg-deb' , '--info' , "${-> buildDist.outputs.files.filter(debFilter).singleFile}"
exec . standardOutput = output
doLast {
String expectedLicense
if ( project . name . contains ( 'oss-' ) ) {
expectedLicense = "ASL-2.0"
} else {
expectedLicense = "Elastic-License"
}
final Pattern pattern = Pattern . compile ( "\\s*License: (.+)" )
final String info = output . toString ( 'UTF-8' )
final String [ ] actualLines = info . split ( "\n" )
int count = 0
for ( final String actualLine : actualLines ) {
final Matcher matcher = pattern . matcher ( actualLine )
if ( matcher . matches ( ) ) {
count + +
final String actualLicense = matcher . group ( 1 )
if ( expectedLicense ! = actualLicense ) {
throw new GradleException ( "expected license [${expectedLicense} for package info but found [${actualLicense}]" )
}
2018-04-24 12:10:51 -04:00
}
}
2019-09-27 02:03:15 -04:00
if ( count = = 0 ) {
throw new GradleException ( "expected license [${expectedLicense}] for package info but found none in:\n${info}" )
}
if ( count > 1 ) {
throw new GradleException ( "expected a single license for package info but found [${count}] in:\n${info}" )
}
2018-04-24 12:10:51 -04:00
}
}
2019-09-27 02:03:15 -04:00
} else {
assert project . name . contains ( 'rpm' )
checkLicenseMetadata { LoggedExec exec - >
onlyIf rpmExists
final ByteArrayOutputStream output = new ByteArrayOutputStream ( )
exec . commandLine 'rpm' , '-qp' , '--queryformat' , '%{License}' , "${-> buildDist.outputs.files.singleFile}"
exec . standardOutput = output
doLast {
String license = output . toString ( 'UTF-8' )
String expectedLicense
if ( project . name . contains ( 'oss-' ) ) {
expectedLicense = "ASL 2.0"
} else {
expectedLicense = "Elastic License"
}
if ( license ! = expectedLicense ) {
throw new GradleException ( "expected license [${expectedLicense}] for [${-> buildDist.outputs.files.singleFile}] but was [${license}]" )
}
2018-04-24 12:10:51 -04:00
}
}
}
}
2018-02-23 11:03:17 -05:00
}