refactor: improve logging system and add deployment fixes
- Enhance logging handlers (Console, DockerJson, File, JsonFile, MultiFile) - Improve exception and line formatters - Update logger initialization and processor management - Add Ansible playbooks for staging 502 error troubleshooting - Update deployment documentation - Fix serializer and queue components - Update error kernel and queued log handler
This commit is contained in:
63
deployment/ansible/playbooks/check-entrypoint-execution.yml
Normal file
63
deployment/ansible/playbooks/check-entrypoint-execution.yml
Normal file
@@ -0,0 +1,63 @@
|
||||
---
|
||||
- name: Check Entrypoint Script Execution
|
||||
hosts: production
|
||||
gather_facts: yes
|
||||
become: no
|
||||
|
||||
tasks:
|
||||
- name: Check when nginx container started
|
||||
shell: |
|
||||
cd ~/deployment/stacks/staging
|
||||
docker compose ps staging-nginx --format "{{.Status}}" || echo "Container not running"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: container_status
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
|
||||
- name: Display container status
|
||||
debug:
|
||||
msg: "{{ container_status.stdout }}"
|
||||
|
||||
- name: Check entrypoint logs
|
||||
shell: |
|
||||
cd ~/deployment/stacks/staging
|
||||
echo "=== Entrypoint logs (startup) ==="
|
||||
docker compose logs staging-nginx 2>&1 | grep -E "(??|Fixing|PHP-FPM|upstream)" | head -20
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: entrypoint_logs
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
|
||||
- name: Display entrypoint logs
|
||||
debug:
|
||||
msg: "{{ entrypoint_logs.stdout_lines }}"
|
||||
|
||||
- name: Check if sites-available/default is a volume mount
|
||||
shell: |
|
||||
cd ~/deployment/stacks/staging
|
||||
docker inspect staging-nginx 2>&1 | grep -A 20 "Mounts" | grep "sites-available\|sites-enabled" || echo "No volume mounts for sites-available"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: volume_check
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
|
||||
- name: Display volume check
|
||||
debug:
|
||||
msg: "{{ volume_check.stdout_lines }}"
|
||||
|
||||
- name: Check when sites-available/default was last modified
|
||||
shell: |
|
||||
cd ~/deployment/stacks/staging
|
||||
docker compose exec -T staging-nginx stat -c "%y" /etc/nginx/sites-available/default 2>&1 || echo "Could not get file stat"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: file_stat
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
|
||||
- name: Display file modification time
|
||||
debug:
|
||||
msg: "{{ file_stat.stdout_lines }}"
|
||||
52
deployment/ansible/playbooks/fix-staging-502-quick.yml
Normal file
52
deployment/ansible/playbooks/fix-staging-502-quick.yml
Normal file
@@ -0,0 +1,52 @@
|
||||
---
|
||||
- name: Quick Fix Staging 502 Bad Gateway
|
||||
hosts: production
|
||||
gather_facts: yes
|
||||
become: no
|
||||
|
||||
tasks:
|
||||
- name: Fix php-upstream in sites-available/default
|
||||
shell: |
|
||||
cd ~/deployment/stacks/staging
|
||||
echo "=== Fixing nginx upstream configuration ==="
|
||||
docker compose exec -T staging-nginx sed -i '/upstream php-upstream {/,/}/s|server 127.0.0.1:9000;|server staging-app:9000;|g' /etc/nginx/sites-available/default || echo "Fix 127.0.0.1 failed"
|
||||
docker compose exec -T staging-nginx sed -i '/upstream php-upstream {/,/}/s|server localhost:9000;|server staging-app:9000;|g' /etc/nginx/sites-available/default || echo "Fix localhost failed"
|
||||
echo "=== Verifying fix ==="
|
||||
docker compose exec -T staging-nginx grep -A 3 "upstream php-upstream" /etc/nginx/sites-available/default
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: fix_result
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
|
||||
- name: Display fix result
|
||||
debug:
|
||||
msg: "{{ fix_result.stdout_lines }}"
|
||||
|
||||
- name: Reload nginx
|
||||
shell: |
|
||||
cd ~/deployment/stacks/staging
|
||||
docker compose exec -T staging-nginx nginx -t && docker compose restart staging-nginx
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: reload_result
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
|
||||
- name: Display reload result
|
||||
debug:
|
||||
msg: "{{ reload_result.stdout_lines }}"
|
||||
|
||||
- name: Test if fix worked
|
||||
shell: |
|
||||
sleep 3
|
||||
curl -H "User-Agent: Mozilla/5.0" -s -o /dev/null -w "%{http_code}" https://staging.michaelschiemer.de/ || echo "502"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: test_result
|
||||
ignore_errors: yes
|
||||
failed_when: false
|
||||
|
||||
- name: Display test result
|
||||
debug:
|
||||
msg: "HTTP Status: {{ test_result.stdout }} (200 = OK, 502 = Still broken)"
|
||||
@@ -158,9 +158,40 @@ ansible-playbook -i deployment/ansible/inventory/production.yml \
|
||||
|
||||
## Verhindern in Zukunft
|
||||
|
||||
1. **Entrypoint-Script:** Das Entrypoint-Script behebt das Problem automatisch beim Container-Start
|
||||
2. **Image-Build:** Idealerweise sollte die `sites-available/default` Datei im Docker-Image bereits korrekt konfiguriert sein
|
||||
3. **Alternativ:** Entferne `sites-available/default` komplett und verwende nur `conf.d/default.conf`
|
||||
### Nach jedem Deployment
|
||||
|
||||
**WICHTIG:** Nach jedem Deployment (Push zu staging-Branch) muss dieser Fix ausgef?hrt werden, da die Container neu erstellt werden.
|
||||
|
||||
```bash
|
||||
# Mit Ansible (empfohlen)
|
||||
ansible-playbook -i deployment/ansible/inventory/production.yml \
|
||||
deployment/ansible/playbooks/fix-staging-502-quick.yml
|
||||
|
||||
# Oder manuell
|
||||
cd ~/deployment/stacks/staging
|
||||
docker compose exec -T staging-nginx sed -i '/upstream php-upstream {/,/}/s|server 127.0.0.1:9000;|server staging-app:9000;|g' /etc/nginx/sites-available/default
|
||||
docker compose restart staging-nginx
|
||||
```
|
||||
|
||||
### Langfristige L?sungen
|
||||
|
||||
1. **Entrypoint-Script:** Das Entrypoint-Script behebt das Problem automatisch beim Container-Start (implementiert, aber nicht 100% zuverl?ssig)
|
||||
2. **Deployment-Script:** Erweitere `.gitea/workflows/build-image.yml` um einen Post-Deployment-Fix (siehe TODO unten)
|
||||
3. **Image-Build:** Idealerweise sollte die `sites-available/default` Datei im Docker-Image bereits korrekt konfiguriert sein
|
||||
4. **Alternativ:** Entferne `sites-available/default` komplett und verwende nur `conf.d/default.conf`
|
||||
|
||||
### TODO: Deployment-Script erweitern
|
||||
|
||||
Das Deployment-Script in `.gitea/workflows/build-image.yml` sollte nach Zeile 991 erweitert werden:
|
||||
|
||||
```bash
|
||||
# Fix nginx upstream configuration - critical fix for 502 errors
|
||||
echo "?? Fixing nginx PHP-FPM upstream configuration (post-deploy fix)..."
|
||||
sleep 5
|
||||
docker compose exec -T staging-nginx sed -i '/upstream php-upstream {/,/}/s|server 127.0.0.1:9000;|server staging-app:9000;|g' /etc/nginx/sites-available/default
|
||||
docker compose exec -T staging-nginx sed -i '/upstream php-upstream {/,/}/s|server localhost:9000;|server staging-app:9000;|g' /etc/nginx/sites-available/default
|
||||
docker compose exec -T staging-nginx nginx -t && docker compose restart staging-nginx
|
||||
```
|
||||
|
||||
## Siehe auch
|
||||
|
||||
|
||||
Reference in New Issue
Block a user