Skip to content

Commit af0f5dc

Browse files
committed
Fix PM2 service identification services
1 parent e107112 commit af0f5dc

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
(github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging')
4141
environment:
4242
name: staging
43-
url: https://staging.codeframe.example.com
43+
url: https://dev.codeframeapp.com
4444

4545
steps:
4646
- name: Checkout code
@@ -173,18 +173,19 @@ jobs:
173173
BACKEND_NAME="${{ secrets.PM2_BACKEND_NAME }}"
174174
FRONTEND_NAME="${{ secrets.PM2_FRONTEND_NAME }}"
175175
176-
# Function to check if a PM2 process exists
177-
process_exists() {
178-
pm2 jlist 2>/dev/null | grep -q "\"name\":\"$1\""
176+
# Function to check if a PM2 process is online
177+
is_process_online() {
178+
pm2 describe "$1" 2>/dev/null | grep -q "online"
179179
}
180180
181181
# Restart both frontend and backend via config file
182-
if process_exists "${BACKEND_NAME}"; then
183-
echo "♻️ Restarting ${BACKEND_NAME}..."
184-
pm2 restart ${CONFIG_FILE}
182+
if is_process_online "${BACKEND_NAME}" && is_process_online "${FRONTEND_NAME}"; then
183+
echo "♻️ Restarting PM2 services..."
184+
pm2 restart "${BACKEND_NAME}"
185+
pm2 restart "${FRONTEND_NAME}"
185186
else
186-
echo "🚀 Starting ${BACKEND_NAME}..."
187-
pm2 start ${CONFIG_FILE}
187+
echo "🚀 Starting PM2 services from config..."
188+
pm2 start "${CONFIG_FILE}"
188189
fi
189190
190191
pm2 save
@@ -466,27 +467,27 @@ jobs:
466467
BACKEND_NAME="codeframe-production-backend"
467468
FRONTEND_NAME="codeframe-production-frontend"
468469
469-
# Function to check if a PM2 process exists
470-
process_exists() {
471-
pm2 jlist 2>/dev/null | grep -q "\"name\":\"$1\""
470+
# Function to check if a PM2 process is online
471+
is_process_online() {
472+
pm2 describe "$1" 2>/dev/null | grep -q "online"
472473
}
473474
474475
# Handle backend process
475-
if process_exists "${BACKEND_NAME}"; then
476+
if is_process_online "${BACKEND_NAME}"; then
476477
echo "♻️ Restarting ${BACKEND_NAME}..."
477478
pm2 restart "${BACKEND_NAME}"
478479
else
479480
echo "🚀 Starting ${BACKEND_NAME}..."
480-
pm2 start ${CONFIG_FILE} --only "${BACKEND_NAME}"
481+
pm2 start "${CONFIG_FILE}" --only "${BACKEND_NAME}"
481482
fi
482483
483484
# Handle frontend process
484-
if process_exists "${FRONTEND_NAME}"; then
485-
echo "♻️ Restarting \${FRONTEND_NAME}..."
486-
pm2 restart "\${FRONTEND_NAME}"
485+
if is_process_online "${FRONTEND_NAME}"; then
486+
echo "♻️ Restarting ${FRONTEND_NAME}..."
487+
pm2 restart "${FRONTEND_NAME}"
487488
else
488-
echo "🚀 Starting \${FRONTEND_NAME}..."
489-
pm2 start \${CONFIG_FILE} --only "\${FRONTEND_NAME}"
489+
echo "🚀 Starting ${FRONTEND_NAME}..."
490+
pm2 start "${CONFIG_FILE}" --only "${FRONTEND_NAME}"
490491
fi
491492
492493
pm2 save

0 commit comments

Comments
 (0)