-
Notifications
You must be signed in to change notification settings - Fork 1
79 lines (65 loc) · 3.23 KB
/
fuckingfix.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: Server Check and Auto Fix
on:
workflow_dispatch: # Allows manual triggering of the workflow
schedule:
- cron: '0 * * * *' # Runs every hour, adjust as needed
jobs:
check-and-fix-server:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Install SSH Client
run: sudo apt-get install -y openssh-client
- name: Connect to Server and Check Status
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
# Check Nginx Status
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no username@your_server_ip "sudo systemctl status nginx" > status.txt || echo "NGINX_ERROR" > error.txt
# Check Disk Space
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no username@your_server_ip "df -h" > diskspace.txt
if grep -q '100%' diskspace.txt; then
echo "DISK_FULL" > error.txt
fi
# Check Nginx Logs for Critical Errors
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] "sudo tail -n 50 /var/log/nginx/error.log" > nginx_errors.txt
if grep -q 'critical' nginx_errors.txt; then
echo "NGINX_CRITICAL_ERROR" > error.txt
fi
# Check for SSL and Domain Configuration Errors
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no username@your_server_ip "sudo nginx -t" > nginx_test.txt || echo "NGINX_CONFIG_ERROR" > error.txt
if grep -q "SSL" nginx_test.txt; then
echo "SSL_ERROR" > error.txt
fi
if grep -q "could not be resolved" nginx_test.txt; then
echo "DOMAIN_ERROR" > error.txt
fi
- name: Handle Errors and Auto Fix
run: |
if grep -q "NGINX_ERROR" error.txt; then
echo "Nginx is down. Restarting Nginx..."
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no username@your_server_ip "sudo systemctl restart nginx"
fi
if grep -q "DISK_FULL" error.txt; then
echo "Disk is full. Clearing cache..."
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no username@your_server_ip "sudo rm -rf /var/cache/nginx/*"
fi
if grep -q "NGINX_CRITICAL_ERROR" error.txt; then
echo "Critical Nginx error detected. Attempting to fix..."
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no username@your_server_ip "sudo nginx -t && sudo systemctl reload nginx"
fi
if grep -q "SSL_ERROR" error.txt; then
echo "SSL error detected. Attempting to fix..."
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no username@your_server_ip "sudo certbot renew --nginx"
fi
if grep -q "DOMAIN_ERROR" error.txt; then
echo "Domain configuration error detected. Attempting to fix..."
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no username@your_server_ip "sudo sed -i 's/your_old_domain.com/your_new_domain.com/g' /etc/nginx/sites-available/default"
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no username@your_server_ip "sudo nginx -t && sudo systemctl reload nginx"
fi