File zabbix_ite.spec of Package zabbix-agent-ite

Name:           zabbix-agent
Version:        6.4.17
Release:        1%{?dist}
Summary:        Zabbix monitoring agent

License:        GPL-2.0-or-later
URL:            https://www.zabbix.com/
Source0:        https://cdn.zabbix.com/zabbix/binaries/stable/6.4/6.4.17/zabbix_agent-6.4.17-linux-3.0-amd64-static.tar.gz
Source1:        zabbix-agent-ite.service
Source2:        zabbix_agentd_ite.conf
Source3:        zabbix-agent-logrotate.conf
Source4:        btrfs.disco.sh

Requires:       logrotate
Requires:       systemd
Requires(pre):  shadow
Conflicts:      zabbix-agent

Requires(pre): /usr/sbin/groupadd
BuildRequires:  tar
BuildRequires:  shadow
BuildRequires:  gzip
BuildRequires:  systemd
BuildRequires:  hostname
BuildRequires:  coreutils


%description
Zabbix is an enterprise-level monitoring solution for networks and applications. 
This package contains the Zabbix agent for monitoring.

%prep
# Manually extract the tarball
mkdir -p %{_tmpdir}/zabbix_agent
chmod 777 %{_tmpdir}/zabbix_agent
tar -xzf %{SOURCE0} -C %{_tmpdir}/zabbix_agent
cd %{_tmpdir}/zabbix_agent

%build
# No build step required as we're using precompiled binaries.

%install
# Create necessary directories
install -d %{buildroot}/etc/logrotate.d/
install -d %{buildroot}/opt/zabbix_ite/bin/
install -d %{buildroot}/opt/zabbix_ite/sbin/
install -d %{buildroot}/opt/zabbix_ite/conf/
install -d %{buildroot}/opt/zabbix_ite/externalscripts/
install -d %{buildroot}/opt/zabbix_ite/conf/zabbix_agentd/
install -d %{buildroot}/opt/zabbix_ite/logs/
install -d %{buildroot}/usr/lib/systemd/system/

# Install Zabbix agent binary
install -m 0755 %{_tmpdir}/zabbix_agent/bin/zabbix_get %{buildroot}/opt/zabbix_ite/bin/zabbix_get
install -m 0755 %{_tmpdir}/zabbix_agent/bin/zabbix_sender %{buildroot}/opt/zabbix_ite/bin/zabbix_sender
install -m 0755 %{_tmpdir}/zabbix_agent/sbin/zabbix_agentd %{buildroot}/opt/zabbix_ite/sbin/zabbix_agentd
install -m 0755 %{SOURCE4} %{buildroot}/opt/zabbix_ite/externalscripts/btrfs.disco.sh

# Install configuration files
install -m 0644 %{_tmpdir}/zabbix_agent/conf/zabbix_agentd/userparameter_examples.conf %{buildroot}/opt/zabbix_ite/conf/zabbix_agentd/userparameter_examples.conf
install -m 0644 %{_tmpdir}/zabbix_agent/conf/zabbix_agentd/userparameter_mysql.conf %{buildroot}/opt/zabbix_ite/conf/zabbix_agentd/userparameter_mysql.conf
install -m 0644 %{SOURCE2} %{buildroot}/opt/zabbix_ite/conf/zabbix_agentd_ite.conf
install -m 0644 %{SOURCE3} %{buildroot}/etc/logrotate.d/zabbix-agent

# Install systemd service file
install -m 0644 %{SOURCE1} %{buildroot}/usr/lib/systemd/system/zabbix-agent-ite.service

%post
ls -la /opt/zabbix_ite
getent group zabbix >/dev/null || /usr/sbin/groupadd -r zabbix
getent passwd zabbix >/dev/null || useradd -r -g zabbix -d /opt/zabbix_ite -s /bin/false -c "Zabbix Monitoring Agent" zabbix


# Retrieve the system's FQDN
FQDN=$(hostname -f)

# Replace the Hostname= line in the configuration file
if [ -f /opt/zabbix_ite/conf/zabbix_agentd_ite.conf ]; then
    sed -i "s/^Hostname=.*/Hostname=${FQDN}/" /opt/zabbix_ite/conf/zabbix_agentd_ite.conf
fi

chown -R zabbix:zabbix /opt/zabbix_ite/

# Check if the service exists and stop it if it does, this service is installed through old zabbix-agent rpm
if systemctl list-units --type=service --state=running | grep -q 'zabbix_agentd.service'; then
    systemctl stop zabbix_agentd.service || true
    systemctl disable zabbix_agentd.service || true
fi

# Check if the service exists and stop it if it does, this service is installed through custom installation
if systemctl list-units --type=service --state=running | grep -q 'zabbix-agent-ite.service'; then
    systemctl stop zabbix-agent-ite.service || true
fi

# Reload systemd daemon to recognize new or updated service files
systemctl daemon-reload

# Restart the zabbix-agent-ite service
systemctl enable zabbix-agent-ite.service || true
systemctl restart zabbix-agent-ite.service || true

%files
/etc/logrotate.d/zabbix-agent
/opt/zabbix_ite/
/usr/lib/systemd/system/zabbix-agent-ite.service
openSUSE Build Service is sponsored by