Files
ansible-gitea/roles/docker/handlers/main.yml
T
2025-12-05 11:18:26 +07:00

87 lines
2.4 KiB
YAML

---
# ============================================================================
# NGINX HANDLERS FOR AUTO-SCALING DEPLOYMENT
# ============================================================================
# if nginx install by aaPanel: run command > mkdir -p /etc/nginx/conf.d/
# if nginx install by aaPanel: run command > ln -fs /www/server/nginx/sbin/nginx /usr/bin/nginx
# if nginx install by aaPanel: run command > echo "map $http_upgrade $connection_upgrade { default upgrade; '' close; }" > /www/server/panel/vhost/nginx/0.websocket.conf
# if nginx install by aaPanel: run command > echo "include /etc/nginx/conf.d/*.conf;" > /www/server/panel/vhost/nginx/forlife-upstream.conf
- name: test nginx configuration
command: nginx -t
become: yes
listen: test nginx configuration
- name: reload nginx
shell: |
# Test nginx configuration
nginx -t && /etc/init.d/nginx reload
# Wait for reload
sleep 3
become: yes
when: ansible_service_mgr == "systemd"
listen: reload nginx
- name: webapplication purge cache
shell: |
filepath="/www/server/scripts/cloudflare-purge-cache.sh"
if [ -f "$filepath" ]; then bash "$filepath"; fi
become: yes
when: ansible_service_mgr == "systemd"
listen: webapplication purge cache
- name: restart nginx
shell: |
# Test nginx configuration
nginx -t && /etc/init.d/nginx restart
# Wait for reload
sleep 3
become: yes
when: ansible_service_mgr == "systemd"
listen: restart nginx
- name: validate nginx upstream
shell: |
# Test nginx configuration
nginx -t && /etc/init.d/nginx reload
# Wait for reload
sleep 3
become: yes
ignore_errors: true
listen: validate nginx upstream
# service:
# name: nginx
# state: reloaded
# become: yes
# when: ansible_service_mgr == "systemd"
# listen: reload nginx
#- name: restart nginx
# service:
# name: nginx
# state: restarted
# become: yes
# when: ansible_service_mgr == "systemd"
# listen: restart nginx
#- name: validate nginx upstream
# shell: |
# # Test nginx configuration
# nginx -t && nginx -s reload
#
# # Wait for reload
# sleep 3
#
# # Test upstream connectivity
# if command -v curl >/dev/null 2>&1; then
# echo "Testing upstream connectivity..."
# curl -f -s --max-time 10 http://localhost/health || echo "⚠️ Upstream health check skipped"
# fi
# become: yes
# ignore_errors: true
# listen: validate nginx upstream