This post was originally published on my personal blog.
I am super excited about this post because I made a thing! Yes, I actually made a thing with my own two hands and now I'm releasing it! I present to you: jinx
As background story, I very recently killed my entire server infrastructure by accidentally generating way too many Let's Encrypt accounts in a very short timeframe. It was super funny and I spent the better part of my Saturday getting everything back up on a backup nginx setup.
As part of that I quickly noticed a very repetitive pattern to setting up my virtual hosts. It went a little something like this for every site
# create a new site cp \ /etc/nginx/configurations/php.conf \ /etc/nginx/sites-available/pretzelhands.com.conf # change the host name to the new site name nano /etc/nginx/sites-available/pretzelhands.com.conf # activate the site in nginx ln -s \ /etc/nginx/sites-available/pretzelhands.com.conf \ /etc/nginx/sites-enabled # restart to publish newly activated sites systemctl restart nginx
^R was a bit faster but still incredibly tedious. That's 4 different commands and I have to enter the same or a similar path a whopping four times. That just didn't feel good and so I remembered how much I wrote about shell-scripting
recently and decided to make use of it to create jinx.
With it this same process now looks like this.
# create a new site and insert hostname in template file jinx site create pretzelhands.com php # activate the site and restart jinx site activate pretzelhands.com -r
From four long, repetitive commands to two quite short ones. What a nice improvement. And it only cost me my Sunday afternoon.
The initial development effort may have been higher than setting the sites up manually but I'm still glad I did it because it was fun to do and I can reuse it all the time. Every time I create a new virtual host, this tool probably saves me some 2-3 minutes of repetitive typing.
There's also a few other features, but you can read up on everything in the documentation.
I freely admit that this is probably my single most useful side-project to date. Also it got the approval of Pieter Levels so I guess that counts for something!
jinx is a wrapper script for nginx written entirely in Bash. It helps you manage your sites and configurations in a more streamlined way than working with plain shell commands.
Table of Contents
- Using the commands
Since this is an early release of jinx, it still has some assumptions about your enviroment. Currently these are as follows:
Your sites are organized in two folders:
sites-enabled: The former one holding all available sites you could potentially host and the latter holding the sites that are reachable on the web.
Installation of jinx can be done in one line using the convenient installer script…
I hope you get as much joy and and practical use out of this tool as I do and I'll be trying to extend it with some more useful features such as activating HTTPS and building configurations from included snippets. We'll see how far I can take it!
Single Responsibility Principle (or SRP) is one of the most important concepts in software development. The main idea of this concept is: all pieces of software must have only a single responsibility.