Skip to content

Auto Reload Nginx Configuration #3

@MiteshShah

Description

@MiteshShah

When we create a symbolic link in /etc/nginx/sites-enabled

Then shell script auto detect any new file is created in /etc/nginx/sites-enabled
Then call nginx -t to check nginx configuration test
If nginx configuration test is passed
Then reload nginx using the following commands

service nginx reload

This following script is just a demo needed proper logging.

#!/bin/bash
dpkg --list | grep inotify-tools &> /dev/null
if [ $? -eq 0 ]
then
        echo "Inotify Tools Already Installed"
else
        echo "Installing Inotify Tools..."
        apt-get -y install inotify-tools
fi
while true
do
        inotifywait --exclude .swp -e create -e modify -e delete -e move  /etc/nginx/sites-enabled
        nginx -t
        if [ $? -eq 0 ]
        then
                echo "Reloading Nginx Configuration"
                service nginx reload
        fi
done

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions