commit e50a6d10875a678d59b1311bc124b3f002d7106d Author: Maksym Buz Date: Wed Sep 3 11:21:38 2025 +0200 INIT: First commit diff --git a/zabbix-apk-builder/.github/workflows/build.yml b/zabbix-apk-builder/.github/workflows/build.yml new file mode 100644 index 0000000..e69de29 diff --git a/zabbix-apk-builder/.gitignore b/zabbix-apk-builder/.gitignore new file mode 100644 index 0000000..327d344 --- /dev/null +++ b/zabbix-apk-builder/.gitignore @@ -0,0 +1,16 @@ +# Build artifacts +packages/ +*.apk +src/ +*.tar.gz + +# Docker cache +.docker/ + +# Backup files +*.backup +*~ + +# OS files +.DS_Store +Thumbs.db diff --git a/zabbix-apk-builder/APKBUILD b/zabbix-apk-builder/APKBUILD new file mode 100644 index 0000000..84e5663 --- /dev/null +++ b/zabbix-apk-builder/APKBUILD @@ -0,0 +1,148 @@ +# Contributor: Maks +# Maintainer: Maks +pkgname=zabbix +pkgver=7.4.2 +pkgrel=0 +pkgdesc="Enterprise-class open source distributed monitoring solution" +url="https://www.zabbix.com/" +arch="all" +license="AGPL-3.0-or-later" +options="!check" # No test suite available +makedepends=" + autoconf + automake + curl-dev + libevent-dev + libxml2-dev + libtool + linux-headers + net-snmp-dev + openssl-dev + pcre2-dev + sqlite-dev + unixodbc-dev + libssh2-dev + " +pkgusers="zabbix" +pkggroups="zabbix" +install="$pkgname-agent.pre-install $pkgname-proxy.pre-install" +subpackages="$pkgname-agent $pkgname-proxy" +source="https://cdn.zabbix.com/zabbix/sources/stable/${pkgver%.*}/zabbix-$pkgver.tar.gz + zabbix-agent.initd + zabbix-agent.confd + zabbix-proxy.initd + zabbix-proxy.confd + " +builddir="$srcdir/$pkgname-$pkgver" + +prepare() { + default_prepare + + # Regenerate autotools files + cd "$builddir" + autoreconf -fiv + + # Create separate build directories for agent and proxy + cp -r "$builddir" "$srcdir/zabbix-agent-$pkgver" + cp -r "$builddir" "$srcdir/zabbix-proxy-$pkgver" +} + +build() { + # Build agent with minimal dependencies + cd "$srcdir/zabbix-agent-$pkgver" + ./configure \ + --build=$CBUILD \ + --host=$CHOST \ + --prefix=/usr \ + --sysconfdir=/etc/zabbix \ + --localstatedir=/var \ + --enable-agent \ + --with-libcurl \ + --with-net-snmp \ + --with-openssl \ + --with-libpcre2 + make + + # Build proxy with database support + cd "$srcdir/zabbix-proxy-$pkgver" + ./configure \ + --build=$CBUILD \ + --host=$CHOST \ + --prefix=/usr \ + --sysconfdir=/etc/zabbix \ + --localstatedir=/var \ + --enable-proxy \ + --with-libcurl \ + --with-net-snmp \ + --with-openssl \ + --with-libpcre2 \ + --with-sqlite3 \ + --with-unixodbc \ + --with-ssh2 \ + --with-libxml2 \ + --with-libevent + make +} + +package() { + # Meta-package - intentionally empty + # Users install zabbix-agent and/or zabbix-proxy directly + mkdir -p "$pkgdir" +} + +agent() { + pkgdesc="Zabbix monitoring agent" + + cd "$srcdir/zabbix-agent-$pkgver" + + # Install agent binary + install -Dm755 src/zabbix_agent/zabbix_agentd \ + "$subpkgdir"/usr/sbin/zabbix_agentd + + + # Install agent configuration + install -Dm644 conf/zabbix_agentd.conf \ + "$subpkgdir"/etc/zabbix/zabbix_agentd.conf + + # Install init script and conf + install -Dm755 "$srcdir"/zabbix-agent.initd \ + "$subpkgdir"/etc/init.d/zabbix-agent + install -Dm644 "$srcdir"/zabbix-agent.confd \ + "$subpkgdir"/etc/conf.d/zabbix-agent + + # Create directories + install -dm755 "$subpkgdir"/var/log/zabbix + install -dm755 "$subpkgdir"/var/run/zabbix +} + +proxy() { + pkgdesc="Zabbix network monitoring proxy daemon" + + cd "$srcdir/zabbix-proxy-$pkgver" + + # Install proxy binary + install -Dm755 src/zabbix_proxy/zabbix_proxy \ + "$subpkgdir"/usr/sbin/zabbix_proxy + + # Install proxy configuration + install -Dm644 conf/zabbix_proxy.conf \ + "$subpkgdir"/etc/zabbix/zabbix_proxy.conf + + # Install init script and conf + install -Dm755 "$srcdir"/zabbix-proxy.initd \ + "$subpkgdir"/etc/init.d/zabbix-proxy + install -Dm644 "$srcdir"/zabbix-proxy.confd \ + "$subpkgdir"/etc/conf.d/zabbix-proxy + + # Create directories + install -dm755 "$subpkgdir"/var/log/zabbix + install -dm755 "$subpkgdir"/var/run/zabbix +} + +sha512sums=" +3bf1f915c2cd5a59f1dd3afc10dd1a6e596840e576013839d6eae057cd327893f87cc5cec1d32b6a8ca8bd00735c0070327084aae01dc8d3399202f5a3e365c1 zabbix-7.4.2.tar.gz +SKIP +SKIP +SKIP +SKIP +" diff --git a/zabbix-apk-builder/Dockerfile b/zabbix-apk-builder/Dockerfile new file mode 100644 index 0000000..a8a5573 --- /dev/null +++ b/zabbix-apk-builder/Dockerfile @@ -0,0 +1,40 @@ +FROM alpine:latest + +# Install build dependencies +RUN apk add --no-cache \ + abuild \ + alpine-sdk \ + autoconf \ + automake \ + libtool \ + linux-headers \ + pkgconfig \ + sudo \ + curl-dev \ + libevent-dev \ + libxml2-dev \ + net-snmp-dev \ + openssl-dev \ + pcre2-dev \ + sqlite-dev \ + unixodbc-dev \ + zlib-dev \ + openldap-dev \ + libssh2-dev \ + && adduser -D -G abuild builder \ + && echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +# Setup build environment +USER builder +WORKDIR /home/builder + +# Generate signing keys +RUN abuild-keygen -a -i -n + +# Copy package files +COPY --chown=builder:builder . /home/builder/zabbix/ + +WORKDIR /home/builder/zabbix + +# Set build command +CMD ["abuild", "-r"] diff --git a/zabbix-apk-builder/README.md b/zabbix-apk-builder/README.md new file mode 100644 index 0000000..442093b --- /dev/null +++ b/zabbix-apk-builder/README.md @@ -0,0 +1,76 @@ +# Zabbix APK Builder + +Automated build system for creating Zabbix monitoring packages for Alpine Linux using Docker. + +## What it does + +This project builds separate Alpine Linux packages for: +- **zabbix-agent** - Monitoring agent for data collection +- **zabbix-proxy** - Network monitoring proxy daemon +- **zabbix** - Meta-package that installs both components + +Each package includes proper OpenRC init scripts and user management for production deployment. + +## Quick Start + +```bash +# Build packages +./build.sh + +# Install on Alpine Linux +apk add --allow-untrusted packages/zabbix-agent-*.apk +apk add --allow-untrusted packages/zabbix-proxy-*.apk + +# Enable and start services +rc-update add zabbix-agent default +rc-service zabbix-agent start +``` + +## Configuration + +### Change Zabbix Version +Edit `APKBUILD`: +```bash +pkgver=7.4.2 # Change to desired version +``` + +### Change Architecture +Edit `APKBUILD`: +```bash +arch="all" # All architectures +arch="x86_64" # 64-bit Intel/AMD only +arch="x86_64 aarch64" # 64-bit Intel/AMD and ARM64 +``` + +### Update Checksums +After changing the version: +```bash +# Manual approach +wget https://cdn.zabbix.com/zabbix/sources/stable/X.Y/zabbix-X.Y.Z.tar.gz +sha512sum zabbix-X.Y.Z.tar.gz # Update sha512sums in APKBUILD +# Or let the build system handle it +./build.sh # Will download and verify against official SHA256 +``` +sha512 is used per Alpine recommendation: +https://wiki.alpinelinux.org/wiki/APKBUILD_Reference +`New packages should use only sha512sums. Support for md5sums and sha1sums was dropped.` + +## Build Process + +1. **Docker Build**: Creates Alpine Linux build environment +2. **Download Sources**: `abuild checksum` downloads tarball and generates SHA512 +2. **Package Build**: Compiles and packages using Alpine's `abuild` system +3. **Output**: Generated APK files in `packages/` directory + +## Requirements + +- Docker +- Internet connection (for source download and verification) + +## Files + +- `APKBUILD` - Alpine package definition +- `build.sh` - Build automation script +- `Dockerfile` - Build environment container +- `zabbix-agent.*` - Agent service configuration files +- `zabbix-proxy.*` - Proxy service configuration files diff --git a/zabbix-apk-builder/build.sh b/zabbix-apk-builder/build.sh new file mode 100755 index 0000000..e7eb629 --- /dev/null +++ b/zabbix-apk-builder/build.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +set -e + +# Configuration +PROJECT_DIR="$(pwd)" +IMAGE_NAME="zabbix-apk-builder" +CONTAINER_NAME="zabbix-build-$$" +OUTPUT_DIR="$PROJECT_DIR/packages" + +echo "=== Zabbix APK Builder ===" +echo "Project directory: $PROJECT_DIR" +echo "Output directory: $OUTPUT_DIR" + +# Clean up any existing containers +cleanup() { + echo "Cleaning up..." + docker rm -f "$CONTAINER_NAME" 2>/dev/null || true +} + +trap cleanup EXIT + +# Create output directory +mkdir -p "$OUTPUT_DIR" + +# Build Docker image +echo "Building Docker image..." +docker build -t "$IMAGE_NAME" "$PROJECT_DIR" + +# Run the build in container +echo "Running package build..." +docker run --rm \ + --name "$CONTAINER_NAME" \ + -v "$OUTPUT_DIR:/output" \ + "$IMAGE_NAME" \ + sh -c " + set -e + echo 'Starting package build...' + + # Generate checksums for APKBUILD + echo 'Generating checksums for APKBUILD...' + abuild checksum + + # Build packages + abuild -r + + # Copy packages to output + echo 'Copying packages to output directory...' + find /home/builder/packages -name '*.apk' -exec cp {} /output/ \; + " +echo "Build completed successfully!" +echo "To install packages:" +echo " apk add --allow-untrusted $OUTPUT_DIR/zabbix-agent-*.apk" +echo " apk add --allow-untrusted $OUTPUT_DIR/zabbix-proxy-*.apk" \ No newline at end of file diff --git a/zabbix-apk-builder/zabbix-agent.confd b/zabbix-apk-builder/zabbix-agent.confd new file mode 100644 index 0000000..171df8e --- /dev/null +++ b/zabbix-apk-builder/zabbix-agent.confd @@ -0,0 +1,11 @@ +# Configuration for zabbix-agent + +# User and group for the agent +ZABBIX_AGENT_USER="zabbix" +ZABBIX_AGENT_GROUP="zabbix" + +# Configuration file location +ZABBIX_AGENT_CONFIG="/etc/zabbix/zabbix_agentd.conf" + +# PID file location +ZABBIX_AGENT_PID="/var/run/zabbix/zabbix_agentd.pid" diff --git a/zabbix-apk-builder/zabbix-agent.initd b/zabbix-apk-builder/zabbix-agent.initd new file mode 100644 index 0000000..c350b19 --- /dev/null +++ b/zabbix-apk-builder/zabbix-agent.initd @@ -0,0 +1,42 @@ +#!/sbin/openrc-run +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +extra_commands="checkconfig" +extra_started_commands="reload" + +depend() { + need net + use logger +} + +: ${ZABBIX_AGENT_USER:=zabbix} +: ${ZABBIX_AGENT_GROUP:=zabbix} +: ${ZABBIX_AGENT_CONFIG:=/etc/zabbix/zabbix_agentd.conf} +: ${ZABBIX_AGENT_PID:=/var/run/zabbix/zabbix_agentd.pid} + +command="/usr/sbin/zabbix_agentd" +command_args="-c ${ZABBIX_AGENT_CONFIG}" +command_user="${ZABBIX_AGENT_USER}:${ZABBIX_AGENT_GROUP}" +pidfile="${ZABBIX_AGENT_PID}" +required_files="${ZABBIX_AGENT_CONFIG}" + +checkconfig() { + if [ ! -f "${ZABBIX_AGENT_CONFIG}" ] ; then + eerror "You need to create appropriate config file." + return 1 + fi +} + +start_pre() { + checkconfig || return $? + + checkpath --directory --owner ${ZABBIX_AGENT_USER}:${ZABBIX_AGENT_GROUP} --mode 0755 \ + $(dirname ${ZABBIX_AGENT_PID}) /var/log/zabbix +} + +reload() { + ebegin "Reloading ${SVCNAME}" + start-stop-daemon --signal HUP --pidfile "${pidfile}" + eend $? +} diff --git a/zabbix-apk-builder/zabbix-agent.pre-install b/zabbix-apk-builder/zabbix-agent.pre-install new file mode 100644 index 0000000..c148181 --- /dev/null +++ b/zabbix-apk-builder/zabbix-agent.pre-install @@ -0,0 +1,6 @@ +#!/bin/sh + +addgroup -S zabbix 2>/dev/null +adduser -S -D -H -s /bin/false -G zabbix -g zabbix zabbix 2>/dev/null + +exit 0 diff --git a/zabbix-apk-builder/zabbix-proxy.confd b/zabbix-apk-builder/zabbix-proxy.confd new file mode 100644 index 0000000..5cbcbf2 --- /dev/null +++ b/zabbix-apk-builder/zabbix-proxy.confd @@ -0,0 +1,11 @@ +# Configuration for zabbix-proxy + +# User and group for the proxy +ZABBIX_PROXY_USER="zabbix" +ZABBIX_PROXY_GROUP="zabbix" + +# Configuration file location +ZABBIX_PROXY_CONFIG="/etc/zabbix/zabbix_proxy.conf" + +# PID file location +ZABBIX_PROXY_PID="/var/run/zabbix/zabbix_proxy.pid" diff --git a/zabbix-apk-builder/zabbix-proxy.initd b/zabbix-apk-builder/zabbix-proxy.initd new file mode 100644 index 0000000..a137756 --- /dev/null +++ b/zabbix-apk-builder/zabbix-proxy.initd @@ -0,0 +1,43 @@ +#!/sbin/openrc-run +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +extra_commands="checkconfig" +extra_started_commands="reload" + +depend() { + need net + use logger + after postgresql mysql +} + +: ${ZABBIX_PROXY_USER:=zabbix} +: ${ZABBIX_PROXY_GROUP:=zabbix} +: ${ZABBIX_PROXY_CONFIG:=/etc/zabbix/zabbix_proxy.conf} +: ${ZABBIX_PROXY_PID:=/var/run/zabbix/zabbix_proxy.pid} + +command="/usr/sbin/zabbix_proxy" +command_args="-c ${ZABBIX_PROXY_CONFIG}" +command_user="${ZABBIX_PROXY_USER}:${ZABBIX_PROXY_GROUP}" +pidfile="${ZABBIX_PROXY_PID}" +required_files="${ZABBIX_PROXY_CONFIG}" + +checkconfig() { + if [ ! -f "${ZABBIX_PROXY_CONFIG}" ] ; then + eerror "You need to create appropriate config file." + return 1 + fi +} + +start_pre() { + checkconfig || return $? + + checkpath --directory --owner ${ZABBIX_PROXY_USER}:${ZABBIX_PROXY_GROUP} --mode 0755 \ + $(dirname ${ZABBIX_PROXY_PID}) /var/log/zabbix +} + +reload() { + ebegin "Reloading ${SVCNAME}" + start-stop-daemon --signal HUP --pidfile "${pidfile}" + eend $? +} diff --git a/zabbix-apk-builder/zabbix-proxy.pre-install b/zabbix-apk-builder/zabbix-proxy.pre-install new file mode 100644 index 0000000..c148181 --- /dev/null +++ b/zabbix-apk-builder/zabbix-proxy.pre-install @@ -0,0 +1,6 @@ +#!/bin/sh + +addgroup -S zabbix 2>/dev/null +adduser -S -D -H -s /bin/false -G zabbix -g zabbix zabbix 2>/dev/null + +exit 0