#!/bin/bash
# Starts and stops the Node-RED container for eurogard-nodered.service.
# The fair use terms gate the container, not the Docker daemon (the daemon has to be available for updates).
. /usr/lib/eurogard/nodered/common.sh

case "${1:-}" in
    start)
        if fairuse_ok; then
            cd /docker && docker compose up -d
        else
            log "the fair use terms are not accepted, Node-RED stays stopped"
            docker stop "${CONTAINER}" > /dev/null 2>&1
            exit 0
        fi
        ;;
    stop)
        cd /docker && docker compose stop
        ;;
    *)
        echo "usage: $0 start|stop" >&2
        exit 2
        ;;
esac
