Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deb: add systemd service config for upcoming Jessie #8765

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions src/deb/control/conffiles
Expand Up @@ -2,3 +2,4 @@
/etc/default/elasticsearch
/etc/elasticsearch/logging.yml
/etc/elasticsearch/elasticsearch.yml
/usr/lib/systemd/system/elasticsearch.service
22 changes: 17 additions & 5 deletions src/deb/control/postinst
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/deb/control/postrm
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/deb/control/prerm
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions 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