#!/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;