refactor(upgrade): Adapt upgrade script for aiohttp auth server

This commit is contained in:
Whispering Wind
2025-08-23 23:08:29 +03:30
committed by GitHub
parent eac9cfde75
commit 80b7af2d61
2 changed files with 32 additions and 22 deletions

View File

@ -49,12 +49,13 @@ After=network.target
[Service] [Service]
Type=simple Type=simple
User=root User=root
WorkingDirectory=/etc/hysteria/core/scripts/hysteria2 WorkingDirectory=/etc/hysteria
ExecStart=/etc/hysteria/hysteria2_venv/bin/python3 /etc/hysteria/core/scripts/hysteria2/auth_server.py ExecStart=/etc/hysteria/hysteria2_venv/bin/python3 /etc/hysteria/core/scripts/hysteria2/auth_server.py
Restart=always Restart=always
RestartSec=3 RestartSec=10
Environment="USERS_FILE=/etc/hysteria/users.json" StandardOutput=journal
Environment="CONFIG_FILE=/etc/hysteria/config.json" StandardError=journal
SyslogIdentifier=hysteria-Auth
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -7,7 +7,7 @@ trap 'echo -e "\n❌ An error occurred. Aborting."; exit 1' ERR
HYSTERIA_INSTALL_DIR="/etc/hysteria" HYSTERIA_INSTALL_DIR="/etc/hysteria"
HYSTERIA_VENV_DIR="$HYSTERIA_INSTALL_DIR/hysteria2_venv" HYSTERIA_VENV_DIR="$HYSTERIA_INSTALL_DIR/hysteria2_venv"
REPO_URL="https://github.com/ReturnFI/Blitz" REPO_URL="https://github.com/ReturnFI/Blitz"
REPO_BRANCH="main" REPO_BRANCH="auth"
GEOSITE_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat" GEOSITE_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat"
GEOIP_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geoip.dat" GEOIP_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geoip.dat"
@ -34,7 +34,6 @@ FILES=(
"$HYSTERIA_INSTALL_DIR/.configs.env" "$HYSTERIA_INSTALL_DIR/.configs.env"
"$HYSTERIA_INSTALL_DIR/nodes.json" "$HYSTERIA_INSTALL_DIR/nodes.json"
"$HYSTERIA_INSTALL_DIR/core/scripts/telegrambot/.env" "$HYSTERIA_INSTALL_DIR/core/scripts/telegrambot/.env"
# "$HYSTERIA_INSTALL_DIR/core/scripts/singbox/.env"
"$HYSTERIA_INSTALL_DIR/core/scripts/normalsub/.env" "$HYSTERIA_INSTALL_DIR/core/scripts/normalsub/.env"
"$HYSTERIA_INSTALL_DIR/core/scripts/normalsub/Caddyfile.normalsub" "$HYSTERIA_INSTALL_DIR/core/scripts/normalsub/Caddyfile.normalsub"
"$HYSTERIA_INSTALL_DIR/core/scripts/webpanel/.env" "$HYSTERIA_INSTALL_DIR/core/scripts/webpanel/.env"
@ -77,15 +76,22 @@ for FILE in "${FILES[@]}"; do
fi fi
done done
# ========== Update Configuration ==========
info "Updating Hysteria configuration for HTTP authentication..."
auth_block='{"type": "http", "http": {"url": "http://127.0.0.1:28262/auth", "timeout": "5s"}}'
if [[ -f "$HYSTERIA_INSTALL_DIR/config.json" ]]; then
jq --argjson auth_block "$auth_block" '.auth = $auth_block' "$HYSTERIA_INSTALL_DIR/config.json" > "$HYSTERIA_INSTALL_DIR/config.json.tmp" && mv "$HYSTERIA_INSTALL_DIR/config.json.tmp" "$HYSTERIA_INSTALL_DIR/config.json"
success "config.json updated to use aiohttp auth server."
else
warn "config.json not found after restore. Skipping auth update."
fi
# ========== Permissions ========== # ========== Permissions ==========
info "Setting ownership and permissions..." info "Setting ownership and permissions..."
chown hysteria:hysteria "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt" chown hysteria:hysteria "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt"
chmod 640 "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt" chmod 640 "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt"
# chown -R hysteria:hysteria "$HYSTERIA_INSTALL_DIR/core/scripts/singbox"
chown -R hysteria:hysteria "$HYSTERIA_INSTALL_DIR/core/scripts/telegrambot" chown -R hysteria:hysteria "$HYSTERIA_INSTALL_DIR/core/scripts/telegrambot"
chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/auth_server.py"
chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/user.sh"
chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/kick.py" chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/kick.py"
# ========== Virtual Environment ========== # ========== Virtual Environment ==========
@ -97,26 +103,29 @@ pip install --upgrade pip >/dev/null
pip install -r requirements.txt >/dev/null pip install -r requirements.txt >/dev/null
success "Python environment ready." success "Python environment ready."
# ========== Scheduler ========== # ========== Systemd Services ==========
info "Ensuring scheduler is set..." info "Ensuring systemd services are configured..."
if source "$HYSTERIA_INSTALL_DIR/core/scripts/scheduler.sh"; then if source "$HYSTERIA_INSTALL_DIR/core/scripts/scheduler.sh"; then
if ! check_scheduler_service; then if ! check_auth_server_service; then
if setup_hysteria_scheduler; then setup_hysteria_auth_server && success "Auth server service configured." || warn "Auth server setup failed."
success "Scheduler service configured."
else
warn "Scheduler setup failed, but continuing upgrade..."
fi
else else
success "Scheduler already set." success "Auth server service already configured."
fi
if ! check_scheduler_service; then
setup_hysteria_scheduler && success "Scheduler service configured." || warn "Scheduler setup failed."
else
success "Scheduler service already set."
fi fi
else else
warn "Failed to source scheduler.sh, continuing without scheduler setup..." warn "Failed to source scheduler.sh, continuing without service setup..."
fi fi
# ========== Restart Services ========== # ========== Restart Services ==========
SERVICES=( SERVICES=(
hysteria-caddy.service hysteria-caddy.service
hysteria-server.service hysteria-server.service
hysteria-auth.service
hysteria-scheduler.service hysteria-scheduler.service
hysteria-telegram-bot.service hysteria-telegram-bot.service
hysteria-normal-sub.service hysteria-normal-sub.service
@ -130,7 +139,7 @@ for SERVICE in "${SERVICES[@]}"; do
if systemctl status "$SERVICE" &>/dev/null; then if systemctl status "$SERVICE" &>/dev/null; then
systemctl restart "$SERVICE" && success "$SERVICE restarted." || warn "$SERVICE failed to restart." systemctl restart "$SERVICE" && success "$SERVICE restarted." || warn "$SERVICE failed to restart."
else else
warn "$SERVICE not found or not installed. Skipping..." warn "$SERVICE not found. Skipping..."
fi fi
done done
@ -144,4 +153,4 @@ fi
# ========== Launch Menu ========== # ========== Launch Menu ==========
sleep 10 sleep 10
chmod +x menu.sh chmod +x menu.sh
./menu.sh ./menu.sh