Create separate caddy service for hysteria project
This commit is contained in:
12
core/cli.py
12
core/cli.py
@ -419,11 +419,11 @@ def webpanel(action: str, domain: str, port: int, admin_username: str, admin_pas
|
|||||||
if not services_status:
|
if not services_status:
|
||||||
raise click.Abort('Error: WebPanel services status not available.')
|
raise click.Abort('Error: WebPanel services status not available.')
|
||||||
|
|
||||||
if not services_status.get('webpanel'):
|
if not services_status.get('hysteria-webpanel'):
|
||||||
raise click.Abort('Error: hysteria-webpanel.service service is not running.')
|
raise click.Abort('Error: hysteria-webpanel.service service is not running.')
|
||||||
|
|
||||||
if not services_status.get('caddy'):
|
if not services_status.get('hysteria-caddy'):
|
||||||
raise click.Abort('Error: caddy.service service is not running.')
|
raise click.Abort('Error: hysteria-caddy.service service is not running.')
|
||||||
|
|
||||||
url = cli_api.get_webpanel_url()
|
url = cli_api.get_webpanel_url()
|
||||||
click.echo(f'Hysteria web panel is now running. The service is accessible on: {url}')
|
click.echo(f'Hysteria web panel is now running. The service is accessible on: {url}')
|
||||||
@ -456,10 +456,10 @@ def get_web_panel_api_token():
|
|||||||
def get_web_panel_services_status():
|
def get_web_panel_services_status():
|
||||||
try:
|
try:
|
||||||
if services_status := cli_api.get_services_status():
|
if services_status := cli_api.get_services_status():
|
||||||
webpanel_status = services_status.get('webpanel', False)
|
webpanel_status = services_status.get('hysteria-webpanel', False)
|
||||||
caddy_status = services_status.get('caddy', False)
|
caddy_status = services_status.get('hysteria-caddy', False)
|
||||||
print(f"hysteria-webpanel.service: {'Active' if webpanel_status else 'Inactive'}")
|
print(f"hysteria-webpanel.service: {'Active' if webpanel_status else 'Inactive'}")
|
||||||
print(f"caddy.service: {'Active' if caddy_status else 'Inactive'}")
|
print(f"hysteria-caddy.service: {'Active' if caddy_status else 'Inactive'}")
|
||||||
else:
|
else:
|
||||||
click.echo('Error: Services status not available.')
|
click.echo('Error: Services status not available.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
declare -a services=(
|
declare -a services=(
|
||||||
"hysteria-server.service"
|
"hysteria-server.service"
|
||||||
"hysteria-webpanel.service"
|
"hysteria-webpanel.service"
|
||||||
|
"hysteria-caddy.service"
|
||||||
"hysteria-telegram-bot.service"
|
"hysteria-telegram-bot.service"
|
||||||
"hysteria-normal-sub.service"
|
"hysteria-normal-sub.service"
|
||||||
"hysteria-singbox.service"
|
"hysteria-singbox.service"
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
source /etc/hysteria/core/scripts/utils.sh
|
source /etc/hysteria/core/scripts/utils.sh
|
||||||
define_colors
|
define_colors
|
||||||
|
|
||||||
|
CADDY_CONFIG_FILE="/etc/hysteria/core/scripts/webpanel/Caddyfile"
|
||||||
|
|
||||||
install_dependencies() {
|
install_dependencies() {
|
||||||
# Update system
|
# Update system
|
||||||
sudo apt update -y > /dev/null 2>&1
|
sudo apt update -y > /dev/null 2>&1
|
||||||
@ -52,8 +54,6 @@ EOL
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_caddy_file() {
|
update_caddy_file() {
|
||||||
local config_file="/etc/caddy/Caddyfile"
|
|
||||||
|
|
||||||
source /etc/hysteria/core/scripts/webpanel/.env
|
source /etc/hysteria/core/scripts/webpanel/.env
|
||||||
|
|
||||||
# Ensure all required variables are set
|
# Ensure all required variables are set
|
||||||
@ -63,7 +63,7 @@ update_caddy_file() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Update the Caddyfile without the email directive
|
# Update the Caddyfile without the email directive
|
||||||
cat <<EOL > "$config_file"
|
cat <<EOL > "$CADDY_CONFIG_FILE"
|
||||||
# Global configuration
|
# Global configuration
|
||||||
{
|
{
|
||||||
# Disable admin panel of the Caddy
|
# Disable admin panel of the Caddy
|
||||||
@ -115,6 +115,27 @@ WantedBy=multi-user.target
|
|||||||
EOL
|
EOL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_caddy_service_file() {
|
||||||
|
cat <<EOL > /etc/systemd/system/hysteria-caddy.service
|
||||||
|
[Unit]
|
||||||
|
Description=Hysteria2 Caddy
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=/etc/caddy
|
||||||
|
ExecStart=/usr/bin/caddy run --environ --config $CADDY_CONFIG_FILE
|
||||||
|
ExecReload=/usr/bin/caddy reload --config $CADDY_CONFIG_FILE --force
|
||||||
|
TimeoutStopSec=5s
|
||||||
|
LimitNOFILE=1048576
|
||||||
|
PrivateTmp=true
|
||||||
|
User=root
|
||||||
|
Group=root
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOL
|
||||||
|
}
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
local domain=$1
|
local domain=$1
|
||||||
local port=$2
|
local port=$2
|
||||||
@ -125,7 +146,7 @@ start_service() {
|
|||||||
|
|
||||||
# MAYBE I WANT TO CHANGE CONFIGS WITHOUT RESTARTING THE SERVICE MYSELF
|
# MAYBE I WANT TO CHANGE CONFIGS WITHOUT RESTARTING THE SERVICE MYSELF
|
||||||
# # Check if the services are already active
|
# # Check if the services are already active
|
||||||
# if systemctl is-active --quiet hysteria-webpanel.service && systemctl is-active --quiet caddy.service; then
|
# if systemctl is-active --quiet hysteria-webpanel.service && systemctl is-active --quiet hysteria-caddy.service; then
|
||||||
# echo -e "${green}Hysteria web panel is already running with Caddy.${NC}"
|
# echo -e "${green}Hysteria web panel is already running with Caddy.${NC}"
|
||||||
# source /etc/hysteria/core/scripts/webpanel/.env
|
# source /etc/hysteria/core/scripts/webpanel/.env
|
||||||
# echo -e "${yellow}The web panel is accessible at: http://$domain:$port/$ROOT_PATH${NC}"
|
# echo -e "${yellow}The web panel is accessible at: http://$domain:$port/$ROOT_PATH${NC}"
|
||||||
@ -169,8 +190,14 @@ start_service() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
create_caddy_service_file
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "${red}Error: Failed to create the Caddy service file.${NC}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Restart Caddy service
|
# Restart Caddy service
|
||||||
systemctl restart caddy.service
|
systemctl restart hysteria-caddy.service
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo -e "${red}Error: Failed to restart Caddy.${NC}"
|
echo -e "${red}Error: Failed to restart Caddy.${NC}"
|
||||||
return 1
|
return 1
|
||||||
@ -199,8 +226,8 @@ show_webpanel_api_token() {
|
|||||||
|
|
||||||
stop_service() {
|
stop_service() {
|
||||||
echo "Stopping Caddy..."
|
echo "Stopping Caddy..."
|
||||||
systemctl disable caddy.service
|
systemctl disable hysteria-caddy.service
|
||||||
systemctl stop caddy.service
|
systemctl stop hysteria-caddy.service
|
||||||
echo "Caddy stopped."
|
echo "Caddy stopped."
|
||||||
|
|
||||||
echo "Stopping Hysteria web panel..."
|
echo "Stopping Hysteria web panel..."
|
||||||
|
|||||||
Reference in New Issue
Block a user