Skip to content

Commit a1166cc

Browse files
authored
Fix system unit TimeoutStopSec on older version. (#14947)
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.
1 parent 311d4dc commit a1166cc

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

pkg/centos/after-install.sh

+18
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,23 @@ sed -i \
77
/etc/logstash/logstash.yml
88
chmod 600 /etc/logstash/startup.options
99
chmod 600 /etc/default/logstash
10+
11+
# Starting from systemd 229, TimeouStopSec supports using
12+
# 'infinity' to disable not send a SIG Kill.
13+
#
14+
# Older versions need to use 0 instead.
15+
systemd_version=$(rpm -q systemd 2> /dev/null | cut -d '-' -f2)
16+
if [ -n $systemd_version ] && [ $systemd_version -lt 229 ]; then
17+
sed -i \
18+
-e "s/^TimeoutStopSec=infinity/TimeoutStopSec=0/" \
19+
/lib/systemd/system/logstash.service || true
20+
else
21+
# Ensure's an upgraded system has the right setting, if it
22+
# wasn't automatically replaced by the OS.
23+
sed -i \
24+
-e "s/^TimeoutStopSec=0/TimeoutStopSec=infinity/" \
25+
/lib/systemd/system/logstash.service || true
26+
fi
27+
1028
# Ensure the init script is picked up by systemd
1129
systemctl daemon-reload 2> /dev/null || true

pkg/debian/after-install.sh

+16
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,19 @@ sed -i \
1111
chmod 600 /etc/logstash/startup.options
1212
chmod 600 /etc/default/logstash
1313

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

pkg/ubuntu/after-install.sh

+17
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,20 @@ sed -i \
99
/etc/logstash/logstash.yml
1010
chmod 600 /etc/logstash/startup.options
1111
chmod 600 /etc/default/logstash
12+
13+
# Starting from systemd 229, TimeouStopSec supports using
14+
# 'infinity' to disable not send a SIG Kill.
15+
#
16+
# Older versions need to use 0 instead.
17+
systemd_version=$(dpkg-query --showformat='${Version}' --show systemd 2> /dev/null)
18+
if [ -n $systemd_version ] && dpkg --compare-versions "$systemd_version" lt 229 ; then
19+
sed -i \
20+
-e "s/^TimeoutStopSec=infinity/TimeoutStopSec=0/" \
21+
/lib/systemd/system/logstash.service || true
22+
else
23+
# Ensure's an upgraded system has the right setting, if it
24+
# wasn't automatically replaced by the OS.
25+
sed -i \
26+
-e "s/^TimeoutStopSec=0/TimeoutStopSec=infinity/" \
27+
/lib/systemd/system/logstash.service || true
28+
fi

0 commit comments

Comments
 (0)