feat: improve edit_subpath function with better error handling and efficient Caddy reload
- Add service status validation before editing subpath - Use systemctl reload for Caddy config changes - Add fallback to restart if reload fails - Enhance user feedback with old/new subpath comparison - Improve error handling and status verification
This commit is contained in:
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"githubPullRequests.ignoredPullRequestBranches": [
|
||||||
|
"main"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -193,25 +193,39 @@ edit_subpath() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! systemctl is-active --quiet hysteria-normal-sub.service || ! systemctl is-active --quiet hysteria-caddy-normalsub.service; then
|
||||||
|
echo -e "${red}Error: One or more services are not running. Please start the services first.${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
source "$NORMALSUB_ENV_FILE"
|
source "$NORMALSUB_ENV_FILE"
|
||||||
local old_subpath="$SUBPATH"
|
local old_subpath="$SUBPATH"
|
||||||
|
|
||||||
sed -i "s|^SUBPATH=.*|SUBPATH=$new_path|" "$NORMALSUB_ENV_FILE"
|
sed -i "s|^SUBPATH=.*|SUBPATH=$new_path|" "$NORMALSUB_ENV_FILE"
|
||||||
echo -e "${green}SUBPATH updated to $new_path in $NORMALSUB_ENV_FILE.${NC}"
|
echo -e "${green}SUBPATH updated from '$old_subpath' to '$new_path' in $NORMALSUB_ENV_FILE.${NC}"
|
||||||
|
|
||||||
update_caddy_file_normalsub "$HYSTERIA_DOMAIN" "$HYSTERIA_PORT" "$new_path" "$AIOHTTP_LISTEN_ADDRESS" "$AIOHTTP_LISTEN_PORT"
|
update_caddy_file_normalsub "$HYSTERIA_DOMAIN" "$HYSTERIA_PORT" "$new_path" "$AIOHTTP_LISTEN_ADDRESS" "$AIOHTTP_LISTEN_PORT"
|
||||||
echo -e "${green}Caddyfile for Normalsub updated.${NC}"
|
echo -e "${green}Caddyfile for Normalsub updated with new subpath.${NC}"
|
||||||
|
|
||||||
echo -e "${yellow}Restarting hysteria-normal-sub service...${NC}"
|
echo -e "${yellow}Restarting hysteria-normal-sub service to reload environment...${NC}"
|
||||||
systemctl restart hysteria-normal-sub.service
|
systemctl restart hysteria-normal-sub.service
|
||||||
echo -e "${yellow}Reloading hysteria-caddy-normalsub service...${NC}"
|
|
||||||
|
echo -e "${yellow}Reloading Caddy configuration...${NC}"
|
||||||
|
if systemctl reload hysteria-caddy-normalsub.service 2>/dev/null; then
|
||||||
|
echo -e "${green}Caddy configuration reloaded successfully.${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${yellow}Reload failed, restarting Caddy service...${NC}"
|
||||||
systemctl restart hysteria-caddy-normalsub.service
|
systemctl restart hysteria-caddy-normalsub.service
|
||||||
|
fi
|
||||||
|
|
||||||
if systemctl is-active --quiet hysteria-normal-sub.service && systemctl is-active --quiet hysteria-caddy-normalsub.service; then
|
if systemctl is-active --quiet hysteria-normal-sub.service && systemctl is-active --quiet hysteria-caddy-normalsub.service; then
|
||||||
echo -e "${green}Services restarted/reloaded successfully.${NC}"
|
echo -e "${green}Services updated successfully.${NC}"
|
||||||
echo -e "${green}New access base URL: https://$HYSTERIA_DOMAIN:$HYSTERIA_PORT/$new_path/sub/normal/{username}${NC}"
|
echo -e "${green}New access base URL: https://$HYSTERIA_DOMAIN:$HYSTERIA_PORT/$new_path/sub/normal/{username}${NC}"
|
||||||
|
echo -e "${cyan}Old subpath '$old_subpath' is no longer accessible.${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${red}Error: One or more services failed to restart/reload. Please check logs.${NC}"
|
echo -e "${red}Error: One or more services failed to restart/reload. Please check logs.${NC}"
|
||||||
|
systemctl status hysteria-normal-sub.service --no-pager
|
||||||
|
systemctl status hysteria-caddy-normalsub.service --no-pager
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
menu.sh
5
menu.sh
@ -619,9 +619,8 @@ normalsub_handler() {
|
|||||||
elif ! [[ "$subpath" =~ [A-Z] ]] || ! [[ "$subpath" =~ [a-z] ]] || ! [[ "$subpath" =~ [0-9] ]]; then
|
elif ! [[ "$subpath" =~ [A-Z] ]] || ! [[ "$subpath" =~ [a-z] ]] || ! [[ "$subpath" =~ [0-9] ]]; then
|
||||||
echo "Error: SUBPATH must include at least one uppercase letter, one lowercase letter, and one number."
|
echo "Error: SUBPATH must include at least one uppercase letter, one lowercase letter, and one number."
|
||||||
else
|
else
|
||||||
sed -i "s|^SUBPATH=.*|SUBPATH=${subpath}|" "$NORMALSUB_ENV"
|
python3 $CLI_PATH normal-sub -a edit_subpath -sp "$subpath"
|
||||||
systemctl restart hysteria-normal-sub.service
|
# echo "SUBPATH updated successfully!"
|
||||||
echo "SUBPATH updated successfully!"
|
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user