bin sh cd usr local etc nginx NGPATH usr local etc nginx NGBIN usr loc

  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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#!/bin/sh
cd /usr/local/etc/nginx
NGPATH="/usr/local/etc/nginx";
NGBIN="/usr/local/sbin/nginx";
ISERROR="NO"
if [ -f $NGPATH/vhost.conf.new ]; then
echo "Already runnuing...."
exit 0;
fi
if [ -f $NGPATH/nginx.reload ]; then
cp $NGPATH/vhost.conf $NGPATH/vhost.conf.backup
echo '' > $NGPATH/vhost.conf.new;
echo '' > $NGPATH/domains.log;
cat /usr/local/etc/apache22/Includes/directadmin-vhosts.conf | awk '{ print $2 }' |
{
while read conffile
do
cat $conffile | grep "#NGINX" |
while read vhost
do
NGINXUSER=$vhost;
DOMAIN=`echo $NGINXUSER | awk -F":" '{ print $2 }'` ;
DOCROOT=`echo $NGINXUSER | awk -F":" '{ print $3 }'` ;
IP=`echo $NGINXUSER | awk -F":" '{ print $4 }'` ;
echo $DOMAIN;
sed -e "s/@domain@/$DOMAIN/g" $NGPATH/server.template > $NGPATH/vhost.tmp;
sed -e "s|@homedir@|$DOCROOT|g" $NGPATH/vhost.tmp > $NGPATH/vhost.tmp2;
sed -e "s|@ip@|$IP|g" $NGPATH/vhost.tmp2 >> $NGPATH/vhost.conf.new;
if [ ! -f $NGPATH/vhost.tmp ]
then
echo Config file not exist, state 1
ISERROR="YES"
fi
if [ ! -f $NGPATH/vhost.tmp2 ]
then
echo Config file not exist, state 2
ISERROR="YES"
fi
rm $NGPATH/vhost.tmp;
rm $NGPATH/vhost.tmp2;
done
done
}
cp $NGPATH/vhost.conf.new $NGPATH/vhost.conf
rm $NGPATH/vhost.conf.new
# testing, that's all ok
nginxtest=`$NGBIN -t` ;
if [ ${?} = 0 -a $ISERROR="NO" ]; then
# Restaring
echo "Restarting nginx..."
/usr/local/etc/rc.d/nginx restart
rm $NGPATH/nginx.reload
else
echo "ERROR! Config wrong! Restoring backup";
echo "Return code ${?}"
cp $NGPATH/vhost.conf.backup $NGPATH/vhost.conf
#echo $nginxtest > $NGPATH/email.txt
#mail -s "NGINX GENERATE ERROR!" sherbacov@bsys.ru < $NGPATH/email.txt
fi
fi;