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/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
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user