Skip to content

Commit

Permalink
Fix system unit TimeoutStopSec on older version. (elastic#14947)
Browse files Browse the repository at this point in the history
Fixes the system unit TimeoutStopSec option to set 0 on older version that do not support 'infinity'.
Also handles the upgrade case where the OS may not automatically upgrade the systemd file.
  • Loading branch information
roaksoax authored Mar 31, 2023
1 parent 311d4dc commit a1166cc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/centos/after-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,23 @@ sed -i \
/etc/logstash/logstash.yml
chmod 600 /etc/logstash/startup.options
chmod 600 /etc/default/logstash

# Starting from systemd 229, TimeouStopSec supports using
# 'infinity' to disable not send a SIG Kill.
#
# Older versions need to use 0 instead.
systemd_version=$(rpm -q systemd 2> /dev/null | cut -d '-' -f2)
if [ -n $systemd_version ] && [ $systemd_version -lt 229 ]; then
sed -i \
-e "s/^TimeoutStopSec=infinity/TimeoutStopSec=0/" \
/lib/systemd/system/logstash.service || true
else
# Ensure's an upgraded system has the right setting, if it
# wasn't automatically replaced by the OS.
sed -i \
-e "s/^TimeoutStopSec=0/TimeoutStopSec=infinity/" \
/lib/systemd/system/logstash.service || true
fi

# Ensure the init script is picked up by systemd
systemctl daemon-reload 2> /dev/null || true
16 changes: 16 additions & 0 deletions pkg/debian/after-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ sed -i \
chmod 600 /etc/logstash/startup.options
chmod 600 /etc/default/logstash

# Starting from systemd 229, TimeouStopSec supports using
# 'infinity' to disable not send a SIG Kill.
#
# Older versions need to use 0 instead.
systemd_version=$(dpkg-query --showformat='${Version}' --show systemd 2> /dev/null)
if [ -n $systemd_version ] && dpkg --compare-versions "$systemd_version" lt 229 ; then
sed -i \
-e "s/^TimeoutStopSec=infinity/TimeoutStopSec=0/" \
/lib/systemd/system/logstash.service || true
else
# Ensure's an upgraded system has the right setting, if it
# wasn't automatically replaced by the OS.
sed -i \
-e "s/^TimeoutStopSec=0/TimeoutStopSec=infinity/" \
/lib/systemd/system/logstash.service || true
fi
17 changes: 17 additions & 0 deletions pkg/ubuntu/after-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,20 @@ sed -i \
/etc/logstash/logstash.yml
chmod 600 /etc/logstash/startup.options
chmod 600 /etc/default/logstash

# Starting from systemd 229, TimeouStopSec supports using
# 'infinity' to disable not send a SIG Kill.
#
# Older versions need to use 0 instead.
systemd_version=$(dpkg-query --showformat='${Version}' --show systemd 2> /dev/null)
if [ -n $systemd_version ] && dpkg --compare-versions "$systemd_version" lt 229 ; then
sed -i \
-e "s/^TimeoutStopSec=infinity/TimeoutStopSec=0/" \
/lib/systemd/system/logstash.service || true
else
# Ensure's an upgraded system has the right setting, if it
# wasn't automatically replaced by the OS.
sed -i \
-e "s/^TimeoutStopSec=0/TimeoutStopSec=infinity/" \
/lib/systemd/system/logstash.service || true
fi

0 comments on commit a1166cc

Please sign in to comment.