fix: use new run.sh when updating

This commit is contained in:
zhayujie
2026-03-28 19:16:41 +08:00
parent 23d097bc1c
commit dbc06dbe95

41
run.sh
View File

@@ -792,27 +792,43 @@ cmd_update() {
echo -e "${GREEN}${EMOJI_WRENCH} Updating CowAgent...${NC}" echo -e "${GREEN}${EMOJI_WRENCH} Updating CowAgent...${NC}"
cd "${BASE_DIR}" cd "${BASE_DIR}"
# Stop service # Pull latest code first (service still running)
if is_running; then local pull_ok=false
cmd_stop
fi
# Update code
if [ -d .git ]; then if [ -d .git ]; then
echo -e "${GREEN}🔄 Pulling latest code...${NC}" echo -e "${GREEN}🔄 Pulling latest code...${NC}"
git pull || { if git pull; then
echo -e "${YELLOW}⚠️ GitHub failed, trying Gitee...${NC}" pull_ok=true
else
echo -e "${YELLOW}⚠️ git pull failed, trying Gitee mirror...${NC}"
git remote set-url origin https://gitee.com/zhayujie/chatgpt-on-wechat.git git remote set-url origin https://gitee.com/zhayujie/chatgpt-on-wechat.git
git pull if git pull; then
} pull_ok=true
else
echo -e "${RED}❌ Failed to pull code. Update aborted.${NC}"
exit 1
fi
fi
else else
echo -e "${YELLOW}⚠️ Not a git repository, skipping code update${NC}" echo -e "${YELLOW}⚠️ Not a git repository, skipping code update${NC}"
fi fi
# Re-exec with the updated run.sh to pick up new logic
exec "$0" _post_update
}
# Post-update: called by cmd_update after git pull to run with new code
cmd_post_update() {
cd "${BASE_DIR}"
# Stop service
if is_running; then
cmd_stop
fi
# Reinstall dependencies # Reinstall dependencies
check_python_version check_python_version
install_dependencies install_dependencies
# Restart service # Restart service
cmd_start cmd_start
} }
@@ -882,7 +898,7 @@ require_project_dir() {
# Main function # Main function
main() { main() {
case "$1" in case "$1" in
start|stop|restart|status|logs|config|update) start|stop|restart|status|logs|config|update|_post_update)
require_project_dir require_project_dir
;; ;;
esac esac
@@ -895,6 +911,7 @@ main() {
logs) cmd_logs ;; logs) cmd_logs ;;
config) cmd_config ;; config) cmd_config ;;
update) cmd_update ;; update) cmd_update ;;
_post_update) cmd_post_update ;;
help|--help|-h) help|--help|-h)
show_usage show_usage
;; ;;