23 lines
420 B
Bash
Executable File
23 lines
420 B
Bash
Executable File
#!/bin/bash
|
|
|
|
CONFIG=/etc/nginx/sites-available/$1
|
|
DOMAIN=$2
|
|
|
|
IP=$(dig $DOMAIN +short)
|
|
IP_OLD=$(grep -A0 '#DYNAMIC' $CONFIG | awk '{print $2}' | cut -f1 -d ';')
|
|
|
|
if [ "$IP" != "$IP_OLD" ]
|
|
then
|
|
NGINX_STATUS=$(nginx -t 2>&1 | tail -n 1 | awk '{print $7}')
|
|
if [ "$NGINX_STATUS" = "successful" ]
|
|
then
|
|
sed -i "s/$IP_OLD/$IP/" $CONFIG
|
|
systemctl restart nginx
|
|
else
|
|
echo nginx test failed
|
|
fi
|
|
else
|
|
echo IP IS SAME
|
|
fi
|
|
|