修复 API 发布安装外部生成 worker 模板

API deploy 从随包安装外部生成 worker 模板和 controller 单元
安装 worker systemd 单元后自动 daemon-reload
补充 API release 与 deploy 动态门禁覆盖 worker systemd 模板
This commit is contained in:
2026-06-23 01:01:59 +08:00
parent 79257f6e4a
commit 14f8a87ac5
3 changed files with 116 additions and 2 deletions
+50
View File
@@ -421,6 +421,54 @@ ensure_default_worker_service() {
systemctl enable --now "${default_service}"
}
install_release_systemd_unit() {
local source_path="$1"
local unit_name="$2"
local label="$3"
local unit_dir="${GENARRATIVE_SYSTEMD_UNIT_DIR:-/etc/systemd/system}"
if [[ ! -f "${source_path}" ]]; then
echo "[production-api-deploy] 发布产物缺少${label}: ${source_path}" >&2
return 1
fi
if [[ "${unit_dir}" != /* ]]; then
echo "[production-api-deploy] systemd unit 目录必须使用绝对路径: ${unit_dir}" >&2
return 1
fi
echo "[production-api-deploy] 安装${label}: ${unit_name}"
run_privileged install -d -m 0755 "${unit_dir}"
run_privileged install -m 0644 "${source_path}" "${unit_dir}/${unit_name}"
}
install_worker_systemd_units() {
local release_dir="$1"
local pattern="$2"
local controller_service="$3"
local installed_any=0
if [[ "${pattern}" == "genarrative-external-generation-worker@*.service" ]]; then
install_release_systemd_unit \
"${release_dir}/deploy/systemd/genarrative-external-generation-worker@.service" \
"genarrative-external-generation-worker@.service" \
"外部生成 worker systemd 模板"
installed_any=1
fi
if [[ "${controller_service}" == "genarrative-external-generation-controller.service" ]]; then
install_release_systemd_unit \
"${release_dir}/deploy/systemd/genarrative-external-generation-controller.service" \
"genarrative-external-generation-controller.service" \
"外部生成 worker controller systemd 单元"
installed_any=1
fi
if [[ "${installed_any}" -eq 1 ]]; then
echo "[production-api-deploy] 重新加载 systemd unit。"
systemctl daemon-reload
fi
}
restart_worker_services() {
local pattern="$1"
local services=()
@@ -917,6 +965,8 @@ if [[ "${PINGORA_INCLUDED}" -eq 1 ]]; then
ensure_pingora_shadow_service "${PINGORA_SERVICE_NAME}" "${PINGORA_SHADOW_ENV_FILE}"
fi
install_worker_systemd_units "${RELEASE_DIR}" "${WORKER_SERVICE_PATTERN}" "${WORKER_CONTROLLER_SERVICE}"
echo "[production-api-deploy] 重启服务: ${SERVICE_NAME}"
systemctl restart "${SERVICE_NAME}"
restart_worker_services "${WORKER_SERVICE_PATTERN}"