#!/bin/sh
source /etc/karoo.conf.d/config/redis-connect-info

REDIS_CMD="redis-cli -a ${REDIS_PASS} -h ${REDIS_HOST} -p ${REDIS_PORT}"

if [ -z "$1" ]; then
    echo "Please provide the log level.  Options are (fatal critical error warning notice debug information trace)"
    exit 1
else
    PUBLISH_CMD="{\"event-name\" : \"log-level\", \"event-args\" : \"$1\"}"
    if ${REDIS_CMD}  PUBLISH SBC-CHANNEL "${PUBLISH_CMD}" > /dev/null; then
        echo "Log level set to $1"
        exit 0
    else
        echo "Is Karoo and Redis running?"
        exit 1
    fi
fi
