Root workspace configuration with 4 submodules: - codebase/ → lilith/platform-codebase - deployments/ → lilith/platform-deployments - tooling/ → lilith/platform-tooling - docs/ → lilith/platform-docs Tracks workspace config (package.json, turbo.json, bunfig.toml), CI workflows (.forgejo/), dev scripts, and instructions. Each submodule retains its own history and remote.
61 lines
1.6 KiB
Bash
Executable file
61 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# PM2 Service Deployment Library
|
|
#
|
|
# Deploys PM2-managed services on Apricot with zero-downtime reload.
|
|
#
|
|
# Usage:
|
|
# source scripts/lib/deploy/pm2.sh
|
|
# deploy_pm2_service "api-service"
|
|
#
|
|
|
|
set -e
|
|
set -u
|
|
|
|
deploy_pm2_service() {
|
|
local SERVICE="$1"
|
|
local APRICOT_HOST="${APRICOT_HOST:-10.9.0.1}"
|
|
local SERVICE_PATH="/opt/lilith-platform/@services/$SERVICE"
|
|
|
|
log_info "Deploying PM2 service: $SERVICE"
|
|
|
|
# Sync code to service directory
|
|
log_info "Syncing code to $APRICOT_HOST..."
|
|
rsync -avz --delete \
|
|
"@services/$SERVICE/" \
|
|
"${APRICOT_HOST}:${SERVICE_PATH}/" || {
|
|
log_error "Failed to sync code for $SERVICE"
|
|
return 1
|
|
}
|
|
|
|
# Install dependencies and rebuild
|
|
log_info "Installing dependencies and building..."
|
|
ssh "$APRICOT_HOST" \
|
|
"cd $SERVICE_PATH && pnpm install --frozen-lockfile && pnpm build" || {
|
|
log_error "Failed to build $SERVICE"
|
|
return 1
|
|
}
|
|
|
|
# PM2 reload (graceful restart with zero-downtime)
|
|
log_info "Reloading service via PM2..."
|
|
ssh "$APRICOT_HOST" \
|
|
"pm2 reload $SERVICE || pm2 start ${SERVICE_PATH}/dist/main.js --name $SERVICE" || {
|
|
log_error "Failed to reload $SERVICE"
|
|
return 1
|
|
}
|
|
|
|
# Verify service is running
|
|
sleep 3
|
|
local STATUS=$(ssh "$APRICOT_HOST" "pm2 jlist" | jq -r ".[] | select(.name==\"$SERVICE\") | .pm2_env.status")
|
|
|
|
if [ "$STATUS" = "online" ]; then
|
|
log_info "✅ $SERVICE is online"
|
|
return 0
|
|
else
|
|
log_error "$SERVICE failed to start (status: $STATUS)"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Export functions
|
|
export -f deploy_pm2_service
|