Tiny Website Manager

This is a simple script written in bash to help manage different websites/services on a shared web server. I actually wrote it to manage this very website.

You can find it publicly hosted in Gitlab

Project Status

This project is on “maintenance only”. I can’t really think of anything else I want from it and it should only get updates if it turns out I’ve made a boo-boo somewhere. Part of me would also like to check out how to integrate tab completion but it’s honestly too low priority compared to everything else. As such, as much as I do think it would be nice to have, it’s unlikely I’ll spend the time looking it up and sorting it out.

The situation

I self-host a handful of different services. These live in different VMs or BSD Jails and have their own configuration and particulars. In order to make sure all of these are running correctly, I have a “gateway” NGINX server which then reverse proxies to the correct thing, forwarding traffic to the actual servers.

In order to facilitate this management, I use a common structure where each site or service has it’s own conf file which lives in a sites-available folder. If I want this to be reachable, I make a link to it on a sites-enabled folder, where NGINX actually reads them from.

This makes it easy to tweak things individually and allows me to quickly toggle services if there’s something I want to take offline or it’s a temporary debug tool or whatnot. But that still requires a lot of ln and rm calls and it’s error prone. In fact, at one point I was looking at things and I had accidentally copied over some files instead of linking, which is a classic opportunity for the classic “silly bug which takes forever to track down”.

With this in mind I decided to help myself and write a little tool to help me with this work

What it does

The tool itself makes and destroys links as its main day to day feature. You can call it with -h to get a list of all available options.

In addition to just listing your conf files and letting you know whether that one is “enabled” or not, it also does some sanity checking and can attempt to correct misconfigured instances.

It’ll check whether links are valid, whether everything in the sites-enabled folder is a link and whether all of those point to files which exist in the sites-available folder.

As a convenience feature, you can use it to launch a text editor of your choice to open the file in question (can be used to Create new conf files)

Old: vim /usr/local/etc/nginx/sites-available/my-page.com
Gold: ./websites.sh -c my-page.com

Configuration and use

Once you clone the repository, you need to edit the script and point it to the right directories. This will be handled through the SITES_AVAILABLE_DIR and SITES_ENABLED_DIR, declared near the top of the script. You can also configure which editor the script launches (defaults to nano).

The script defaults to /usr/local/etc/nginx as you nginx folder, but it has a built-in override that sets it to the script’s own location. This is to facilitate testing and experimenting.

In order to do that, you can run the auxiliary script create-test-files.sh. This script will create a series of files and links within its directory. You can then use the websites.sh script to check out how it behaves before configuring it for production

Version

1.0 (initial release)

Known Issues

None at time of writing

Version History and Change Log

Initial release