summaryrefslogtreecommitdiff
path: root/openrc/joeac.net
blob: 83e95660ca84a8f258f165fde8107c981bdd801d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/sbin/openrc-run
# credits:
# https://gist.github.com/itzwam/2069e935385193207f7e5bea7156e21d
# https://github.com/0x17de/dockerservice-openrc

: ${SRCDIR:=/usr/local/lib/joeac.net}
DOCKER_COMPOSE_UP_ARGS=${DOCKER_COMPOSE_UP_ARGS-"--no-build --no-recreate --no-deps"}

[ -z "${SVCNAME}" ] && 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 ${SVCNAME}"
  "${COMPOSECMD}" -f "${COMPOSEFILE}" up -d ${DOCKER_COMPOSE_UP_ARGS}
  eend $?
}

stop() {
  ebegin "Stopping ${SVCNAME}"
  "${COMPOSECMD}" -f "${COMPOSEFILE}" stop --timeout=300
  eend $?
}

status() {
  pods=0
  started=0
  while read pod; do
        pods=$(($pods+1))
        if podman top $pod &>/dev/null; then
                einfo "status: [$pod] started"
                started=$(($started+1))
        else
                einfo "status: [$pod] stopped"
        fi
  done < <("${COMPOSECMD}" -f "${COMPOSEFILE}" ps --quiet)
  if [ $started -eq $pods ]; then
    einfo "status: started"
  else
    einfo "status: stopped"
    return 3
  fi
}