diff options
| author | Joe Carstairs <me@joeac.net> | 2026-07-03 15:13:55 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-07-03 15:14:02 +0100 |
| commit | f5a7d78d4f3b39283e33a2338d2c45dbdf8a3e23 (patch) | |
| tree | 4b29ccea8efeca0aafcc600263a59d09ef3e63ba /openrc | |
| parent | c42c6362319c9ad7564e9b17d34a87cefb0cb45e (diff) | |
uses custom COMPOSECMD in joeac.net openrc services
Diffstat (limited to 'openrc')
| -rwxr-xr-x | openrc/init.d/joeac.net | 66 | ||||
| -rwxr-xr-x | openrc/init.d/joeac.net.template | 65 |
2 files changed, 65 insertions, 66 deletions
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 +} |
