diff --git a/testing/grommunio-admin-api/0002-enable-openapi-core-0.19.patch b/testing/grommunio-admin-api/0002-enable-openapi-core-0.19.patch new file mode 100644 index 00000000000..9f0513128f6 --- /dev/null +++ b/testing/grommunio-admin-api/0002-enable-openapi-core-0.19.patch @@ -0,0 +1,15 @@ +# openapi_core 0.19 has the required fixes for python 3.12 +--- a/api/core.py ++++ b/api/core.py +@@ -22,9 +22,9 @@ + from openapi_core.contrib.flask import FlaskOpenAPIRequest, FlaskOpenAPIResponse + if self.version < [0, 15, 0]: + from openapi_core import create_spec +- elif self.version < [0, 18, 0]: ++ elif self.version < [0, 19, 0]: + from openapi_core.spec.shortcuts import create_spec +- if self.version < [0, 18, 0]: ++ if self.version < [0, 19, 0]: + self.spec = create_spec(apiSpec) + else: + self.spec = openapi_core.Spec.from_dict(apiSpec) diff --git a/testing/grommunio-admin-api/0003-disable-systemd-log-reader.patch b/testing/grommunio-admin-api/0003-disable-systemd-log-reader.patch new file mode 100644 index 00000000000..ed277a69076 --- /dev/null +++ b/testing/grommunio-admin-api/0003-disable-systemd-log-reader.patch @@ -0,0 +1,21 @@ +# The systemd log reader should be replaced with another solution +# For now we disable it +--- a/endpoints/system/logs.py ++++ b/endpoints/system/logs.py +@@ -11,7 +11,6 @@ + import psutil + + from tools.config import Config +-from tools.logs import LogReader + from tools.permissions import SystemAdminROPermission + + +@@ -32,7 +31,7 @@ + n = int(request.args.get("n", 10)) + skip = int(request.args.get("skip", 0)) + after = datetime.strptime(request.args["after"], "%Y-%m-%d %H:%M:%S.%f") if "after" in request.args else None +- return jsonify(data=LogReader.tail(log.get("format", "journald"), log["source"], n, skip, after)) ++ return jsonify(message="Log file not found"), 404 + + + @API.route(api.BaseRoute+"/system/updateLog/", methods=["GET"]) diff --git a/testing/grommunio-admin-api/0004-replace-systemd-calls.patch b/testing/grommunio-admin-api/0004-replace-systemd-calls.patch new file mode 100644 index 00000000000..bc70ba06a8f --- /dev/null +++ b/testing/grommunio-admin-api/0004-replace-systemd-calls.patch @@ -0,0 +1,22 @@ +# The systemctl calls are replaced with a proprietary openrc wrapper +--- a/services/systemd.py ++++ b/services/systemd.py +@@ -35,8 +35,7 @@ + return "--system" if self.system else "--user" + + def getServices(self, *services): +- args = ("systemctl", "-q", self.__mode, "show", +- "--property="+",".join(self.valmap), *services) ++ args = ("rcctl", "info", *services) + result = subprocess.run(args, stdout=subprocess.PIPE, universal_newlines=True) + split = [[line.split("=", 1) for line in block.split("\n") if "=" in line] for block in result.stdout.split("\n\n")] + units = [{self.valmap[key]: value for key, value in block if key in self.valmap} for block in split] +@@ -53,7 +52,7 @@ + return {unit["unit"]: unit for unit in units if "unit" in unit} + + def run(self, command, *targets): +- result = subprocess.run(("systemctl", "-q", self.__mode, command, *targets), ++ result = subprocess.run(("rcctl", "-q", command, *targets), + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) + return result.returncode, result.stdout + diff --git a/testing/grommunio-admin-api/APKBUILD b/testing/grommunio-admin-api/APKBUILD index e87cb59f09b..8ad4c54e2f6 100644 --- a/testing/grommunio-admin-api/APKBUILD +++ b/testing/grommunio-admin-api/APKBUILD @@ -1,17 +1,18 @@ # Maintainer: Noel Kuntze pkgname=grommunio-admin-api pkgdesc="Backend for grommunio management" -pkgver=1.14 +pkgver=1.15 pkgrel=0 arch="noarch !riscv64" -url="http://www.grommunio.com" +url="https://grommunio.com/" license="AGPL-3.0-only" options="!check" # No test suite subpackages="$pkgname-doc $pkgname-openrc $pkgname-bash-completion" -makedepends="cmake py3-yaml ninja nginx" +makedepends="cmake py3-yaml samurai nginx" +# still missing: py3-mattermostdriver py3-openapi-core depends="grommunio-admin-common grommunio-gromox - libexmdbpp + py3-pyexmdb py3-ldap3 py3-mysqlclient py3-redis @@ -26,9 +27,9 @@ depends="grommunio-admin-common py3-flask py3-jwt py3-multidict - py3-openapi-codec py3-requests uwsgi + uwsgi-python3 " pkgusers="grommunio" @@ -36,9 +37,14 @@ pkggroups="grommunio" source="$pkgname-$pkgver.tar.gz::https://github.com/grommunio/admin-api/archive/refs/tags/$pkgver.tar.gz 0001-makefile.patch + 0002-enable-openapi-core-0.19.patch + 0003-disable-systemd-log-reader.patch + 0004-replace-systemd-calls.patch + grommunio-admin-api.initd grommunio-admin-api.confd database.yaml + rc-service-ctl.sh " builddir="$srcdir/admin-api-$pkgver" @@ -46,9 +52,10 @@ builddir="$srcdir/admin-api-$pkgver" build() { cmake -B build -G Ninja \ -DCMAKE_INSTALL_PREFIX=/usr \ - -DCMAKE_INSTALL_LIBDIR=lib \ - -DCONFDIR=/usr/share/examples/grommunio-admin-api \ - -DCOMMONCONFDIR=/usr/share/examples/grommunio-admin-common \ + -DCMAKE_INSTALL_SYSCONFDIR=/etc \ + -DCMAKE_INSTALL_SBINDIR=/usr/sbin \ + -DCMAKE_INSTALL_LIBDIR=/usr/lib \ + -DCMAKE_INSTALL_LOCALSTATEDIR=/var \ -DCMAKE_BUILD_TYPE=MinSizeRel cmake --build build @@ -61,14 +68,20 @@ package() { install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname ln -sf "/etc/init.d/uwsgi" "$pkgdir/etc/init.d/$pkgname" install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname + install -d -m0750 -o grommunio -g grommunio "$pkgdir"/etc/grommunio-admin-api/conf.d install -m644 -D "$srcdir"/database.yaml "$pkgdir"/etc/grommunio-admin-api/conf.d/database.yaml + install -m755 -D "$srcdir"/rc-service-ctl.sh "$pkgdir"/usr/bin/rcctl install -d -m0775 -o grommunio -g nginx "$pkgdir"/var/run/grommunio } sha512sums=" -3dfb6a0c194d862f0358dd854830b52f84730b8944940aa5a3ec200f50a3a5cef03184347684a08978b146ed0214d969962ac8d299b68f146551b3be3446f693 grommunio-admin-api-1.14.tar.gz +c88ab4153f867f8196db72e19b871eb882228b2fd2077b2d43e5682e0a0cba7d274412ca9b870940fc9668b30c0a2501282e02f96477dca0e1da5a5e26963d4a grommunio-admin-api-1.15.tar.gz 47dc0698ca3d107b9a37f4778c386d099bd24bfaa6104e9512166b0266898dfcb1a63eb1eb2b1bb27d7d54b56560c4cfb6f3a48c7e56e5a61c21cb445aa830ea 0001-makefile.patch +bfc5828e5f456e7be77a9c8b65d8a629d56c72184f28b53fdef488eb9522661c6ee1adb9c64fe53da86020194535fea7ea157864beb81e43859d95bd4b5dbd1e 0002-enable-openapi-core-0.19.patch +27dceea394302b2afafca84927c3fc9a57cb6502e4fd08ccd35786855c6bd3203869a357d89766e3775c4c05882105372ab6c9db5b974fc727fa8b4753387236 0003-disable-systemd-log-reader.patch +815e3151c10be79b9471c28f871af6f80afcf1cbd753091d141d2e66b7c0f32d58e2ca6f0967168c8efb6cdb6126626904384f09983f63f8a17fd80abdadab52 0004-replace-systemd-calls.patch b87910a731ad58b86679b08674632fffb4d76a94ad67602906200acf7e36fb23508ec19f56ca2f8a1e257a7ef3a32c4dbfa7b27d9d902006eff3d92d8816c067 grommunio-admin-api.initd -b634a1d20372f45e9f9e347d9f0b0785dca561849920381e223b2a7f356d7e9a37299087b8b6e69d8caf1af87313f14d8e0ac85699bafd9258c6e7153c590cf5 grommunio-admin-api.confd +9ac7e9abc06a3abf868baede3cd64aeda52f5badb30eafd2369ceda0a79f7fa91d7c6e73b139e2f4f4d808ff8ff781d7b4fa313bad89af53be1b6c4fe7ede914 grommunio-admin-api.confd bf166f9f46d3a6755c2273502576c63060b17d2eb7a4abbac9da5ed1b74a4ed47baf6269eda58adf04657a78028e862572cd7b24d9c8b5b6497b778338def12f database.yaml +70ccbe4085c255b09a2b558f051ce47a1076777057453ff35e98089ed33364dd366d479b035b9b1aef08488901086300a7d9c1bfb68b02424e7baf5d826ba745 rc-service-ctl.sh " diff --git a/testing/grommunio-admin-api/grommunio-admin-api.confd b/testing/grommunio-admin-api/grommunio-admin-api.confd index 4746d7a3641..15938c51fb6 100644 --- a/testing/grommunio-admin-api/grommunio-admin-api.confd +++ b/testing/grommunio-admin-api/grommunio-admin-api.confd @@ -1,3 +1,10 @@ # Configuration for /etc/init.d/grommunio-admin-api +user="grommunio" +group="nginx" +pidfile="/run/grommunio/admin-api.pid" + +#output_logger="'logger -t grommunio-admin-api'" +#error_logger="'logger -t grommunio-admin-api -p3'" + uwsgi_opts="--ini /usr/share/grommunio-admin-api/api-config.ini" diff --git a/testing/grommunio-admin-api/rc-service-ctl.sh b/testing/grommunio-admin-api/rc-service-ctl.sh new file mode 100644 index 00000000000..ff3d7031774 --- /dev/null +++ b/testing/grommunio-admin-api/rc-service-ctl.sh @@ -0,0 +1,130 @@ +#!/bin/ash +# +# This script is a wrapper for Alpine Linux openrc tools, i.e. rc-service, rc-update, rc-status +# It allows to control multiple services at once using systemd-like commands +# NOTE: The info command is compatible with the systemctl output expected by grommunio-admin-api +# +# Copyright 2024 Miguel Da Silva, Contauro AG +# Distributed under the terms of the GNU General Public License, v2 or later +# +# Version: 0.2 - 2024-04-04 +# Last change: Added info command for grommunio +# + +usage() { + echo >&2 "Wrapper for openrc tools to control multiple services at once" + echo >&2 + echo >&2 "Usage: $(basename "$0") [options] " + echo >&2 + echo >&2 "Commands: start | stop | reload | restart | | enable | disable | status | info |" + echo >&2 " try-restart | reload-or-restart | try-reload-or-restart" + echo >&2 "Service: one or multiple services separate by blanks" + echo >&2 + echo >&2 "Options:" + echo >&2 " -q, --quiet Run quietly" + exit ${1:-0} +} + +# Show usage by default +[ $# -eq 0 ] && usage + +# Retrieve options and command +prog=""; cmd=""; opt=""; combined=0; try=0 +while [ -z "$cmd" ]; do + case "$1" in + "start") prog="rc-service"; cmd="start" ;; + "stop") prog="rc-service"; cmd="stop" ;; + "reload") prog="rc-service"; cmd="reload" ;; + "restart") prog="rc-service"; cmd="restart" ;; + "enable") prog="rc-update"; cmd="add" ;; + "disable") prog="rc-update"; cmd="del" ;; + "status") prog="rc-service"; cmd="status" ;; + "info") prog="internal"; cmd="info" ;; + "try-restart") prog="rc-service"; cmd="restart" try=1 ;; + "reload-or-restart") prog="rc-service"; cmd="reload-or-restart"; combined=1 ;; + "try-reload-or-restart") prog="rc-service"; cmd="reload-or-restart"; combined=1; try=1 ;; + -h|--help) usage ;; + -q|--quiet) opt="-q"; shift ;; + *) echo >&2 "ERROR: Unknown command."; exit 1 ;; + esac +done + +# Verify service input +if [ -z "$2" ] && [ "$cmd" != "status" ]; then + echo >&2 "ERROR: Specify one or mulitple services as argument." + exit 1 +fi + + +# status command is allowed without service +[ $# -eq 1 ] && [ "$cmd" = "status" ] && rc-status && exit 0 + + +# Loop over services +while [ -n "$2" ]; do + + # Remove suffix '.service' if available + service=${2%%.service} + + # Retrieve initscript. If not found, skip this service. + initscript=$(rc-service -r $service) + if [ -z "$initscript" ]; then + [ "$cmd" != "info" ] && echo -e >&2 "\e[1;31m * \e[0m$service: unknown service" + shift + continue + fi + + # Retrieve service state + servicestate=$(rc-service $service status | awk '{print $3}') + + # No actions if try-flag is set and the service is stopped + [ $try -eq 1 ] && [ "$servicestate" = "stopped" ] && shift && continue + + + ## Invoke external commands + if [ $combined -eq 0 ]; then + # Fix status output for multiple services + statusfix="" + [ "$cmd" = "status" ] && statusfix="| sed 's/status/$service/'" + + [ "$prog" = "rc-service" ] && eval $prog $opt $service $cmd $statusfix + [ "$prog" = "rc-update" ] && eval $prog $opt $cmd $service + else + # combined commands reload/restart + if [ "$prog" = "rc-service" ] && [ "$cmd" = "reload-or-restart" ]; then + eval $prog $opt $service "reload" + [ $? -ne 0 ] && eval $prog $opt $service "restart" + fi + fi + + + ## Process info command + if [ "$prog" = "internal" ] && [ "$cmd" = "info" ]; then + # Retrieve description from init.d file + description=$(grep '^description=' $initscript | cut -d'=' -f2 | tr -d "\"") + + # Retrieve service unit state (enabled/disabled) + unitstate="disabled" + rc-update show | grep -q "$service" && unitstate="enabled" + + # Translate service state to systemd-like activestate and substate + case "$servicestate" in + "started") activestate="active"; substate="running" ;; + "stopped") activestate="inactive"; substate="dead" ;; + "crashed") activestate="failed"; substate="failed" ;; + *) activestate="unknown"; substate="unknown" ;; + esac + + # Print out required variables. Print a newline between items + printf "Names=$service.service\n" + printf "Description=$description\n" + printf "ActiveState=$activestate\n" + printf "SubState=$substate\n" + printf "UnitFileState=$unitstate\n" + printf "ActiveEnterTimestampMonotonic=0\n" + printf "InactiveEnterTimestampMonotonic=0\n" + [ -n "$3" ] && printf "\n" + fi + shift; +done +