Last active
August 29, 2015 14:04
-
-
Save Dirrk/a03510eeace85d9e2ef1 to your computer and use it in GitHub Desktop.
setup nginx config and service folder for daemon tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# setup nginx config and service folder | |
if [ "$UID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
# Variables | |
nginxsdir=/services/nginx | |
prefixdir=/app/nginx | |
configfile=$prefixdir/conf/nginx.conf | |
if [ ! -z $1 ]; then | |
nginxconfigurl=$1 | |
else | |
nginxconfigurl=https://gist.githubusercontent.com/Dirrk/2fa6d4d173c591bc620d/raw/ | |
fi | |
# Add service folder and setup | |
if [ ! -e $nginxsdir ]; then | |
mkdir -p $nginxsdir | |
touch $nginxsdir/run | |
echo "#!/bin/bash" > $nginxsdir/run | |
echo "exec nice -1 /app/nginx/sbin/nginx -c /app/nginx/conf/nginx.conf" >> $nginxsdir/run | |
chmod 540 $nginxsdir/run | |
ln -s $nginxsdir /service/nginx | |
else | |
echo "Service directory was already created" | |
fi | |
# Download the config and reload nginx | |
wget -qq --no-check-certificate -O $prefixdir/conf/test.conf $nginxconfigurl | |
backup=`date +%s` | |
if [[ $(du -sb $prefixdir/conf/test.conf | cut -f 1) -gt 0 ]]; then | |
cp $configfile $configfile.$backup | |
$prefixdir/sbin/nginx -t -c $prefixdir/conf/test.conf && mv $prefixdir/conf/test.conf $configfile | |
status=$? | |
if [ $status -eq 0 ]; then | |
echo successfully replaced the old config | |
$prefixdir/sbin/nginx -s reload | |
status=$? | |
if [ $status -eq 0 ]; then | |
echo reloaded nginx | |
else | |
echo couldnt reload nginx check if its running | |
fi | |
else | |
echo config failed reloaded previous config | |
mv $configfile.$backup $configfile | |
fi | |
else | |
echo Config file did not download | |
fi | |
if [ ! -e $prefixdir/html/static/index.html ]; then | |
mkdir -p $prefixdir/html/static | |
echo "<html><p>nginx is working</p></html>" > $prefixdir/html/static/index.html | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment