Allow packages to disable immediate restart on package upgrade
Both package types, RPM and deb now contain an option to not restart on upgrade. This option can be configure in /etc/default/elasticsearch for dpkg based systems and /etc/sysconfig/elasticsearch for rpm based systems. By default the setting is as before, where a restart is executed on upgrade. Closes #3685
This commit is contained in:
parent
ba6bc2a4df
commit
26f9968b3b
|
@ -1,9 +1,20 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
[ -f /etc/default/elasticsearch ] && . /etc/default/elasticsearch
|
||||||
|
|
||||||
|
startElasticsearch() {
|
||||||
|
if [ -x "/etc/init.d/elasticsearch" ]; then
|
||||||
|
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
|
||||||
|
invoke-rc.d elasticsearch start || true
|
||||||
|
else
|
||||||
|
/etc/init.d/elasticsearch start || true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
configure)
|
configure)
|
||||||
[ -f /etc/default/elasticsearch ] && . /etc/default/elasticsearch
|
|
||||||
[ -z "$ES_USER" ] && ES_USER="elasticsearch"
|
[ -z "$ES_USER" ] && ES_USER="elasticsearch"
|
||||||
[ -z "$ES_GROUP" ] && ES_GROUP="elasticsearch"
|
[ -z "$ES_GROUP" ] && ES_GROUP="elasticsearch"
|
||||||
if ! getent group "$ES_GROUP" > /dev/null 2>&1 ; then
|
if ! getent group "$ES_GROUP" > /dev/null 2>&1 ; then
|
||||||
|
@ -24,16 +35,15 @@ case "$1" in
|
||||||
chown -Rh root:root /etc/elasticsearch/*
|
chown -Rh root:root /etc/elasticsearch/*
|
||||||
chmod 755 /etc/elasticsearch
|
chmod 755 /etc/elasticsearch
|
||||||
chmod 644 /etc/elasticsearch/*
|
chmod 644 /etc/elasticsearch/*
|
||||||
|
|
||||||
|
update-rc.d elasticsearch defaults 95 10 >/dev/null
|
||||||
|
# if $2 is set, this is an upgrade
|
||||||
|
if ( [ -n $2 ] && [ "$RESTART_ON_UPGRADE" = "true" ] ) ; then
|
||||||
|
startElasticsearch
|
||||||
|
# this is a fresh installation, start anyway
|
||||||
|
elif [ -z $2 ] ; then
|
||||||
|
startElasticsearch
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
if [ -x "/etc/init.d/elasticsearch" ]; then
|
|
||||||
update-rc.d elasticsearch defaults 95 10 >/dev/null
|
|
||||||
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
|
|
||||||
invoke-rc.d elasticsearch start || true
|
|
||||||
else
|
|
||||||
/etc/init.d/elasticsearch start || true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
[ -f /etc/default/elasticsearch ] && . /etc/default/elasticsearch
|
||||||
|
|
||||||
|
stopElasticsearch() {
|
||||||
if [ -x "/etc/init.d/elasticsearch" ]; then
|
if [ -x "/etc/init.d/elasticsearch" ]; then
|
||||||
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
|
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
|
||||||
invoke-rc.d elasticsearch stop || true
|
invoke-rc.d elasticsearch stop || true
|
||||||
|
@ -8,3 +11,16 @@ if [ -x "/etc/init.d/elasticsearch" ]; then
|
||||||
/etc/init.d/elasticsearch stop || true
|
/etc/init.d/elasticsearch stop || true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
upgrade)
|
||||||
|
if [ "$RESTART_ON_UPGRADE" = "true" ] ; then
|
||||||
|
stopElasticsearch
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
remove)
|
||||||
|
stopElasticsearch
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
|
@ -36,3 +36,6 @@
|
||||||
|
|
||||||
# Additional Java OPTS
|
# Additional Java OPTS
|
||||||
#ES_JAVA_OPTS=
|
#ES_JAVA_OPTS=
|
||||||
|
|
||||||
|
# Configure restart on package upgrade (true, every other setting will lead to not restarting)
|
||||||
|
#RESTART_ON_UPGRADE=true
|
||||||
|
|
|
@ -1,24 +1,43 @@
|
||||||
hasBeenEnabledOnStart=false
|
|
||||||
|
|
||||||
if [ $1 -eq 1 ] ; then
|
[ -f /etc/sysconfig/elasticsearch ] && . /etc/sysconfig/elasticsearch
|
||||||
# Initial installation
|
|
||||||
|
startElasticsearch() {
|
||||||
if [ -x /bin/systemctl ] ; then
|
if [ -x /bin/systemctl ] ; then
|
||||||
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
|
|
||||||
/bin/systemctl enable elasticsearch.service
|
|
||||||
/bin/systemctl start elasticsearch.service
|
/bin/systemctl start elasticsearch.service
|
||||||
hasBeenEnabledOnStart=true
|
elif [ -x /etc/init.d/elasticsearch ] ; then
|
||||||
fi
|
/etc/init.d/elasticsearch start
|
||||||
|
|
||||||
if [ -x /sbin/chkconfig -a "$hasBeenEnabledOnStart" == "false" ] ; then
|
|
||||||
/sbin/chkconfig --add elasticsearch
|
|
||||||
# older suse linux distributions do not ship with systemd
|
# older suse linux distributions do not ship with systemd
|
||||||
# but do not have an /etc/init.d/ directory
|
# but do not have an /etc/init.d/ directory
|
||||||
# this tries to start elasticsearch on these as well without failing this script
|
# this tries to start elasticsearch on these as well without failing this script
|
||||||
if [ -x /etc/init.d/elasticsearch ] ; then
|
|
||||||
/etc/init.d/elasticsearch start
|
|
||||||
elif [ -x /etc/rc.d/init.d/elasticsearch ] ; then
|
elif [ -x /etc/rc.d/init.d/elasticsearch ] ; then
|
||||||
/etc/rc.d/init.d/elasticsearch start
|
/etc/rc.d/init.d/elasticsearch start
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
stopElasticsearch() {
|
||||||
|
if [ -x /bin/systemctl ] ; then
|
||||||
|
/bin/systemctl stop elasticsearch.service > /dev/null 2>&1 || :
|
||||||
|
elif [ -x /etc/init.d/elasticsearch ] ; then
|
||||||
|
/etc/init.d/elasticsearch stop
|
||||||
|
elif [ -x /etc/rc.d/init.d/elasticsearch ] ; then
|
||||||
|
/etc/rc.d/init.d/elasticsearch stop
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initial installation: $1 == 1
|
||||||
|
# Upgrade: $1 == 2, and configured to restart on upgrade
|
||||||
|
if [ $1 -eq 1 ] ; then
|
||||||
|
|
||||||
|
if [ -x /bin/systemctl ] ; then
|
||||||
|
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
|
||||||
|
/bin/systemctl enable elasticsearch.service
|
||||||
|
elif [ -x /sbin/chkconfig ] ; then
|
||||||
|
/sbin/chkconfig --add elasticsearch
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
startElasticsearch
|
||||||
|
elif [ $1 -ge 2 -a "$RESTART_ON_UPGRADE" == "true" ] ; then
|
||||||
|
stopElasticsearch
|
||||||
|
startElasticsearch
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,29 @@
|
||||||
|
|
||||||
|
[ -f /etc/sysconfig/elasticsearch ] && . /etc/sysconfig/elasticsearch
|
||||||
|
|
||||||
|
stopElasticsearch() {
|
||||||
|
if [ -x /bin/systemctl ] ; then
|
||||||
|
/bin/systemctl stop elasticsearch.service > /dev/null 2>&1 || :
|
||||||
|
elif [ -x /etc/init.d/elasticsearch ] ; then
|
||||||
|
/etc/init.d/elasticsearch stop
|
||||||
|
elif [ -x /etc/rc.d/init.d/elasticsearch ] ; then
|
||||||
|
/etc/rc.d/init.d/elasticsearch stop
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Removal: $1 == 0
|
||||||
|
# Dont do anything on upgrade, because the preun script in redhat gets executed after the postinst (madness!)
|
||||||
if [ $1 -eq 0 ] ; then
|
if [ $1 -eq 0 ] ; then
|
||||||
# Package removal, not upgrade
|
|
||||||
if [ -x /bin/systemctl ] ; then
|
if [ -x /bin/systemctl ] ; then
|
||||||
/bin/systemctl --no-reload disable elasticsearch.service > /dev/null 2>&1 || :
|
/bin/systemctl --no-reload disable elasticsearch.service > /dev/null 2>&1 || :
|
||||||
/bin/systemctl stop elasticsearch.service > /dev/null 2>&1 || :
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -x /sbin/chkconfig ] ; then
|
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
|
/sbin/chkconfig --del elasticsearch 2> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
stopElasticsearch
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
@ -38,3 +38,6 @@ CONF_FILE=/etc/elasticsearch/elasticsearch.yml
|
||||||
# Also make sure, this user can write into the log directories in case you change them
|
# 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
|
# This setting only works for the init script, but has to be configured separately for systemd startup
|
||||||
ES_USER=elasticsearch
|
ES_USER=elasticsearch
|
||||||
|
|
||||||
|
# Configure restart on package upgrade (true, every other setting will lead to not restarting)
|
||||||
|
#RESTART_ON_UPGRADE=true
|
||||||
|
|
Loading…
Reference in New Issue