Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Go: add more start server parameters (#16093)

Jin Hai6865039a227e
diff --git a/build.sh b/build.sh
index 05b3274bb4..7204d2065a 100755
--- a/build.sh
+++ b/build.sh
@@ -16,6 +16,7 @@ CPP_DIR="$PROJECT_ROOT/internal/cpp"
BUILD_DIR="$CPP_DIR/cmake-build-release"
RAGFLOW_SERVER_BINARY="$PROJECT_ROOT/bin/ragflow_server"
ADMIN_SERVER_BINARY="$PROJECT_ROOT/bin/admin_server"
+INGESTOR_BINARY="$PROJECT_ROOT/bin/ingestor"
RAGFLOW_CLI_BINARY="$PROJECT_ROOT/bin/ragflow_cli"
# office_oxide native library settings
@@ -261,13 +262,16 @@ build_go() {
export CGO_LDFLAGS="-L${OFFICE_OXIDE_PREFIX}/lib -loffice_oxide -Wl,-rpath,${OFFICE_OXIDE_PREFIX}/lib${CGO_LDFLAGS:+ $CGO_LDFLAGS}"
echo "Exporting CGO_LDFLAGS: $CGO_LDFLAGS"
- echo "Building RAGFlow binary: $RAGFLOW_SERVER_BINARY, $ADMIN_SERVER_BINARY, and $RAGFLOW_CLI_BINARY"
+ echo "Building RAGFlow binary: $RAGFLOW_SERVER_BINARY, $ADMIN_SERVER_BINARY, $INGESTOR_BINARY, and $RAGFLOW_CLI_BINARY"
GOPROXY=${GOPROXY:-https://goproxy.cn,https://proxy.golang.org,direct} CGO_ENABLED=1 \
CGO_CFLAGS="$CGO_CFLAGS" CGO_LDFLAGS="$CGO_LDFLAGS" \
go build -o "$RAGFLOW_SERVER_BINARY" cmd/server_main.go
GOPROXY=${GOPROXY:-https://goproxy.cn,https://proxy.golang.org,direct} CGO_ENABLED=1 \
CGO_CFLAGS="$CGO_CFLAGS" CGO_LDFLAGS="$CGO_LDFLAGS" \
go build -o "$ADMIN_SERVER_BINARY" cmd/admin_server.go
+ GOPROXY=${GOPROXY:-https://goproxy.cn,https://proxy.golang.org,direct} CGO_ENABLED=1 \
+ CGO_CFLAGS="$CGO_CFLAGS" CGO_LDFLAGS="$CGO_LDFLAGS" \
+ go build -o "$INGESTOR_BINARY" cmd/ingestor.go
GOPROXY=${GOPROXY:-https://goproxy.cn,https://proxy.golang.org,direct} CGO_ENABLED=1 \
CGO_CFLAGS="$CGO_CFLAGS" CGO_LDFLAGS="$CGO_LDFLAGS" \
go build -o "$RAGFLOW_CLI_BINARY" cmd/ragflow_cli.go
@@ -282,9 +286,15 @@ build_go() {
exit 1
fi
+ if [ ! -f "$INGESTOR_BINARY" ]; then
+ echo -e "${RED}Error: Failed to build Ingestor binary${NC}"
+ exit 1
+ fi
+
echo -e "${GREEN}✓ Go ragflow_server built successfully: $RAGFLOW_SERVER_BINARY${NC}"
echo -e "${GREEN}✓ Go admin_server built successfully: $ADMIN_SERVER_BINARY${NC}"
echo -e "${GREEN}✓ Go ragflow_cli built successfully: $RAGFLOW_CLI_BINARY${NC}"
+ echo -e "${GREEN}✓ Go ingestor built successfully: $INGESTOR_BINARY${NC}"
}
# Clean build artifacts
@@ -294,6 +304,8 @@ clean() {
rm -rf "$BUILD_DIR"
rm -f "$RAGFLOW_SERVER_BINARY"
rm -f "$ADMIN_SERVER_BINARY"
+ rm -f "$INGESTOR_BINARY"
+ rm -f "$RAGFLOW_CLI_BINARY"
echo -e "${GREEN}✓ Build artifacts cleaned${NC}"
}
@@ -308,6 +320,10 @@ run() {
echo -e "${RED}Error: $RAGFLOW_SERVER_BINARY not found. Build first with --all or --go${NC}"
exit 1
fi
+ if [ ! -f "$INGESTOR_BINARY" ]; then
+ echo -e "${RED}Error: $INGESTOR_BINARY not found. Build first with --all or --go${NC}"
+ exit 1
+ fi
cd "$PROJECT_ROOT"
@@ -322,6 +338,12 @@ run() {
# ragflow_server starts sending heartbeats to it.
sleep 1
+ print_section "Starting ingestor (background)"
+ "$INGESTOR_BINARY" &
+ INGESTOR_PID=$!
+ trap 'kill "$INGESTOR_PID" 2>/dev/null || true' EXIT INT TERM
+ sleep 1
+
print_section "Starting RAGFlow server (foreground)"
"$RAGFLOW_SERVER_BINARY"
}
@@ -396,7 +418,7 @@ main() {
build_cpp
build_go
echo -e "\n${GREEN}=== Build completed successfully! ===${NC}"
- echo "Binary: $RAGFLOW_SERVER_BINARY, $ADMIN_SERVER_BINARY"
+ echo "Binary: $RAGFLOW_SERVER_BINARY, $ADMIN_SERVER_BINARY, $INGESTOR_BINARY, $RAGFLOW_CLI_BINARY"
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
diff --git a/cmd/admin_server.go b/cmd/admin_server.go
index 4e650d1e79..0870f52fcc 100644
--- a/cmd/admin_server.go
+++ b/cmd/admin_server.go
@@ -41,11 +41,38 @@ import (
"ragflow/internal/server"
)
+func printHelp() {
+ fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS]\n\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, "RAGFlow Admin Server\n\n")
+ fmt.Fprintf(os.Stderr, "Options:\n")
+ fmt.Fprintf(os.Stderr, " --config string\tPath to configuration file\n")
+ fmt.Fprintf(os.Stderr, " -v, --version \tPrint version information and exit\n")
+ fmt.Fprintf(os.Stderr, " --debug \tEnable debug-level logging\n")
+ fmt.Fprintf(os.Stderr, " --init-superuser\tInitialize superuser account\n")
+ fmt.Fprintf(os.Stderr, " -h, --help \tShow this help message and exit\n")
+}
+
func main() {
var configPath string
flag.StringVar(&configPath, "config", "", "Path to configuration file")
+ var debugFlag bool
+ flag.BoolVar(&debugFlag, "debug", false, "Enable debug-level logging")
+ var versionFlag bool
+ flag.BoolVar(&versionFlag, "version", false, "Print version information and exit")
+ var initSuperuser bool
+ flag.BoolVar(&initSuperuser, "init-superuser", false, "Initialize superuser account")
+
+ // Custom help message
+ flag.Usage = printHelp
+
flag.Parse()
+ // Handle --version flag: print version and exit immediately
+ if versionFlag {
+ fmt.Printf("RAGFlow version: %s\n", utility.GetRAGFlowVersion())
+ return
+ }
+
// Initialize logger
if err := common.Init("info", "admin_server.log"); err != nil {
panic("failed to initialize logger: " + err.Error())
@@ -60,10 +87,17 @@ func main() {
cfg := server.GetConfig()
// Reinitialize logger with configured level if different
- if cfg.Log.Level != "" && cfg.Log.Level != "info" {
- if err := common.Init(cfg.Log.Level, "admin_server.log"); err != nil {
- common.Error("Failed to reinitialize logger with configured level", err)
- }
+ logLevel := cfg.Log.Level
+ if logLevel == "" {
+ logLevel = "info"
+ }
+
+ if debugFlag {
+ logLevel = "debug"
+ }
+
+ if err := common.Init(logLevel, "admin_server.log"); err != nil {
+ common.Error("Failed to reinitialize logger with configured level", err)
}
// Set logger for server package
@@ -109,9 +143,12 @@ func main() {
adminService := admin.NewService()
adminHandler := admin.NewHandler(adminService)
- // Initialize default admin user
- if err := adminService.InitDefaultAdmin(); err != nil {
- common.Error("Failed to initialize default admin user", err)
+ if initSuperuser {
+ // Initialize default admin user
+ if err := adminService.InitDefaultAdmin(); err != nil {
+ common.Error("Failed to initialize default admin user", err)
+ }
+
}
// Initialize router
diff --git a/cmd/ingestor.go b/cmd/ingestor.go
index 8b740f8a1f..e1bc2e2219 100644
--- a/cmd/ingestor.go
+++ b/cmd/ingestor.go
@@ -51,11 +51,15 @@ func printIngestionServerHelp() {
fmt.Fprintf(os.Stderr, " --name string\t\tIngestion server name (default: \"default_ingestion\")\n")
fmt.Fprintf(os.Stderr, " --admin-host string\tAdmin server host (overrides config file)\n")
fmt.Fprintf(os.Stderr, " --admin-port int\tAdmin server port (overrides config file)\n")
+ fmt.Fprintf(os.Stderr, " --version \tPrint version information and exit\n")
+ fmt.Fprintf(os.Stderr, " --debug \tEnable debug-level logging\n")
fmt.Fprintf(os.Stderr, " -h, --help\t\tShow this help message and exit\n")
fmt.Fprintf(os.Stderr, "\nExamples:\n")
fmt.Fprintf(os.Stderr, " %s # Start with default config\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s -f /path/to/config.yaml # Start with custom config file\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s --admin-host 10.0.0.1 --admin-port 9383\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, " %s --version \t\t# Show version and exit\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, " %s --debug \t\t# Start with debug logging\n", os.Args[0])
}
func main() {
@@ -69,12 +73,22 @@ func main() {
flag.StringVar(&name, "name", "default_ingestion", "Ingestion server name")
flag.StringVar(&adminHost, "admin-host", "", "Admin server host (overrides config file)")
flag.IntVar(&adminPort, "admin-port", 0, "Admin server port (overrides config file)")
+ var debugFlag bool
+ flag.BoolVar(&debugFlag, "debug", false, "Enable debug-level logging")
+ var versionFlag bool
+ flag.BoolVar(&versionFlag, "version", false, "Print version information and exit")
// Custom help message
flag.Usage = printIngestionServerHelp
flag.Parse()
+ // Handle --version flag: print version and exit immediately
+ if versionFlag {
+ fmt.Printf("RAGFlow version: %s\n", utility.GetRAGFlowVersion())
+ return
+ }
+
// Initialize logger with default level
if err := common.Init("info", "ingestion_server.log"); err != nil {
panic(fmt.Sprintf("Failed to initialize logger: %v", err))
@@ -104,6 +118,11 @@ func main() {
if level == "" {
level = "info"
}
+
+ if debugFlag {
+ level = "debug"
+ }
+
if err := common.Init(level, "ingestion_server.log"); err != nil {
common.Error("Failed to reinitialize logger", err)
}
diff --git a/cmd/server_main.go b/cmd/server_main.go
index 67cf7283cb..82e8a3be9b 100644
--- a/cmd/server_main.go
+++ b/cmd/server_main.go
@@ -54,12 +54,16 @@ func printHelp() {
fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS]\n\n", os.Args[0])
fmt.Fprintf(os.Stderr, "RAGFlow Server - Open-source RAG engine based on deep document understanding\n\n")
fmt.Fprintf(os.Stderr, "Options:\n")
- fmt.Fprintf(os.Stderr, " -p, --port int\tServer port (overrides config file)\n")
- fmt.Fprintf(os.Stderr, " -h, --help \tShow this help message and exit\n")
+ fmt.Fprintf(os.Stderr, " -p, --port int\t\tServer port (overrides config file)\n")
+ fmt.Fprintf(os.Stderr, " -v, --version \tPrint version information and exit\n")
+ fmt.Fprintf(os.Stderr, " --debug \tEnable debug-level logging\n")
+ fmt.Fprintf(os.Stderr, " -h, --help \tShow this help message and exit\n")
fmt.Fprintf(os.Stderr, "\nExamples:\n")
- fmt.Fprintf(os.Stderr, " %s # Start server with config file port\n", os.Args[0])
- fmt.Fprintf(os.Stderr, " %s -p 8080 # Start server on port 8080\n", os.Args[0])
- fmt.Fprintf(os.Stderr, " %s --port 8080 # Start server on port 8080\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, " %s \t\t# Start server with config file port\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, " %s -p 8080 \t\t# Start server on port 8080\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, " %s --port 8080 \t# Start server on port 8080\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, " %s --version \t# Show version and exit\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, " %s --debug \t# Start server with debug logging\n", os.Args[0])
}
func main() {
@@ -67,12 +71,22 @@ func main() {
var portFlag int
flag.IntVar(&portFlag, "port", 0, "Server port (overrides config file)")
flag.IntVar(&portFlag, "p", 0, "Server port (shorthand, overrides config file)")
+ var debugFlag bool
+ flag.BoolVar(&debugFlag, "debug", false, "Enable debug-level logging")
+ var versionFlag bool
+ flag.BoolVar(&versionFlag, "version", false, "Print version information and exit")
// Custom help message
flag.Usage = printHelp
flag.Parse()
+ // Handle --version flag: print version and exit immediately
+ if versionFlag {
+ fmt.Printf("RAGFlow version: %s\n", utility.GetRAGFlowVersion())
+ return
+ }
+
// Initialize logger with default level
// logger.Init("info"); // set debug log level
if err := common.Init("info", "server_main.log"); err != nil {
@@ -100,6 +114,11 @@ func main() {
if level == "" {
level = "info"
}
+
+ if debugFlag {
+ level = "debug"
+ }
+
if err := common.Init(level, "server_main.log"); err != nil {
common.Error("Failed to reinitialize logger", err)
}
diff --git a/internal/admin/service.go b/internal/admin/service.go
index 351abafc3d..5fa3ac4b29 100644
--- a/internal/admin/service.go
+++ b/internal/admin/service.go
@@ -1811,6 +1811,7 @@ func (s *Service) InitDefaultAdmin() error {
return fmt.Errorf("failed to add tenant for admin: %w", err)
}
+ common.Info("Init default super user successfully")
return nil
}
@@ -1838,6 +1839,7 @@ func (s *Service) InitDefaultAdmin() error {
}
}
+ common.Info("Init default super user successfully")
return nil
}