#!/usr/bin/env bash # 将 Shopro 队列 Supervisor 配置安装到服务器 # 用法(root): # DEPLOY_PATH=/www/wwwroot/chufang.gynhc.com PHP_BIN=/www/server/php/74/bin/php bash deploy/supervisor/install.sh set -euo pipefail DEPLOY_PATH="${DEPLOY_PATH:-/www/wwwroot/chufang.gynhc.com}" PHP_BIN="${PHP_BIN:-$(command -v php || true)}" CONF_SRC="${DEPLOY_PATH}/deploy/supervisor/shopro-queue.conf" CONF_DST="${SUPERVISOR_CONF_DIR:-/etc/supervisor/conf.d}/shopro-queue.conf" if [[ -z "$PHP_BIN" || ! -x "$PHP_BIN" ]]; then echo "ERROR: 找不到可执行的 PHP,请设置 PHP_BIN,例如:" echo " PHP_BIN=/www/server/php/74/bin/php" exit 1 fi if [[ ! -f "$CONF_SRC" ]]; then echo "ERROR: 配置文件不存在: $CONF_SRC" exit 1 fi if [[ ! -f "${DEPLOY_PATH}/think" ]]; then echo "ERROR: 项目根目录不正确,未找到 think: ${DEPLOY_PATH}/think" exit 1 fi mkdir -p "${DEPLOY_PATH}/runtime/log" sed \ -e "s|PHP_BIN_PLACEHOLDER|${PHP_BIN}|g" \ -e "s|DEPLOY_PATH_PLACEHOLDER|${DEPLOY_PATH}|g" \ "$CONF_SRC" > "$CONF_DST" echo "已写入: $CONF_DST" echo "PHP: $PHP_BIN" echo "项目: $DEPLOY_PATH" if command -v supervisorctl >/dev/null 2>&1; then supervisorctl reread supervisorctl update supervisorctl status shopro-queue:* else echo "WARN: 未找到 supervisorctl,请手动执行:" echo " supervisorctl reread && supervisorctl update && supervisorctl status" fi echo "完成。"