7th January 2019 | 2 minutes
I am super excited about today's blog 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
👉 You can find it on GitHub. Go ahead and star it. I'll wait.
Done? Great. Now as you may remember, 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
Just typing out this code block made me feel gross
^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
It's so beautiful I might just cry
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!
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!