hysteria-scheduler service setup
- Create installation script to automate setup and migration from cron - Update both install.sh and upgrade.sh to use the shared functions
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
source /etc/hysteria/core/scripts/path.sh
|
source /etc/hysteria/core/scripts/path.sh
|
||||||
source /etc/hysteria/core/scripts/utils.sh
|
source /etc/hysteria/core/scripts/utils.sh
|
||||||
|
source /etc/hysteria/core/scripts/scheduler_setup.sh
|
||||||
define_colors
|
define_colors
|
||||||
|
|
||||||
install_hysteria() {
|
install_hysteria() {
|
||||||
@ -82,11 +83,9 @@ install_hysteria() {
|
|||||||
chmod +x /etc/hysteria/core/scripts/hysteria2/user.sh
|
chmod +x /etc/hysteria/core/scripts/hysteria2/user.sh
|
||||||
chmod +x /etc/hysteria/core/scripts/hysteria2/kick.py
|
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 -
|
if ! check_scheduler_service; then
|
||||||
# (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 -
|
setup_hysteria_scheduler
|
||||||
(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 -
|
fi
|
||||||
# (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 systemctl is-active --quiet hysteria-server.service; then
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
|
|||||||
50
core/scripts/scheduler.sh
Normal file
50
core/scripts/scheduler.sh
Normal file
@ -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
|
||||||
38
upgrade.sh
38
upgrade.sh
@ -16,21 +16,6 @@ FILES=(
|
|||||||
"/etc/hysteria/core/scripts/webpanel/Caddyfile"
|
"/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"
|
echo "Backing up files to $TEMP_DIR"
|
||||||
for FILE in "${FILES[@]}"; do
|
for FILE in "${FILES[@]}"; do
|
||||||
mkdir -p "$TEMP_DIR/$(dirname "$FILE")"
|
mkdir -p "$TEMP_DIR/$(dirname "$FILE")"
|
||||||
@ -41,7 +26,7 @@ echo "Removing /etc/hysteria directory"
|
|||||||
rm -rf /etc/hysteria/
|
rm -rf /etc/hysteria/
|
||||||
|
|
||||||
echo "Cloning Blitz repository"
|
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"
|
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
|
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
|
source /etc/hysteria/hysteria2_venv/bin/activate
|
||||||
pip install -r requirements.txt
|
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"
|
echo "Restarting hysteria-caddy service"
|
||||||
systemctl restart hysteria-caddy.service
|
systemctl restart hysteria-caddy.service
|
||||||
|
|
||||||
@ -137,20 +127,6 @@ else
|
|||||||
echo "Upgrade failed: hysteria-server.service is not active"
|
echo "Upgrade failed: hysteria-server.service is not active"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Adding new Hysteria cronjobs..."
|
sleep 10
|
||||||
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
|
|
||||||
|
|
||||||
chmod +x menu.sh
|
chmod +x menu.sh
|
||||||
./menu.sh
|
./menu.sh
|
||||||
|
|||||||
Reference in New Issue
Block a user