From 0a466352cd5c7deb262de6b1c84237ecc311c9f1 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Mon, 11 Mar 2013 08:54:24 +0100 Subject: [PATCH] Add support for creating a fedora RPM package with maven Note: This has been disabled by default and is therefore not included in a standard build. The main reason for this is, that you need to have a RPM binary and the rpm development packages installed, which is not the case on many systems. The package contains an init.d-script as well as systemd configurations. You can build your own RPM package simply by running 'maven rpm:rpm' --- pom.xml | 180 ++++++++++++++++++++++++++ src/rpm/init.d/elasticsearch | 136 +++++++++++++++++++ src/rpm/scripts/postinstall | 17 +++ src/rpm/scripts/postremove | 13 ++ src/rpm/scripts/preinstall | 4 + src/rpm/scripts/preremove | 16 +++ src/rpm/sysconfig/elasticsearch | 40 ++++++ src/rpm/systemd/elasticsearch.conf | 1 + src/rpm/systemd/elasticsearch.service | 14 ++ 9 files changed, 421 insertions(+) create mode 100644 src/rpm/init.d/elasticsearch create mode 100644 src/rpm/scripts/postinstall create mode 100644 src/rpm/scripts/postremove create mode 100644 src/rpm/scripts/preinstall create mode 100644 src/rpm/scripts/preremove create mode 100644 src/rpm/sysconfig/elasticsearch create mode 100644 src/rpm/systemd/elasticsearch.conf create mode 100644 src/rpm/systemd/elasticsearch.service diff --git a/pom.xml b/pom.xml index 5c60b80c8e4..c6b08b93bfe 100644 --- a/pom.xml +++ b/pom.xml @@ -612,6 +612,186 @@ + + org.codehaus.mojo + rpm-maven-plugin + 2.1-alpha-2 + + 2013, Elasticsearch + Elasticsearch + Application/Internet + Elasticsearch + /usr + src/changelog + + _unpackaged_files_terminate_build 0 + _binaries_in_noarch_packages_terminate_build 0 + + 644 + 755 + root + root + + + /etc/elasticsearch/ + true + + + /etc/elasticsearch/ + true + + + config/ + + *.yml + + + + + + /etc/sysconfig/ + true + + + src/rpm/sysconfig + + elasticsearch + + + + + + /etc/rc.d/init.d/ + 755 + true + + + src/rpm/init.d/elasticsearch + + + + + /etc/systemd/system/ + 755 + true + + + src/rpm/systemd + + elasticsearch.service + + + + + + /etc/tmpfiles.d/ + true + + + src/rpm/systemd/ + + elasticsearch.conf + + + + + + /var/run/elasticsearch/ + 755 + elasticsearch + elasticsearch + + + /var/lib/elasticsearch/ + 755 + elasticsearch + elasticsearch + + + /var/log/elasticsearch/ + 755 + elasticsearch + elasticsearch + + + /usr/share/elasticsearch/bin/ + 755 + + + target/bin + + elasticsearch + elasticsearch.in.sh + plugin + + + + + + /usr/share/elasticsearch/lib + + + target/lib/ + + lucene* + log4j* + jna* + spatial4j* + jts* + + + + ${project.build.directory}/ + + ${project.build.finalName}.jar + + + + + + /usr/share/elasticsearch/lib/sigar + + + lib/sigar + + sigar*.jar + libsigar-*-linux.* + + + + + + /usr/share/elasticsearch/ + + + . + + LICENSE.txt + NOTICE.txt + README.textile + + + + + + + src/rpm/scripts/preinstall + utf-8 + + + src/rpm/scripts/postinstall + utf-8 + + + src/rpm/scripts/preremove + utf-8 + + + src/rpm/scripts/postremove + utf-8 + + + diff --git a/src/rpm/init.d/elasticsearch b/src/rpm/init.d/elasticsearch new file mode 100644 index 00000000000..d798450d7f2 --- /dev/null +++ b/src/rpm/init.d/elasticsearch @@ -0,0 +1,136 @@ +#!/bin/sh +# +# elasticsearch +# +# chkconfig: 2345 80 20 +# description: Starts and stops a single elasticsearch instance on this system +# + +### BEGIN INIT INFO +# Provides: Elasticsearch +# Required-Start: $network +# Required-Stop: $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: This service manages the elasticsearch daemon +# Description: Elasticsearch is a very scalable, schema-free and high-performance search solution supporting multi-tenancy and near realtime search. +### END INIT INFO + +# +# init.d / servicectl compatibility (openSUSE) +# +if [ -f /etc/rc.status ]; then + . /etc/rc.status + rc_reset +fi + +# +# Source function library. +# +if [ -f /etc/rc.d/init.d/functions ]; then + . /etc/rc.d/init.d/functions +fi + +exec="/usr/share/elasticsearch/bin/elasticsearch" +prog="elasticsearch" +pidfile=/var/run/elasticsearch/${prog}.pid + +[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog + +export ES_HEAP_SIZE +export ES_HEAP_NEWSIZE +export ES_DIRECT_SIZE +export ES_JAVA_OPTS + +lockfile=/var/lock/subsys/$prog + +start() { + [ -x $exec ] || exit 5 + [ -f $CONF_FILE ] || exit 6 + if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then + echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set" + return 7 + fi + if [ -n "$MAX_OPEN_FILES" ]; then + ulimit -n $MAX_OPEN_FILES + fi + if [ -n "$MAX_LOCKED_MEMORY" ]; then + ulimit -l $MAX_LOCKED_MEMORY + fi + if [ -n "$WORK_DIR" ]; then + mkdir -p "$WORK_DIR" + chown "$ES_USER":"$ES_GROUP" "$WORK_DIR" + fi + echo -n $"Starting $prog: " + # if not running, start it up here, usually something like "daemon $exec" + daemon --user $USER --pidfile $pidfile $exec -p $pidfile -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR -Des.default.path.conf=$CONF_DIR + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() { + echo -n $"Stopping $prog: " + # stop it here, often "killproc $prog" + killproc -p $pidfile $prog + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + stop + start +} + +reload() { + restart +} + +force_reload() { + restart +} + +rh_status() { + # run checks to determine if the service is running or use generic status + status -p $pidfile $prog +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart) + $1 + ;; + reload) + rh_status_q || exit 7 + $1 + ;; + force-reload) + force_reload + ;; + status) + rh_status + ;; + condrestart|try-restart) + rh_status_q || exit 0 + restart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" + exit 2 +esac +exit $? diff --git a/src/rpm/scripts/postinstall b/src/rpm/scripts/postinstall new file mode 100644 index 00000000000..5069201d7f2 --- /dev/null +++ b/src/rpm/scripts/postinstall @@ -0,0 +1,17 @@ +hasBeenEnabledOnStart=false + +if [ $1 -eq 1 ] ; then + # Initial installation + if [ -x /bin/systemctl ] ; then + /bin/systemctl daemon-reload >/dev/null 2>&1 || : + /bin/systemctl enable elasticsearch.service + /bin/systemctl start elasticsearch.service + hasBeenEnabledOnStart=true + fi + + if [ -x /sbin/chkconfig -a "$hasBeenEnabledOnStart" == "false" ] ; then + /sbin/chkconfig --add elasticsearch + /etc/init.d/elasticsearch start + fi + +fi diff --git a/src/rpm/scripts/postremove b/src/rpm/scripts/postremove new file mode 100644 index 00000000000..251b779887d --- /dev/null +++ b/src/rpm/scripts/postremove @@ -0,0 +1,13 @@ +echo "Removing elasticsearch user and group if existing" + +getent passwd elasticsearch > /dev/null +if [ "$?" == "1" ] ; then + userdel elasticsearch +fi + +getent group elasticsearch >/dev/null +if [ "$?" == "1" ] ; then + groupdel elasticsearch +fi + +exit diff --git a/src/rpm/scripts/preinstall b/src/rpm/scripts/preinstall new file mode 100644 index 00000000000..70670ed8036 --- /dev/null +++ b/src/rpm/scripts/preinstall @@ -0,0 +1,4 @@ +getent group elasticsearch >/dev/null || groupadd -r elasticsearch +getent passwd elasticsearch >/dev/null || \ + useradd -r -g elasticsearch -d /usr/lib/elasticsearch -s /sbin/nologin \ + -c "elasticsearch user" elasticsearch diff --git a/src/rpm/scripts/preremove b/src/rpm/scripts/preremove new file mode 100644 index 00000000000..7e012d69b7c --- /dev/null +++ b/src/rpm/scripts/preremove @@ -0,0 +1,16 @@ +if [ $1 -eq 0 ] ; then + # Package removal, not upgrade + if [ -x /bin/systemctl ] ; then + /bin/systemctl --no-reload disable elasticsearch.service > /dev/null 2>&1 || : + /bin/systemctl stop elasticsearch.service > /dev/null 2>&1 || : + fi + + if [ -x /sbin/chkconfig ] ; then + if [ -x /etc/init.d/elasticsearch ] ; then + /etc/init.d/elasticsearch stop + fi + /sbin/chkconfig --del elasticsearch 2> /dev/null + fi +fi + +exit 0 diff --git a/src/rpm/sysconfig/elasticsearch b/src/rpm/sysconfig/elasticsearch new file mode 100644 index 00000000000..64867f1a245 --- /dev/null +++ b/src/rpm/sysconfig/elasticsearch @@ -0,0 +1,40 @@ +# Directory where the ElasticSearch binary distribution resides +ES_HOME=/usr/share/elasticsearch + +# Heap Size (defaults to 256m min, 1g max) +#ES_HEAP_SIZE=2g + +# Heap new generation +#ES_HEAP_NEWSIZE= + +# max direct memory +#ES_DIRECT_SIZE= + +# Additional Java OPTS +#ES_JAVA_OPTS= + +# Maximum number of open files +MAX_OPEN_FILES=65535 + +# Maximum amount of locked memory +#MAX_LOCKED_MEMORY= + +# ElasticSearch log directory +LOG_DIR=/var/log/elasticsearch + +# ElasticSearch data directory +DATA_DIR=/var/lib/elasticsearch + +# ElasticSearch work directory +WORK_DIR=/tmp/elasticsearch + +# ElasticSearch conf directory +CONF_DIR=/etc/elasticsearch + +# ElasticSearch configuration file (elasticsearch.yml) +CONF_FILE=/etc/elasticsearch/elasticsearch.yml + +# User to run as, change this to a specific elasticsearch user if possible +# Also make sure, this user can write into the log directories in case you change them +# This setting only works for the init script, but has to be configured separately for systemd startup +USER=elasticsearch diff --git a/src/rpm/systemd/elasticsearch.conf b/src/rpm/systemd/elasticsearch.conf new file mode 100644 index 00000000000..9db225e74a7 --- /dev/null +++ b/src/rpm/systemd/elasticsearch.conf @@ -0,0 +1 @@ +d /run/elasticsearch 0755 elasticsearch elasticsearch - - diff --git a/src/rpm/systemd/elasticsearch.service b/src/rpm/systemd/elasticsearch.service new file mode 100644 index 00000000000..c68c5054391 --- /dev/null +++ b/src/rpm/systemd/elasticsearch.service @@ -0,0 +1,14 @@ +[Unit] +Description=Starts and stops a single elasticsearch instance on this system +Documentation=http://www.elasticsearch.org + +[Service] +Type=forking +EnvironmentFile=/etc/sysconfig/elasticsearch +User=elasticsearch +Group=elasticsearch +PIDFile=/var/run/elasticsearch/elasticsearch.pid +ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p /var/run/elasticsearch/elasticsearch.pid -Des.default.config=$CONF_FILE -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR -Des.default.path.conf=$CONF_DIR + +[Install] +WantedBy=multi-user.target