|
40 | 40 | (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging') |
41 | 41 | environment: |
42 | 42 | name: staging |
43 | | - url: https://staging.codeframe.example.com |
| 43 | + url: https://dev.codeframeapp.com |
44 | 44 |
|
45 | 45 | steps: |
46 | 46 | - name: Checkout code |
@@ -173,18 +173,19 @@ jobs: |
173 | 173 | BACKEND_NAME="${{ secrets.PM2_BACKEND_NAME }}" |
174 | 174 | FRONTEND_NAME="${{ secrets.PM2_FRONTEND_NAME }}" |
175 | 175 |
|
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" |
179 | 179 | } |
180 | 180 |
|
181 | 181 | # 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}" |
185 | 186 | else |
186 | | - echo "🚀 Starting ${BACKEND_NAME}..." |
187 | | - pm2 start ${CONFIG_FILE} |
| 187 | + echo "🚀 Starting PM2 services from config..." |
| 188 | + pm2 start "${CONFIG_FILE}" |
188 | 189 | fi |
189 | 190 |
|
190 | 191 | pm2 save |
@@ -466,27 +467,27 @@ jobs: |
466 | 467 | BACKEND_NAME="codeframe-production-backend" |
467 | 468 | FRONTEND_NAME="codeframe-production-frontend" |
468 | 469 |
|
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" |
472 | 473 | } |
473 | 474 |
|
474 | 475 | # Handle backend process |
475 | | - if process_exists "${BACKEND_NAME}"; then |
| 476 | + if is_process_online "${BACKEND_NAME}"; then |
476 | 477 | echo "♻️ Restarting ${BACKEND_NAME}..." |
477 | 478 | pm2 restart "${BACKEND_NAME}" |
478 | 479 | else |
479 | 480 | echo "🚀 Starting ${BACKEND_NAME}..." |
480 | | - pm2 start ${CONFIG_FILE} --only "${BACKEND_NAME}" |
| 481 | + pm2 start "${CONFIG_FILE}" --only "${BACKEND_NAME}" |
481 | 482 | fi |
482 | 483 |
|
483 | 484 | # 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}" |
487 | 488 | 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}" |
490 | 491 | fi |
491 | 492 |
|
492 | 493 | pm2 save |
|
0 commit comments