-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·102 lines (80 loc) · 3.58 KB
/
start.sh
File metadata and controls
executable file
·102 lines (80 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
set -e # Exit on error
# ===================================================================
# Check prerequisites
# ===================================================================
echo "[CHECK] Verifying prerequisites..."
# Check for gcc
if ! command -v gcc &> /dev/null; then
echo "ERROR: gcc is not installed"
echo "Install with: sudo apt-get install build-essential"
exit 1
fi
# Check for sqlite3
if ! command -v sqlite3 &> /dev/null; then
echo "ERROR: sqlite3 is not installed"
echo "Install with: sudo apt-get install sqlite3 libsqlite3-dev"
exit 1
fi
# Check for libsqlite3-dev (check if sqlite3.h header exists)
if [ ! -f /usr/include/sqlite3.h ] && [ ! -f /usr/local/include/sqlite3.h ]; then
echo "ERROR: libsqlite3-dev is not installed (needed for compilation)"
echo "Install with: sudo apt-get install libsqlite3-dev"
exit 1
fi
echo "[CHECK] ✓ All prerequisites found"
echo ""
# ===================================================================
# Prepare build directory
# ===================================================================
echo "[BUILD] Preparing build directory..."
mkdir -p build
rm -f build/*.o build/worker build/gateway
# ===================================================================
# Build
# ===================================================================
echo "[BUILD] Compiling workers with real metrics and smart scheduling..."
gcc -c -o build/worker.o src/worker.c -Isrc -lpthread
gcc -c -o build/metrics_reader.o src/metrics_reader.c -Isrc
gcc -c -o build/metrics_smoother.o src/metrics_smoother.c -Isrc
gcc -c -o build/fd_passing.o src/fd_passing.c -Isrc
gcc -c -o build/http_handler.o src/http_handler.c -Isrc
gcc -o build/worker build/worker.o build/metrics_reader.o build/metrics_smoother.o build/fd_passing.o build/http_handler.o -lpthread
echo "[BUILD] Compiling FaaS compiler library..."
gcc -c -o build/faas_compiler.o src/faas_compiler.c -Isrc -I.
echo "[BUILD] Compiling unified gateway (HTTP + Load Balancer + Compiler)..."
gcc -c -o build/gateway.o src/gateway.c -Isrc -I. -lpthread
gcc -c -o build/config_loader.o src/config_loader.c -Isrc
gcc -c -o build/kv.o src/kv.c -Isrc
gcc -c -o build/kv_sqlite_sync.o src/kv_sqlite_sync.c -Isrc
gcc -c -o build/metrics_collector.o src/metrics_collector.c -Isrc
gcc -o build/gateway build/gateway.o build/http_handler.o build/config_loader.o build/kv.o build/kv_sqlite_sync.o build/metrics_collector.o build/fd_passing.o build/faas_compiler.o -lsqlite3 -lpthread
echo "[BUILD] ✓ Compilation successful"
echo "[BUILD] Binaries in: build/"
echo ""
# ===================================================================
# Initialize database
# ===================================================================
echo "[DB] Initializing database..."
if [ -f faas_meta.db ]; then
echo "[DB] Warning: faas_meta.db already exists, recreating..."
rm -f faas_meta.db
fi
sqlite3 faas_meta.db < init.sql
# Verify database was created correctly
ROUTE_COUNT=$(sqlite3 faas_meta.db "SELECT COUNT(*) FROM functions;")
echo "[DB] ✓ Database initialized with $ROUTE_COUNT routes"
echo ""
# ===================================================================
# Start services
# ===================================================================
echo "[START] Launching workers with metrics..."
./build/worker /tmp/faas_worker_0.sock 0 &
./build/worker /tmp/faas_worker_1.sock 1 &
./build/worker /tmp/faas_worker_2.sock 2 &
./build/worker /tmp/faas_worker_3.sock 3 &
sleep 1
echo "[START] Launching unified gateway on http://localhost:8080"
echo "Press Ctrl+C to stop"
echo ""
./build/gateway