From f5a7d78d4f3b39283e33a2338d2c45dbdf8a3e23 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Fri, 3 Jul 2026 15:13:55 +0100 Subject: [PATCH] uses custom COMPOSECMD in joeac.net openrc services --- make/container.mk | 11 ------ make/openrc.mk | 4 +- make/vars.mk | 12 ++++++ openrc/init.d/joeac.net | 66 -------------------------------- openrc/init.d/joeac.net.template | 65 +++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 79 deletions(-) delete mode 100755 openrc/init.d/joeac.net create mode 100755 openrc/init.d/joeac.net.template diff --git a/make/container.mk b/make/container.mk index 189d9b4..323ef58 100644 --- a/make/container.mk +++ b/make/container.mk @@ -2,17 +2,6 @@ CPU_ARCH := $(if $(shell which arch 2>/dev/null),\ $(shell arch),\ $(shell lscpu | grep ^Architecture: | sed "s/^Architecture:[[:space:]]*\([[:alnum:][:punct:]]\+\).*/\1/")) IMAGE_PREFIX := $(if $(filter armv7%,$(CPU_ARCH)),armv7/) -COMPOSE_CMD := \ - ALPINE_VERSION="$(ALPINE_VERSION)" \ - IMAGE_PREFIX="$(IMAGE_PREFIX)" \ - GEMINI_CERTIFICATES_DIR="$(GEMINI_CERTIFICATES_DIR)" \ - GEMINI_COMITIUM_DATA_DIR="$(GEMINI_COMITIUM_DATA_DIR)" \ - ETHERPAD_DATA_DIR="$(ETHERPAD_DATA_DIR)" \ - ETHERPAD_VERSION="$(ETHERPAD_VERSION)" \ - VAULTWARDEN_DATA_DIR="$(VAULTWARDEN_DATA_DIR)" \ - LOCAL_SMTP_PORT=$(PORT_smtp) \ - $(foreach module,$(ALL_MODULES),$(call capitalise,$(module))_PORT=$(PORT_$(module))) \ - podman-compose REGISTRY_DOMAIN := git.joeac.net REGISTRY_USER := joeac diff --git a/make/openrc.mk b/make/openrc.mk index fa2c35a..ec76271 100644 --- a/make/openrc.mk +++ b/make/openrc.mk @@ -50,10 +50,10 @@ $(foreach module,$(MODULES),$(eval $(openrc_add_rule))) $(foreach module,$(MODULES),$(eval $(openrc_start_rule))) $(foreach module,$(MODULES),$(eval $(openrc_restart_rule))) -~/.config/rc/init.d/joeac.net: openrc/init.d/joeac.net ~/.config/rc/init.d ~/.config/rc/runlevels/default /etc/init.d/user.$(USER) /etc/conf.d/user.$(USER) +~/.config/rc/init.d/joeac.net: openrc/init.d/joeac.net.template ~/.config/rc/init.d ~/.config/rc/runlevels/default /etc/init.d/user.$(USER) /etc/conf.d/user.$(USER) rm -f ~/.config/rc/init.d/joeac.net; \ mkdir -p ~/.config/rc/init.d; \ - cp openrc/init.d/joeac.net ~/.config/rc/init.d/joeac.net + COMPOSECMD="$(COMPOSE_CMD)" envsubst -i openrc/init.d/joeac.net.template -o ~/.config/rc/init.d/joeac.net ~/.config/rc/init.d: mkdir -p ~/.config/rc/init.d diff --git a/make/vars.mk b/make/vars.mk index b40592e..2ea7f18 100644 --- a/make/vars.mk +++ b/make/vars.mk @@ -53,6 +53,18 @@ INSTALL_RULES := $(foreach module,$(MODULES),install_$(module)) REINSTALL_RULES := $(foreach module,$(MODULES),reinstall_$(module)) UNINSTALL_RULES := $(foreach module,$(MODULES),uninstall_$(module)) +COMPOSE_CMD := \ + ALPINE_VERSION="$(ALPINE_VERSION)" \ + IMAGE_PREFIX="$(IMAGE_PREFIX)" \ + GEMINI_CERTIFICATES_DIR="$(GEMINI_CERTIFICATES_DIR)" \ + GEMINI_COMITIUM_DATA_DIR="$(GEMINI_COMITIUM_DATA_DIR)" \ + ETHERPAD_DATA_DIR="$(ETHERPAD_DATA_DIR)" \ + ETHERPAD_VERSION="$(ETHERPAD_VERSION)" \ + VAULTWARDEN_DATA_DIR="$(VAULTWARDEN_DATA_DIR)" \ + LOCAL_SMTP_PORT=$(PORT_smtp) \ + $(foreach module,$(ALL_MODULES),$(call capitalise,$(module))_PORT=$(PORT_$(module))) \ + podman-compose + $(foreach module,$(ALL_NGINX_MODULES), \ $(if $(SUBDOMAIN_$(module)),, \ $(error $(module) is declared as an nginx module, but SUBDOMAIN_$(module) is not set))) diff --git a/openrc/init.d/joeac.net b/openrc/init.d/joeac.net deleted file mode 100755 index 2d35363..0000000 --- a/openrc/init.d/joeac.net +++ /dev/null @@ -1,66 +0,0 @@ -#!/sbin/openrc-run -# credits: -# https://gist.github.com/itzwam/2069e935385193207f7e5bea7156e21d -# https://github.com/0x17de/dockerservice-openrc - -: ${HOME:=/home/joeac.net} -: ${MODULENAME:=${RC_SVCNAME##*.}} -: ${SRCDIR:=$HOME/joeac.net} -DOCKER_COMPOSE_UP_ARGS=${DOCKER_COMPOSE_UP_ARGS-"--no-build --no-recreate --no-deps"} - -[ -z "${MODULENAME}" ] && exit 1 -: ${COMPOSEFILE:="${SRCDIR}/compose.yml"} -: ${MAKEFILE:="${SRCDIR}/Makefile"} -COMPOSECMD="/usr/bin/podman-compose" -export COMPOSE_HTTP_TIMEOUT=300 - -description="Manage dockerservices defined in ${COMPOSEFILE}" -extra_commands="configtest" -description_configtest="Check configuration via \"podman-compose -f ${COMPOSEFILE} config\"" - -configtest() { - if ! [ -f "${COMPOSEFILE}" ]; then - eerror "The docker-compose file ${COMPOSEFILE} does not exist!" - return 1 - fi - if "${COMPOSECMD}" -f "${COMPOSEFILE}" config >&/dev/null; then - einfo "config: ok" - else - eerror "config: error" - return 1 - fi -} - -start() { - configtest || return 1 - ebegin "Starting ${MODULENAME}" - "${COMPOSECMD}" -f "${COMPOSEFILE}" up -d ${DOCKER_COMPOSE_UP_ARGS} ${MODULENAME} - eend $? -} - -stop() { - ebegin "Stopping ${MODULENAME}" - "${COMPOSECMD}" -f "${COMPOSEFILE}" down --timeout=5 ${MODULENAME} - eend $? -} - -status() { - pods=0 - started=0 - while read pod; do - pod_service="$(podman inspect $pod | jq .[0].Config.Labels.[\"com.docker.compose.service\"])" - if ! [ "$pod_service" = "\"${MODULENAME}\"" ]; then - continue - fi - pods=$(($pods+1)) - if podman top $pod &>/dev/null; then - einfo "status: [$pod] started" - exit 0 - else - einfo "status: [$pod] stopped" - exit 3 - fi - done < <("${COMPOSECMD}" -f "${COMPOSEFILE}" ps --quiet) - einfo "status: no container found for ${MODULENAME}" - exit 3 -} diff --git a/openrc/init.d/joeac.net.template b/openrc/init.d/joeac.net.template new file mode 100755 index 0000000..584cc61 --- /dev/null +++ b/openrc/init.d/joeac.net.template @@ -0,0 +1,65 @@ +#!/sbin/openrc-run +# credits: +# https://gist.github.com/itzwam/2069e935385193207f7e5bea7156e21d +# https://github.com/0x17de/dockerservice-openrc + +: $${HOME:=/home/joeac.net} +: $${MODULENAME:=$${RC_SVCNAME##*.}} +: $${SRCDIR:=$$HOME/joeac.net} +DOCKER_COMPOSE_UP_ARGS=$${DOCKER_COMPOSE_UP_ARGS-"--no-build --no-recreate --no-deps"} + +[ -z "$${MODULENAME}" ] && exit 1 +: $${COMPOSEFILE:="$${SRCDIR}/compose.yml"} +: $${MAKEFILE:="$${SRCDIR}/Makefile"} +export COMPOSE_HTTP_TIMEOUT=300 + +description="Manage dockerservices defined in $${COMPOSEFILE}" +extra_commands="configtest" +description_configtest="Check configuration via \"podman-compose -f $${COMPOSEFILE} config\"" + +configtest() { + if ! [ -f "$${COMPOSEFILE}" ]; then + eerror "The docker-compose file $${COMPOSEFILE} does not exist!" + return 1 + fi + if "${COMPOSECMD}" -f "$${COMPOSEFILE}" config >&/dev/null; then + einfo "config: ok" + else + eerror "config: error" + return 1 + fi +} + +start() { + configtest || return 1 + ebegin "Starting $${MODULENAME}" + "${COMPOSECMD}" -f "$${COMPOSEFILE}" up -d $${DOCKER_COMPOSE_UP_ARGS} $${MODULENAME} + eend $$? +} + +stop() { + ebegin "Stopping $${MODULENAME}" + "${COMPOSECMD}" -f "$${COMPOSEFILE}" down --timeout=5 $${MODULENAME} + eend $$? +} + +status() { + pods=0 + started=0 + while read pod; do + pod_service="$$(podman inspect $$pod | jq .[0].Config.Labels.[\"com.docker.compose.service\"])" + if ! [ "$$pod_service" = "\"$${MODULENAME}\"" ]; then + continue + fi + pods=$$(($$pods+1)) + if podman top $$pod &>/dev/null; then + einfo "status: [$$pod] started" + exit 0 + else + einfo "status: [$$pod] stopped" + exit 3 + fi + done < <("${COMPOSECMD}" -f "$${COMPOSEFILE}" ps --quiet) + einfo "status: no container found for $${MODULENAME}" + exit 3 +}