diff --git a/pom.xml b/pom.xml
index b7b0d5490f2..40291b271f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -975,6 +975,11 @@
root
+
+ ${project.basedir}/src/deb/systemd/elasticsearch.service
+ /usr/lib/systemd/system/elasticsearch.service
+ file
+
${project.basedir}/config
directory
diff --git a/src/deb/control/conffiles b/src/deb/control/conffiles
index 98e0f5a6432..d77241e3934 100644
--- a/src/deb/control/conffiles
+++ b/src/deb/control/conffiles
@@ -2,3 +2,4 @@
/etc/default/elasticsearch
/etc/elasticsearch/logging.yml
/etc/elasticsearch/elasticsearch.yml
+/usr/lib/systemd/system/elasticsearch.service
diff --git a/src/deb/control/postinst b/src/deb/control/postinst
index 166db9c7e8d..bba988ac6e3 100755
--- a/src/deb/control/postinst
+++ b/src/deb/control/postinst
@@ -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,10 +45,19 @@ case "$1" in
startElasticsearch
# this is a fresh installation
elif [ -z $2 ] ; 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"
+ 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
diff --git a/src/deb/control/postrm b/src/deb/control/postrm
index 4e2a5acdf75..b47965d6ebb 100755
--- a/src/deb/control/postrm
+++ b/src/deb/control/postrm
@@ -5,14 +5,23 @@ case "$1" in
remove)
# 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
- update-rc.d elasticsearch remove >/dev/null || true
+ # 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
diff --git a/src/deb/control/prerm b/src/deb/control/prerm
index fb3c9eb2ce4..c613e0667b1 100755
--- a/src/deb/control/prerm
+++ b/src/deb/control/prerm
@@ -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
diff --git a/src/deb/systemd/elasticsearch.service b/src/deb/systemd/elasticsearch.service
new file mode 100644
index 00000000000..3eeb1f1019f
--- /dev/null
+++ b/src/deb/systemd/elasticsearch.service
@@ -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