#!/bin/bash set -e yaml() { python3 -c "import yaml; from functools import reduce; deep_get = lambda d, k, default=None: reduce(lambda d, key: d.get(key, default) if isinstance(d, dict) else default, k.split('.'), d); value=yaml.safe_load(open('$1')); print(deep_get(value, '$2', ''))" } NSQD_BRORADCAST_ADDRESS=$(yaml ./config/aside.yaml "nsqd.broadcast-address") NSQD_HTTP_ADDRESS=$(yaml ./config/aside.yaml "nsqd.http-address") NSQD_TCP_ADDRESS=$(yaml ./config/aside.yaml "nsqd.tcp-address") NSQLOOKUPD_BROADCAST_ADDRESS=$(yaml ./config/aside.yaml "nsqlookupd.broadcast-address") NSQLOOKUPD_HTTP_ADDRESS=$(yaml ./config/aside.yaml "nsqlookupd.http-address") NSQLOOKUPD_TCP_ADDRESS=$(yaml ./config/aside.yaml "nsqlookupd.tcp-address") NSQADMIN_HTTP_ADDRESS=$(yaml ./config/aside.yaml "nsqadmin.http-address") NSQD_LAUNCH_ARGS="" if [ -n "$NSQD_BRORADCAST_ADDRESS" ]; then NSQD_LAUNCH_ARGS="$NSQD_LAUNCH_ARGS --broadcast-address=$NSQD_BRORADCAST_ADDRESS" fi if [ -n "$NSQD_HTTP_ADDRESS" ]; then NSQD_LAUNCH_ARGS="$NSQD_LAUNCH_ARGS --http-address=$NSQD_HTTP_ADDRESS" fi if [ -n "$NSQD_TCP_ADDRESS" ]; then NSQD_LAUNCH_ARGS="$NSQD_LAUNCH_ARGS --tcp-address=$NSQD_TCP_ADDRESS" fi NSQLOOKUPD_LAUNCH_ARGS="" if [ -n "$NSQLOOKUPD_BROADCAST_ADDRESS" ]; then NSQLOOKUPD_LAUNCH_ARGS="$NSQLOOKUPD_LAUNCH_ARGS --broadcast-address=$NSQLOOKUPD_BROADCAST_ADDRESS" fi if [ -n "$NSQLOOKUPD_HTTP_ADDRESS" ]; then NSQLOOKUPD_LAUNCH_ARGS="$NSQLOOKUPD_LAUNCH_ARGS --http-address=$NSQLOOKUPD_HTTP_ADDRESS" fi if [ -n "$NSQLOOKUPD_TCP_ADDRESS" ]; then NSQLOOKUPD_LAUNCH_ARGS="$NSQLOOKUPD_LAUNCH_ARGS --tcp-address=$NSQLOOKUPD_TCP_ADDRESS" fi NSQADMIN_LAUNCH_ARGS="" if [ -n "$NSQADMIN_HTTP_ADDRESS" ]; then NSQADMIN_LAUNCH_ARGS="$NSQADMIN_LAUNCH_ARGS --http-address=$NSQADMIN_HTTP_ADDRESS" fi LOOKUPD_TCP_ADDRESS="127.0.0.1:4160" if [ -n "$NSQLOOKUPD_TCP_ADDRESS" ]; then LOOKUPD_TCP_ADDRESS="$NSQLOOKUPD_TCP_ADDRESS" fi LOOKUPD_HTTP_ADDRESS="127.0.0.1:4161" if [ -n "$NSQLOOKUPD_HTTP_ADDRESS" ]; then LOOKUPD_HTTP_ADDRESS="$NSQLOOKUPD_HTTP_ADDRESS" fi ./bin/nsqlookupd $NSQLOOKUPD_LAUNCH_ARGS & ./bin/nsqd $NSQD_LAUNCH_ARGS --lookupd-tcp-address=$LOOKUPD_TCP_ADDRESS & ./bin/nsqadmin $NSQADMIN_LAUNCH_ARGS --lookupd-http-address=$LOOKUPD_HTTP_ADDRESS &