Add web server to cluster demo and fix port bug
- Add web server integration to cluster_demo.sh script - Configure web server port (8090) - Update build_if_needed() to check for toastyfs_web binary - Add get_web_binary() function - Start web server after chunk servers - Update status display to show web server - Update help text to show HTTP interface - Fix bug in web/main.c where --local-port incorrectly set upstream_port instead of local_port The cluster demo now starts a full cluster with: - Metadata server on port 8080 (ToastyFS protocol) - N chunk servers starting from port 8081 - Web server on port 8090 (HTTP interface)
This commit is contained in:
+50
-5
@@ -21,6 +21,7 @@ DATA_DIR="$PROJECT_DIR/cluster_data"
|
|||||||
|
|
||||||
METADATA_PORT=8080
|
METADATA_PORT=8080
|
||||||
CHUNK_SERVER_BASE_PORT=8081
|
CHUNK_SERVER_BASE_PORT=8081
|
||||||
|
WEB_SERVER_PORT=8090
|
||||||
|
|
||||||
# Colors for output
|
# Colors for output
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
@@ -46,8 +47,18 @@ print_error() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
build_if_needed() {
|
build_if_needed() {
|
||||||
|
local need_build=false
|
||||||
|
|
||||||
if [ ! -f "$PROJECT_DIR/toastyfs.out" ] && [ ! -f "$PROJECT_DIR/toastyfs.exe" ]; then
|
if [ ! -f "$PROJECT_DIR/toastyfs.out" ] && [ ! -f "$PROJECT_DIR/toastyfs.exe" ]; then
|
||||||
print_info "Binary not found. Building ToastyFS..."
|
need_build=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$PROJECT_DIR/toastyfs_web.out" ] && [ ! -f "$PROJECT_DIR/toastyfs_web.exe" ]; then
|
||||||
|
need_build=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$need_build" = true ]; then
|
||||||
|
print_info "Binaries not found. Building ToastyFS..."
|
||||||
cd "$PROJECT_DIR"
|
cd "$PROJECT_DIR"
|
||||||
make
|
make
|
||||||
print_success "Build complete"
|
print_success "Build complete"
|
||||||
@@ -65,6 +76,17 @@ get_binary() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_web_binary() {
|
||||||
|
if [ -f "$PROJECT_DIR/toastyfs_web.out" ]; then
|
||||||
|
echo "$PROJECT_DIR/toastyfs_web.out"
|
||||||
|
elif [ -f "$PROJECT_DIR/toastyfs_web.exe" ]; then
|
||||||
|
echo "$PROJECT_DIR/toastyfs_web.exe"
|
||||||
|
else
|
||||||
|
print_error "ToastyFS web binary not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
start_cluster() {
|
start_cluster() {
|
||||||
local num_chunk_servers=${1:-3}
|
local num_chunk_servers=${1:-3}
|
||||||
|
|
||||||
@@ -84,6 +106,7 @@ start_cluster() {
|
|||||||
print_info "Starting ToastyFS cluster..."
|
print_info "Starting ToastyFS cluster..."
|
||||||
print_info " Metadata server: 127.0.0.1:$METADATA_PORT"
|
print_info " Metadata server: 127.0.0.1:$METADATA_PORT"
|
||||||
print_info " Chunk servers: $num_chunk_servers"
|
print_info " Chunk servers: $num_chunk_servers"
|
||||||
|
print_info " Web server: 127.0.0.1:$WEB_SERVER_PORT"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Start metadata server
|
# Start metadata server
|
||||||
@@ -126,12 +149,26 @@ start_cluster() {
|
|||||||
sleep 0.5
|
sleep 0.5
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Start web server
|
||||||
|
local web_binary=$(get_web_binary)
|
||||||
|
print_info "Starting web server on port $WEB_SERVER_PORT..."
|
||||||
|
"$web_binary" \
|
||||||
|
--upstream-addr 127.0.0.1 \
|
||||||
|
--upstream-port $METADATA_PORT \
|
||||||
|
--local-addr 127.0.0.1 \
|
||||||
|
--local-port $WEB_SERVER_PORT \
|
||||||
|
> "$LOG_DIR/web_server.log" 2>&1 &
|
||||||
|
|
||||||
|
local web_pid=$!
|
||||||
|
echo "$web_pid" >> "$PID_FILE"
|
||||||
|
print_success "Web server started (PID: $web_pid)"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
print_success "Cluster started successfully!"
|
print_success "Cluster started successfully!"
|
||||||
echo
|
echo
|
||||||
print_info "Connect to the cluster using:"
|
print_info "Connect to the cluster using:"
|
||||||
print_info " Address: 127.0.0.1"
|
print_info " ToastyFS Protocol: 127.0.0.1:$METADATA_PORT"
|
||||||
print_info " Port: $METADATA_PORT"
|
print_info " HTTP Interface: http://127.0.0.1:$WEB_SERVER_PORT"
|
||||||
echo
|
echo
|
||||||
print_info "View logs at: $LOG_DIR/"
|
print_info "View logs at: $LOG_DIR/"
|
||||||
print_info "Data stored at: $DATA_DIR/"
|
print_info "Data stored at: $DATA_DIR/"
|
||||||
@@ -184,12 +221,20 @@ show_status() {
|
|||||||
local running=0
|
local running=0
|
||||||
local not_running=0
|
local not_running=0
|
||||||
local line_num=0
|
local line_num=0
|
||||||
|
local total_lines=$(wc -l < "$PID_FILE")
|
||||||
|
|
||||||
while IFS= read -r pid; do
|
while IFS= read -r pid; do
|
||||||
if [ -n "$pid" ]; then
|
if [ -n "$pid" ]; then
|
||||||
line_num=$((line_num + 1))
|
line_num=$((line_num + 1))
|
||||||
local server_type="Chunk server $((line_num - 1))"
|
local server_type=""
|
||||||
[ $line_num -eq 1 ] && server_type="Metadata server"
|
|
||||||
|
if [ $line_num -eq 1 ]; then
|
||||||
|
server_type="Metadata server"
|
||||||
|
elif [ $line_num -eq $total_lines ]; then
|
||||||
|
server_type="Web server"
|
||||||
|
else
|
||||||
|
server_type="Chunk server $((line_num - 1))"
|
||||||
|
fi
|
||||||
|
|
||||||
if kill -0 "$pid" 2>/dev/null; then
|
if kill -0 "$pid" 2>/dev/null; then
|
||||||
echo -e " ${GREEN}●${NC} $server_type (PID: $pid) - ${GREEN}running${NC}"
|
echo -e " ${GREEN}●${NC} $server_type (PID: $pid) - ${GREEN}running${NC}"
|
||||||
|
|||||||
+7
-4
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#define UNREACHABLE __builtin_trap()
|
#define UNREACHABLE __builtin_trap()
|
||||||
|
|
||||||
|
#define MAX_PROXIED_OPERATIONS (1<<10)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PROXIED_OPERATION_FREE,
|
PROXIED_OPERATION_FREE,
|
||||||
PROXIED_OPERATION_CREATE_DIR,
|
PROXIED_OPERATION_CREATE_DIR,
|
||||||
@@ -43,8 +45,6 @@ typedef struct {
|
|||||||
|
|
||||||
} ProxiedOperation;
|
} ProxiedOperation;
|
||||||
|
|
||||||
#define MAX_PROXIED_OPERATIONS (1<<10)
|
|
||||||
|
|
||||||
static int find_unused_struct(ProxiedOperation *arr, int num)
|
static int find_unused_struct(ProxiedOperation *arr, int num)
|
||||||
{
|
{
|
||||||
if (num == MAX_PROXIED_OPERATIONS)
|
if (num == MAX_PROXIED_OPERATIONS)
|
||||||
@@ -116,7 +116,7 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr, "Error: Invalid port %s\n", argv[i]);
|
fprintf(stderr, "Error: Invalid port %s\n", argv[i]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
upstream_port = (uint16_t) tmp;
|
local_port = (uint16_t) tmp;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error: Invalid option %s\n", argv[i]);
|
fprintf(stderr, "Error: Invalid option %s\n", argv[i]);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -146,6 +146,9 @@ int main(int argc, char **argv)
|
|||||||
int num_proxied = 0;
|
int num_proxied = 0;
|
||||||
ProxiedOperation proxied[MAX_PROXIED_OPERATIONS];
|
ProxiedOperation proxied[MAX_PROXIED_OPERATIONS];
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_PROXIED_OPERATIONS; i++)
|
||||||
|
proxied[i].type = PROXIED_OPERATION_FREE;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
#define POLL_CAPACITY (HTTP_SERVER_POLL_CAPACITY + TOASTY_POLL_CAPACITY)
|
#define POLL_CAPACITY (HTTP_SERVER_POLL_CAPACITY + TOASTY_POLL_CAPACITY)
|
||||||
@@ -160,7 +163,7 @@ int main(int argc, char **argv)
|
|||||||
reg = (EventRegister) {
|
reg = (EventRegister) {
|
||||||
.ptrs=ptrs,
|
.ptrs=ptrs,
|
||||||
.polled=polled,
|
.polled=polled,
|
||||||
.max_polled=POLL_CAPACITY,
|
.max_polled=HTTP_SERVER_POLL_CAPACITY,
|
||||||
.num_polled=0,
|
.num_polled=0,
|
||||||
};
|
};
|
||||||
if (http_server_register_events(&server, ®) < 0) {
|
if (http_server_register_events(&server, ®) < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user