Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Configuration
- owner='root:root'
- confdir='/etc/nginx'
- logdir='/var/log/nginx'
- rundir='/run/nginx'
- conf='nginx.conf'
- exec 2>&1
- if [ ! -d $confdir ]; then
- printf 'Configuration directory %s does not exist!\n' $confdir
- exit 1
- fi
- # Absolute path to config
- conffile="${confdir}/${conf}"
- if [ ! -f $conffile ]; then
- printf 'Main nginx configuration file %s does not exist!\n' $conffile
- exit 1
- fi
- if [ ! -d $rundir ]; then
- printf 'Run directory %s does not exist, creating...' $rundir
- rm -rf $rundir > /dev/null
- mkdir $rundir
- echo ' [done]'
- fi
- if [ $(stat -c '%U:%G' $rundir) != $owner ]; then
- printf 'Run directory %s has incorrect owner, changing...' $rundir
- chown $owner $rundir
- echo ' [done]'
- fi
- if [ $(stat -c '%U:%G' $logdir) != $owner ]; then
- printf 'Log directory %s has incorrect owner, changing...' $logdir
- chown -R $owner $logdir
- echo ' [done]'
- fi
- # Checking if somebody left this instance of nginx running as a daemon.
- pidfile="${rundir}/nginx.pid"
- if [ -f $pidfile ]; then
- read pid <$pidfile
- if [ -n "${pid}" -a -d "/proc/${pid}" ]; then
- echo 'Nginx has been daemonized! Please adjust your config so that it includes a \"daemon off;\" line.'
- exit 10
- fi
- fi
- # Cleaning up trash from previous instance.
- rm -rf "${rundir}/*" > /dev/null
- # Testing nginx config before launching
- conftest=$(nginx -tqc $conffile)
- if [ -n "${conftest}" ]; then
- echo 'Nginx configuration test failed!'
- echo $conftest
- exit 11
- else
- printf 'Successfully tested nginx configuration. Starting from %s...\n' $root
- cd $root
- exec nginx -c $conffile
- fi
Advertisement
Add Comment
Please, Sign In to add comment