askrobots / dbbasic-object-primitive
Public
Python functions as REST objects, with clustering, load balancing and state replication; no containers or orchestration.
start_cluster.sh · 1.9 KB · 51 lines
| 1 | #!/bin/bash |
| 2 | # Start the entire cluster |
| 3 | # Run this from the master station |
| 4 | # Reads configuration from cluster.tsv |
| 5 | |
| 6 | # Load cluster configuration |
| 7 | eval "$(python cluster_shell_helper.py)" |
| 8 | |
| 9 | echo "=== Starting ${WORKER_COUNT}-Station Cluster ===" |
| 10 | echo |
| 11 | |
| 12 | echo "Starting master ($MASTER_ID - this machine)..." |
| 13 | echo "Run manually in separate terminal:" |
| 14 | echo " cd /Users/danq/multiplexing && source .venv/bin/activate && python run_server.py" |
| 15 | echo |
| 16 | |
| 17 | echo "Starting workers..." |
| 18 | echo |
| 19 | |
| 20 | # Start worker 1 (station2) |
| 21 | if [ -n "$WORKER1_ID" ]; then |
| 22 | echo "Starting $WORKER1_ID ($WORKER1_HOST)..." |
| 23 | ssh "$WORKER1_SSH" "cd ~/multiplexing && source .venv/bin/activate && STATION_ID=$WORKER1_ID nohup .venv/bin/python run_server.py > server.log 2>&1 &" |
| 24 | sleep 2 |
| 25 | ssh "$WORKER1_SSH" "cd ~/multiplexing && source .venv/bin/activate && nohup .venv/bin/python cluster_heartbeat_daemon.py $MASTER_HOST --station-id $WORKER1_ID > heartbeat.log 2>&1 &" |
| 26 | echo "✓ $WORKER1_ID started" |
| 27 | echo |
| 28 | fi |
| 29 | |
| 30 | # Start worker 2 (station3) |
| 31 | if [ -n "$WORKER2_ID" ]; then |
| 32 | echo "Starting $WORKER2_ID ($WORKER2_HOST)..." |
| 33 | ssh "$WORKER2_SSH" "cd ~/multiplexing && source .venv/bin/activate && STATION_ID=$WORKER2_ID nohup .venv/bin/python run_server.py > server.log 2>&1 &" |
| 34 | sleep 2 |
| 35 | ssh "$WORKER2_SSH" "cd ~/multiplexing && source .venv/bin/activate && nohup .venv/bin/python cluster_heartbeat_daemon.py $MASTER_HOST --station-id $WORKER2_ID > heartbeat.log 2>&1 &" |
| 36 | echo "✓ $WORKER2_ID started" |
| 37 | echo |
| 38 | fi |
| 39 | |
| 40 | echo "Waiting for stations to register..." |
| 41 | sleep 3 |
| 42 | echo |
| 43 | |
| 44 | echo "=== Cluster Status ===" |
| 45 | curl -s http://localhost:${MASTER_PORT}/cluster/stations | python3 -m json.tool |
| 46 | |
| 47 | echo |
| 48 | echo "=== Cluster Ready ===" |
| 49 | echo "Master: http://localhost:${MASTER_PORT}/dashboard" |
| 50 | [ -n "$WORKER1_HOST" ] && echo "Worker 1: http://${WORKER1_HOST}:${WORKER1_PORT}/dashboard" |
| 51 | [ -n "$WORKER2_HOST" ] && echo "Worker 2: http://${WORKER2_HOST}:${WORKER2_PORT}/dashboard" |