entrypoint.sh


Overview

entrypoint.sh is a Bash script designed as the main startup entry point for a distributed task execution and web service environment. It orchestrates the initialization and launching of multiple components in a software system:

The script parses command-line arguments to enable or disable components, configure runtime parameters such as consumer ID ranges, worker counts, host identifiers, and MCP server connection details. It also dynamically generates a service configuration file from a template by interpolating environment variables.

This script is intended to run inside a Linux environment with Python 3 and necessary dependencies installed. It is typically used as the container or host entrypoint to bootstrap the entire runtime environment for a Ragflow-based distributed compute platform.


Detailed Explanation

Global Variables and Defaults


Functions

usage()

Displays usage instructions and command line options, then exits the script.

./entrypoint.sh --disable-taskexecutor

Prints usage and exits if unknown arguments are passed.


task_exe(consumer_id, host_id)

Starts a single task executor worker in an infinite loop under LD_PRELOAD of jemalloc library for memory optimization.

task_exe 3 myhost123

Starts a task executor for consumer ID 3 on host "myhost123".


start_mcp_server()

Starts the MCP server in the background with configured host, port, base URL, mode, API key, and transport flags.

start_mcp_server

Starts the MCP server on configured parameters.


Command-Line Argument Parsing

The script supports the following command-line options:

Argument

Description

--disable-webserver

Disables starting nginx and ragflow_server.

--disable-taskexecutor

Disables starting task executor workers.

--enable-mcpserver

Enables starting the MCP server.

--consumer-no-beg=<num>

Specifies start of consumer ID range for task executors.

--consumer-no-end=<num>

Specifies end of consumer ID range for task executors.

--workers=<num>

Specifies the number of task executors to run (if consumer range not set).

--host-id=<string>

Sets the unique host ID string. Defaults to hostname or hashed hostname.

--mcp-host=<string>

MCP server host IP or DNS name.

--mcp-port=<num>

MCP server port.

--mcp-base-url=<string>

Base URL for MCP server.

--mcp-mode=<string>

MCP server mode (e.g., self-host).

--mcp-host-api-key=<string>

API key for MCP host authorization.

--mcp-script-path=<string>

Path to MCP server Python script.

--no-transport-sse-enabled

Disable SSE transport flag for MCP server.

--no-transport-streamable-http-enabled

Disable streamable HTTP transport flag for MCP server.

--no-json-response

Disable JSON response flag for MCP server.

Unknown arguments will trigger the usage() function and exit.


Configuration File Generation

The script generates a final service_conf.yaml configuration file from a template service_conf.yaml.template located in /ragflow/conf/ by performing environment variable substitution. This allows dynamic configuration based on runtime environment and arguments.


Component Startup Logic

  1. Web Server (nginx + ragflow_server):
    If enabled, starts nginx daemon and continuously runs ragflow_server.py in a loop in the background.

  2. MCP Server:
    If enabled via --enable-mcpserver, starts the MCP server Python script with configured parameters.

  3. Task Executors:
    If enabled, runs task executors either:

    • For a range of consumer IDs if consumer-no-beg and consumer-no-end are set (start inclusive, end exclusive), or

    • For a fixed number of workers otherwise.

Each task executor runs in the background.

Finally, the script waits for all background jobs to finish (which is normally indefinite).


Important Implementation Details


Interaction with Other System Components


Usage Examples

./entrypoint.sh --disable-taskexecutor
./entrypoint.sh --disable-webserver --consumer-no-beg=0 --consumer-no-end=5
./entrypoint.sh --disable-webserver --workers=2 --host-id=myhost123
./entrypoint.sh --enable-mcpserver

Mermaid Flowchart Diagram

The following flowchart represents the main functions and workflow relationships in entrypoint.sh:

flowchart TD
    A[Start Script] --> B[Parse Command-Line Arguments]
    B --> C[Generate service_conf.yaml from template]

    C --> D{ENABLE_WEBSERVER == 1?}
    D -- Yes --> E[Start nginx]
    E --> F[Start ragflow_server.py in infinite loop]

    D -- No --> G[Skip webserver]

    B --> H{ENABLE_MCP_SERVER == 1?}
    H -- Yes --> I[start_mcp_server()]

    H -- No --> J[Skip MCP server]

    B --> K{ENABLE_TASKEXECUTOR == 1?}
    K -- Yes --> L{CONSUMER_NO_END > CONSUMER_NO_BEG?}
    L -- Yes --> M[Start task_exe() for consumer IDs in range]
    L -- No --> N[Start fixed number of task_exe() workers]

    K -- No --> O[Skip task executors]

    F & I & M & N --> P[wait for background processes]

Summary

entrypoint.sh is a robust, configurable startup script that serves as the main orchestration point for running a Ragflow-based distributed compute environment. It flexibly enables or disables components, dynamically configures the environment, and ensures that critical services and workers are launched and managed reliably. This script is central to bootstrapping the system and managing the lifecycle of web, task executor, and MCP server processes.


End of documentation for entrypoint.sh