deb: add systemd service config for upcoming Jessie

This change adds a systemd service configuration file, and adds systemd logic
to installation and de-installation scripts. The upcoming Debian 8 "Jessie"
release will use systemd.

fixes #8943

Signed-off-by: Thilo Fromm <github@thilo-fromm.de>
This commit is contained in:
Thilo Fromm 2014-12-03 16:37:56 +01:00 committed by Adrien Grand
parent 344bbf2ced
commit 98d18c4bd9
6 changed files with 63 additions and 8 deletions

View File

@ -975,6 +975,11 @@
<group>root</group>
</mapper>
</data>
<data>
<src>${project.basedir}/src/deb/systemd/elasticsearch.service</src>
<dst>/usr/lib/systemd/system/elasticsearch.service</dst>
<type>file</type>
</data>
<data>
<src>${project.basedir}/config</src>
<type>directory</type>

View File

@ -2,3 +2,4 @@
/etc/default/elasticsearch
/etc/elasticsearch/logging.yml
/etc/elasticsearch/elasticsearch.yml
/usr/lib/systemd/system/elasticsearch.service

View File

@ -4,7 +4,10 @@ set -e
[ -f /etc/default/elasticsearch ] && . /etc/default/elasticsearch
startElasticsearch() {
if [ -x "/etc/init.d/elasticsearch" ]; then
if [ -x /bin/systemctl ] ; then
/bin/systemctl daemon-reload
/bin/systemctl start elasticsearch.service
elif [ -x "/etc/init.d/elasticsearch" ]; then
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
invoke-rc.d elasticsearch start || true
else
@ -42,11 +45,20 @@ case "$1" in
startElasticsearch
# this is a fresh installation
elif [ -z $2 ] ; then
if [ -x /bin/systemctl ] ; then
echo "### NOT starting on installation, please execute the following statements to configure elasticsearch to start automatically using systemd"
echo " sudo /bin/systemctl daemon-reload"
echo " sudo /bin/systemctl enable elasticsearch.service"
echo "### You can start elasticsearch by executing"
echo " sudo /bin/systemctl start elasticsearch.service"
elif [ -x /usr/sbin/update-rc.d ] ; then
echo "### NOT starting elasticsearch by default on bootup, please execute"
echo " sudo update-rc.d elasticsearch defaults 95 10"
echo "### In order to start elasticsearch, execute"
echo " sudo /etc/init.d/elasticsearch start"
fi
fi
;;
esac

View File

@ -6,13 +6,22 @@ case "$1" in
# Remove logs
rm -rf /var/log/elasticsearch
# disable elasticsearch service on systemd systems
if [ -x /bin/systemctl ] ; then
/bin/systemctl --no-reload disable elasticsearch.service > /dev/null 2>&1 || :
fi
# remove **only** empty data dir
rmdir --ignore-fail-on-non-empty /var/lib/elasticsearch
;;
purge)
# Remove service
# disable elasticsearch service on systemd systems
if [ -x /bin/systemctl ] ; then
/bin/systemctl --no-reload disable elasticsearch.service > /dev/null 2>&1 || :
else
update-rc.d elasticsearch remove >/dev/null || true
fi
# Remove logs and data
rm -rf /var/log/elasticsearch /var/lib/elasticsearch

View File

@ -4,7 +4,9 @@ set -e
[ -f /etc/default/elasticsearch ] && . /etc/default/elasticsearch
stopElasticsearch() {
if [ -x "/etc/init.d/elasticsearch" ]; then
if [ -x /bin/systemctl ] ; then
/bin/systemctl --no-reload stop elasticsearch.service > /dev/null 2>&1 || :
elif [ -x "/etc/init.d/elasticsearch" ]; then
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
invoke-rc.d elasticsearch stop || true
else

View File

@ -0,0 +1,26 @@
[Unit]
Description=Starts and stops a single elasticsearch instance on this system
Documentation=http://www.elasticsearch.org
Wants=network-online.target
After=network-online.target
[Service]
EnvironmentFile=/etc/default/elasticsearch
User=elasticsearch
Group=elasticsearch
ExecStart=/usr/share/elasticsearch/bin/elasticsearch \
-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
# See MAX_OPEN_FILES in sysconfig
LimitNOFILE=65535
# See MAX_LOCKED_MEMORY in sysconfig, use "infinity" when MAX_LOCKED_MEMORY=unlimited and using bootstrap.mlockall: true
#LimitMEMLOCK=infinity
# Shutdown delay in seconds, before process is tried to be killed with KILL (if configured)
TimeoutStopSec=20
[Install]
WantedBy=multi-user.target