mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Allow create super user when start rag server. (#10634)
### What problem does this PR solve? New options for rag server scripts to create the super admin user when start server. ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Co-authored-by: Zhichang Yu <yuzhichang@gmail.com> Co-authored-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@ -34,14 +34,17 @@ from common.file_utils import get_project_base_directory
|
|||||||
from common import settings
|
from common import settings
|
||||||
from api.common.base64 import encode_to_base64
|
from api.common.base64 import encode_to_base64
|
||||||
|
|
||||||
|
DEFAULT_SUPERUSER_NICKNAME = os.getenv("DEFAULT_SUPERUSER_NICKNAME", "admin")
|
||||||
|
DEFAULT_SUPERUSER_EMAIL = os.getenv("DEFAULT_SUPERUSER_EMAIL", "admin@ragflow.io")
|
||||||
|
DEFAULT_SUPERUSER_PASSWORD = os.getenv("DEFAULT_SUPERUSER_PASSWORD", "admin")
|
||||||
|
|
||||||
def init_superuser():
|
def init_superuser(nickname=DEFAULT_SUPERUSER_NICKNAME, email=DEFAULT_SUPERUSER_EMAIL, password=DEFAULT_SUPERUSER_PASSWORD, role=UserTenantRole.OWNER):
|
||||||
user_info = {
|
user_info = {
|
||||||
"id": uuid.uuid1().hex,
|
"id": uuid.uuid1().hex,
|
||||||
"password": encode_to_base64("admin"),
|
"password": encode_to_base64(password),
|
||||||
"nickname": "admin",
|
"nickname": nickname,
|
||||||
"is_superuser": True,
|
"is_superuser": True,
|
||||||
"email": "admin@ragflow.io",
|
"email": email,
|
||||||
"creator": "system",
|
"creator": "system",
|
||||||
"status": "1",
|
"status": "1",
|
||||||
}
|
}
|
||||||
@ -58,7 +61,7 @@ def init_superuser():
|
|||||||
"tenant_id": user_info["id"],
|
"tenant_id": user_info["id"],
|
||||||
"user_id": user_info["id"],
|
"user_id": user_info["id"],
|
||||||
"invited_by": user_info["id"],
|
"invited_by": user_info["id"],
|
||||||
"role": UserTenantRole.OWNER
|
"role": role
|
||||||
}
|
}
|
||||||
|
|
||||||
tenant_llm = get_init_tenant_llm(user_info["id"])
|
tenant_llm = get_init_tenant_llm(user_info["id"])
|
||||||
@ -70,7 +73,7 @@ def init_superuser():
|
|||||||
UserTenantService.insert(**usr_tenant)
|
UserTenantService.insert(**usr_tenant)
|
||||||
TenantLLMService.insert_many(tenant_llm)
|
TenantLLMService.insert_many(tenant_llm)
|
||||||
logging.info(
|
logging.info(
|
||||||
"Super user initialized. email: admin@ragflow.io, password: admin. Changing the password after login is strongly recommended.")
|
f"Super user initialized. email: {email}, password: {password}. Changing the password after login is strongly recommended.")
|
||||||
|
|
||||||
chat_mdl = LLMBundle(tenant["id"], LLMType.CHAT, tenant["llm_id"])
|
chat_mdl = LLMBundle(tenant["id"], LLMType.CHAT, tenant["llm_id"])
|
||||||
msg = chat_mdl.chat(system="", history=[
|
msg = chat_mdl.chat(system="", history=[
|
||||||
|
|||||||
@ -37,7 +37,7 @@ from api.db.services.document_service import DocumentService
|
|||||||
from common.file_utils import get_project_base_directory
|
from common.file_utils import get_project_base_directory
|
||||||
from common import settings
|
from common import settings
|
||||||
from api.db.db_models import init_database_tables as init_web_db
|
from api.db.db_models import init_database_tables as init_web_db
|
||||||
from api.db.init_data import init_web_data
|
from api.db.init_data import init_web_data, init_superuser
|
||||||
from common.versions import get_ragflow_version
|
from common.versions import get_ragflow_version
|
||||||
from common.config_utils import show_configs
|
from common.config_utils import show_configs
|
||||||
from common.mcp_tool_call_conn import shutdown_all_mcp_sessions
|
from common.mcp_tool_call_conn import shutdown_all_mcp_sessions
|
||||||
@ -109,11 +109,16 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--debug", default=False, help="debug mode", action="store_true"
|
"--debug", default=False, help="debug mode", action="store_true"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--init-superuser", default=False, help="init superuser", action="store_true"
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.version:
|
if args.version:
|
||||||
print(get_ragflow_version())
|
print(get_ragflow_version())
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
if args.init_superuser:
|
||||||
|
init_superuser()
|
||||||
RuntimeConfig.DEBUG = args.debug
|
RuntimeConfig.DEBUG = args.debug
|
||||||
if RuntimeConfig.DEBUG:
|
if RuntimeConfig.DEBUG:
|
||||||
logging.info("run on debug mode")
|
logging.info("run on debug mode")
|
||||||
|
|||||||
@ -13,6 +13,7 @@ function usage() {
|
|||||||
echo " --disable-datasync Disables synchronization of datasource workers."
|
echo " --disable-datasync Disables synchronization of datasource workers."
|
||||||
echo " --enable-mcpserver Enables the MCP server."
|
echo " --enable-mcpserver Enables the MCP server."
|
||||||
echo " --enable-adminserver Enables the Admin server."
|
echo " --enable-adminserver Enables the Admin server."
|
||||||
|
echo " --init-superuser Initializes the superuser."
|
||||||
echo " --consumer-no-beg=<num> Start range for consumers (if using range-based)."
|
echo " --consumer-no-beg=<num> Start range for consumers (if using range-based)."
|
||||||
echo " --consumer-no-end=<num> End range for consumers (if using range-based)."
|
echo " --consumer-no-end=<num> End range for consumers (if using range-based)."
|
||||||
echo " --workers=<num> Number of task executors to run (if range is not used)."
|
echo " --workers=<num> Number of task executors to run (if range is not used)."
|
||||||
@ -24,6 +25,7 @@ function usage() {
|
|||||||
echo " $0 --disable-webserver --workers=2 --host-id=myhost123"
|
echo " $0 --disable-webserver --workers=2 --host-id=myhost123"
|
||||||
echo " $0 --enable-mcpserver"
|
echo " $0 --enable-mcpserver"
|
||||||
echo " $0 --enable-adminserver"
|
echo " $0 --enable-adminserver"
|
||||||
|
echo " $0 --init-superuser"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +34,7 @@ ENABLE_TASKEXECUTOR=1 # Default to enable task executor
|
|||||||
ENABLE_DATASYNC=1
|
ENABLE_DATASYNC=1
|
||||||
ENABLE_MCP_SERVER=0
|
ENABLE_MCP_SERVER=0
|
||||||
ENABLE_ADMIN_SERVER=0 # Default close admin server
|
ENABLE_ADMIN_SERVER=0 # Default close admin server
|
||||||
|
INIT_SUPERUSER_ARGS="" # Default to not initialize superuser
|
||||||
CONSUMER_NO_BEG=0
|
CONSUMER_NO_BEG=0
|
||||||
CONSUMER_NO_END=0
|
CONSUMER_NO_END=0
|
||||||
WORKERS=1
|
WORKERS=1
|
||||||
@ -83,6 +86,10 @@ for arg in "$@"; do
|
|||||||
ENABLE_ADMIN_SERVER=1
|
ENABLE_ADMIN_SERVER=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--init-superuser)
|
||||||
|
INIT_SUPERUSER_ARGS="--init-superuser"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--mcp-host=*)
|
--mcp-host=*)
|
||||||
MCP_HOST="${arg#*=}"
|
MCP_HOST="${arg#*=}"
|
||||||
shift
|
shift
|
||||||
@ -240,7 +247,7 @@ if [[ "${ENABLE_WEBSERVER}" -eq 1 ]]; then
|
|||||||
|
|
||||||
echo "Starting ragflow_server..."
|
echo "Starting ragflow_server..."
|
||||||
while true; do
|
while true; do
|
||||||
"$PY" api/ragflow_server.py &
|
"$PY" api/ragflow_server.py ${INIT_SUPERUSER_ARGS} &
|
||||||
wait;
|
wait;
|
||||||
sleep 1;
|
sleep 1;
|
||||||
done &
|
done &
|
||||||
|
|||||||
Reference in New Issue
Block a user