mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 14:17:58 -04:00
During upgrade, Logstash packaging removes /etc/systemd/system/logstash.service because Logstahs used to install the systemd unit there. However, this could have been modified by the user by overriding the systemd file. As such, the upgrade process should only remove if it is certain it wasn't installed by Logstash. Unfortunately, there's no particular way to determine if Logstash installation process installed the file because it was done on the fly, by a script, on a postinst script of the package. As such, the best way to address this is to check if both the new and the old file exists. If the new one doesn't exist, we can assume we are upgrading (or installing afresh), and the old file should be removed. If the new one exists and the user-create one (old location) also exists, we assume it is user created, and as such, we don't remove it just to be safe.
18 lines
588 B
Bash
18 lines
588 B
Bash
# create logstash group
|
|
if ! getent group logstash >/dev/null; then
|
|
groupadd -r logstash
|
|
fi
|
|
|
|
# create logstash user
|
|
if ! getent passwd logstash >/dev/null; then
|
|
useradd -r -g logstash -d /usr/share/logstash \
|
|
-s /sbin/nologin -c "logstash" logstash
|
|
fi
|
|
|
|
# Handle upgrade: Check if old service unit exists and remove it
|
|
# if the new one is not installed in the system. Otherwise, assume
|
|
# the old one is user-created.
|
|
if [ -f /etc/systemd/system/logstash.service ] && \
|
|
[ ! -f /lib/systemd/system/logstash.service ]; then
|
|
rm -rf /etc/systemd/system/logstash.service || true
|
|
fi
|