diff --git a/core/scripts/hysteria2/install.sh b/core/scripts/hysteria2/install.sh index 761ed4d..f4b64a4 100644 --- a/core/scripts/hysteria2/install.sh +++ b/core/scripts/hysteria2/install.sh @@ -2,6 +2,7 @@ source /etc/hysteria/core/scripts/path.sh source /etc/hysteria/core/scripts/utils.sh +source /etc/hysteria/core/scripts/scheduler_setup.sh define_colors install_hysteria() { @@ -82,11 +83,9 @@ install_hysteria() { chmod +x /etc/hysteria/core/scripts/hysteria2/user.sh chmod +x /etc/hysteria/core/scripts/hysteria2/kick.py - (crontab -l ; echo "*/1 * * * * /bin/bash -c 'source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/cli.py traffic-status --no-gui'") | crontab - - # (crontab -l ; echo "0 3 */3 * * /bin/bash -c 'source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/cli.py restart-hysteria2' >/dev/null 2>&1") | crontab - - (crontab -l ; echo "0 */6 * * * /bin/bash -c 'source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/cli.py backup-hysteria' >/dev/null 2>&1") | crontab - - # (crontab -l ; echo "*/1 * * * * /bin/bash -c 'source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/scripts/hysteria2/kick.py' >/dev/null 2>&1") | crontab - - + if ! check_scheduler_service; then + setup_hysteria_scheduler + fi } if systemctl is-active --quiet hysteria-server.service; then diff --git a/core/scripts/scheduler.sh b/core/scripts/scheduler.sh new file mode 100644 index 0000000..1e2bb1d --- /dev/null +++ b/core/scripts/scheduler.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +setup_hysteria_scheduler() { + echo "Setting up Hysteria scheduler service..." + + chmod +x /etc/hysteria/core/scripts/scheduler.py + + cat > /etc/systemd/system/hysteria-scheduler.service << 'EOF' +[Unit] +Description=Hysteria2 Scheduler Service +After=network.target + +[Service] +Type=simple +User=root +WorkingDirectory=/etc/hysteria +ExecStart=/etc/hysteria/hysteria2_venv/bin/python3 /etc/hysteria/core/scripts/scheduler.py +Restart=always +RestartSec=10 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=hysteria-scheduler + +[Install] +WantedBy=multi-user.target +EOF + + systemctl daemon-reload + systemctl enable hysteria-scheduler.service + systemctl start hysteria-scheduler.service + + (crontab -l | grep -v "hysteria2_venv.*traffic-status" | grep -v "hysteria2_venv.*backup-hysteria") | crontab - + + echo "Hysteria scheduler service has been installed and started." + echo "You can check the status with: systemctl status hysteria-scheduler" + echo "Logs are available at: journalctl -u hysteria-scheduler" +} + +check_scheduler_service() { + if systemctl is-active --quiet hysteria-scheduler.service; then + echo "Hysteria scheduler service is already active." + return 0 + else + return 1 + fi +} + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + setup_hysteria_scheduler +fi \ No newline at end of file diff --git a/upgrade.sh b/upgrade.sh index 908838b..d99afd0 100644 --- a/upgrade.sh +++ b/upgrade.sh @@ -16,21 +16,6 @@ FILES=( "/etc/hysteria/core/scripts/webpanel/Caddyfile" ) -if crontab -l 2>/dev/null | grep -q "source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/cli.py" || \ - crontab -l 2>/dev/null | grep -q "/etc/hysteria/core/scripts/hysteria2/kick.sh"; then - - echo "Removing existing Hysteria cronjobs..." - crontab -l | grep -v "source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/cli.py traffic-status" | \ - grep -v "source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/cli.py restart-hysteria2" | \ - grep -v "source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/cli.py backup-hysteria" | \ - grep -v "/etc/hysteria/core/scripts/hysteria2/kick.sh" | \ - crontab - - echo "Old Hysteria cronjobs removed successfully." -else - echo "No existing Hysteria cronjobs found. Skipping removal." -fi - - echo "Backing up files to $TEMP_DIR" for FILE in "${FILES[@]}"; do mkdir -p "$TEMP_DIR/$(dirname "$FILE")" @@ -41,7 +26,7 @@ echo "Removing /etc/hysteria directory" rm -rf /etc/hysteria/ echo "Cloning Blitz repository" -git clone https://github.com/ReturnFI/Blitz /etc/hysteria +git clone -b beta https://github.com/ReturnFI/Blitz /etc/hysteria echo "Downloading geosite.dat and geoip.dat" wget -O /etc/hysteria/geosite.dat https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat >/dev/null 2>&1 @@ -120,6 +105,11 @@ python3 -m venv hysteria2_venv source /etc/hysteria/hysteria2_venv/bin/activate pip install -r requirements.txt +source /etc/hysteria/core/scripts/scheduler_setup.sh +if ! check_scheduler_service; then + setup_hysteria_scheduler +fi + echo "Restarting hysteria-caddy service" systemctl restart hysteria-caddy.service @@ -137,20 +127,6 @@ else echo "Upgrade failed: hysteria-server.service is not active" fi -echo "Adding new Hysteria cronjobs..." -if ! crontab -l 2>/dev/null | grep -q "python3 /etc/hysteria/core/cli.py traffic-status --no-gui"; then - echo "Adding traffic-status cronjob..." - (crontab -l ; echo "*/1 * * * * /bin/bash -c 'source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/cli.py traffic-status --no-gui'") | crontab - -else - echo "Traffic-status cronjob already exists. Skipping." -fi - -if ! crontab -l 2>/dev/null | grep -q "python3 /etc/hysteria/core/cli.py backup-hysteria"; then - echo "Adding backup-hysteria cronjob..." - (crontab -l ; echo "0 */6 * * * /bin/bash -c 'source /etc/hysteria/hysteria2_venv/bin/activate && python3 /etc/hysteria/core/cli.py backup-hysteria' >/dev/null 2>&1") | crontab - -else - echo "Backup-hysteria cronjob already exists. Skipping." -fi - +sleep 10 chmod +x menu.sh ./menu.sh