launcher.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. set -e
  3. yaml() {
  4. 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', ''))"
  5. }
  6. NSQD_BRORADCAST_ADDRESS=$(yaml ./config/aside.yaml "nsqd.broadcast-address")
  7. NSQD_HTTP_ADDRESS=$(yaml ./config/aside.yaml "nsqd.http-address")
  8. NSQD_TCP_ADDRESS=$(yaml ./config/aside.yaml "nsqd.tcp-address")
  9. NSQLOOKUPD_BROADCAST_ADDRESS=$(yaml ./config/aside.yaml "nsqlookupd.broadcast-address")
  10. NSQLOOKUPD_HTTP_ADDRESS=$(yaml ./config/aside.yaml "nsqlookupd.http-address")
  11. NSQLOOKUPD_TCP_ADDRESS=$(yaml ./config/aside.yaml "nsqlookupd.tcp-address")
  12. NSQADMIN_HTTP_ADDRESS=$(yaml ./config/aside.yaml "nsqadmin.http-address")
  13. NSQD_LAUNCH_ARGS=""
  14. if [ -n "$NSQD_BRORADCAST_ADDRESS" ]; then
  15. NSQD_LAUNCH_ARGS="$NSQD_LAUNCH_ARGS --broadcast-address=$NSQD_BRORADCAST_ADDRESS"
  16. fi
  17. if [ -n "$NSQD_HTTP_ADDRESS" ]; then
  18. NSQD_LAUNCH_ARGS="$NSQD_LAUNCH_ARGS --http-address=$NSQD_HTTP_ADDRESS"
  19. fi
  20. if [ -n "$NSQD_TCP_ADDRESS" ]; then
  21. NSQD_LAUNCH_ARGS="$NSQD_LAUNCH_ARGS --tcp-address=$NSQD_TCP_ADDRESS"
  22. fi
  23. NSQLOOKUPD_LAUNCH_ARGS=""
  24. if [ -n "$NSQLOOKUPD_BROADCAST_ADDRESS" ]; then
  25. NSQLOOKUPD_LAUNCH_ARGS="$NSQLOOKUPD_LAUNCH_ARGS --broadcast-address=$NSQLOOKUPD_BROADCAST_ADDRESS"
  26. fi
  27. if [ -n "$NSQLOOKUPD_HTTP_ADDRESS" ]; then
  28. NSQLOOKUPD_LAUNCH_ARGS="$NSQLOOKUPD_LAUNCH_ARGS --http-address=$NSQLOOKUPD_HTTP_ADDRESS"
  29. fi
  30. if [ -n "$NSQLOOKUPD_TCP_ADDRESS" ]; then
  31. NSQLOOKUPD_LAUNCH_ARGS="$NSQLOOKUPD_LAUNCH_ARGS --tcp-address=$NSQLOOKUPD_TCP_ADDRESS"
  32. fi
  33. NSQADMIN_LAUNCH_ARGS=""
  34. if [ -n "$NSQADMIN_HTTP_ADDRESS" ]; then
  35. NSQADMIN_LAUNCH_ARGS="$NSQADMIN_LAUNCH_ARGS --http-address=$NSQADMIN_HTTP_ADDRESS"
  36. fi
  37. LOOKUPD_TCP_ADDRESS="127.0.0.1:4160"
  38. if [ -n "$NSQLOOKUPD_TCP_ADDRESS" ]; then
  39. LOOKUPD_TCP_ADDRESS="$NSQLOOKUPD_TCP_ADDRESS"
  40. fi
  41. LOOKUPD_HTTP_ADDRESS="127.0.0.1:4161"
  42. if [ -n "$NSQLOOKUPD_HTTP_ADDRESS" ]; then
  43. LOOKUPD_HTTP_ADDRESS="$NSQLOOKUPD_HTTP_ADDRESS"
  44. fi
  45. ./bin/nsqlookupd $NSQLOOKUPD_LAUNCH_ARGS &
  46. ./bin/nsqd $NSQD_LAUNCH_ARGS --lookupd-tcp-address=$LOOKUPD_TCP_ADDRESS &
  47. ./bin/nsqadmin $NSQADMIN_LAUNCH_ARGS --lookupd-http-address=$LOOKUPD_HTTP_ADDRESS &