logstash/pkg/debian/before-install.sh
Andres Rodriguez 303fdb0193
Only remove /etc/s/s/logstash.service if previously installed by Logstash (#14200)
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.
2022-06-24 10:56:07 -04:00

20 lines
619 B
Bash

#!/bin/sh
# 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 -M -r -g logstash -d /usr/share/logstash \
-s /usr/sbin/nologin -c "LogStash Service User" 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