ql_serv / docker-entrypoint.sh
lang03383's picture
Update docker-entrypoint.sh
30cf626 verified
#!/bin/bash
dir_shell=/ql/shell
. $dir_shell/share.sh
. $dir_shell/env.sh
python3 -c "from datasets import load_dataset"
echo -e "======================写入rclone配置========================\n"
echo "$RCLONE_CONF" > ~/.config/rclone/rclone.conf
echo -e "======================从 Datasets 下载数据========================\n"
# 使用 Space Secrets 中的环境变量
python3 -c "from datasets import load_dataset; load_dataset('$DATASET_NAME', use_auth_token='$ACCESS_TOKEN').save_to_disk('/ql/data')"
echo -e "数据下载完成...\n"
echo -e "======================1. 检测配置文件========================\n"
import_config "$@"
make_dir /etc/nginx/conf.d
make_dir /run/nginx
init_nginx
fix_config
pm2 l &>/dev/null
echo -e "======================2. 安装依赖========================\n"
patch_version
echo -e "======================3. 启动nginx========================\n"
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
echo -e "nginx启动成功...\n"
echo -e "======================4. 启动pm2服务========================\n"
reload_update
reload_pm2
if [[ $AutoStartBot == true ]]; then
echo -e "======================5. 启动bot========================\n"
nohup ql bot >$dir_log/bot.log 2>&1 &
echo -e "bot后台启动中...\n"
fi
if [[ $EnableExtraShell == true ]]; then
echo -e "====================6. 执行自定义脚本========================\n"
nohup ql extra >$dir_log/extra.log 2>&1 &
echo -e "自定义脚本后台执行中...\n"
fi
echo -e "##########写入登陆信息############"
echo "{ \"username\": \"$ADMIN_USERNAME\", \"password\": \"$ADMIN_PASSWORD\" }" > /ql/data/config/auth.json
echo -e "======================定期备份数据到 Datasets========================\n"
# 设置备份频率 (每分钟备份一次)
BACKUP_FREQUENCY="* * * * *"
# 创建 cron 任务,使用 Space Secrets 中的环境变量
(crontab -l 2>/dev/null; echo "$BACKUP_FREQUENCY python3 -c \"from datasets import load_dataset, DatasetDict; DatasetDict.from_disk('/ql/data').push_to_hub('$DATASET_NAME', use_auth_token='$ACCESS_TOKEN', private=True)\"") | crontab -
echo -e "数据备份任务已设置...\n"
# 保持容器运行
tail -f /dev/null
exec "$@"