Browse Source

Add tech blog posts

Stu Franks 3 weeks ago
3 changed files with 167 additions and 0 deletions
  1. +63
  2. +3
  3. +101

+ 63
- 0
content/ View File

@@ -0,0 +1,63 @@
title: Backups are Important - Where did my site go?

## Some Background

Websites are awesome, everyone should have one, especially those in the IT world. I bought my first domain name (_``_... ew) at 17 because I wanted to host some of the guides I'd written as I learned Linux first-hand at my first job.

I wrote up a bunch of guides and left the website to the side, I've never been much of a blogger. It wasn't until I was looking for a new job to advance my career that I went back to tidy up the website to "make myself look active" and to showcase some of the half-complete games I'd created (I do still have low-effort "games" over at [](

Now, 8 years down the line I have a pretty empty tangle of services/subdomains with nothing posted on it... I have posts, or at least, I _had_ posts.

## The VPS (_Viciously Pull-apart

The more I learn about IT, the more I want to self-host and "take control" of the services I utilise. Using WordPress-as-a-service? I should have a VPS! Cloud, NGINX, DNS configuration? I've done those things before, time to get into the nitty-gritty of private server configuration!

I'll host with AWS, I've got more experience with it than other providers so why not just grab myself a handy little instance. I can take advantage of spot prices with a deployment configuration that _should_ survive costs increasing beyond the standard hourly charge.

I proceeded to configure the VPS with a WebDAV server (for hosting my encrypted Joplin notes), NGINX for handling my "incredible plan" to have lots of subdomains to compartmentalise the stuff I want to post. I installed and tried quite a few blogging platforms and just didn't enjoy any before eventually using a static site generator for my previous tech blog.

This blog worked alright, and I ported across some of my older content from a somewhat-recent backup of my old WordPress site... From XML to markdown. I even wrote another post about some of the struggles I had with weird escape sequences appearing in my posts, it was a huge frustration to solve and I documented the solution along with screenshots so when I hit that issue again I could easily resolve it!

## The Bad Day

It took 6 months to find out I was wrong...

As I mentioned earlier, I'm not much of a blogger. Due to this, I tend to not check out my own site a lot. But in a moment of self-indulgence I went to my site and felt my stomach drop, "This site can’t be reached".

The frantic checking began. I won't bore with the details but it was gone. My instance had been killed, the virtual disk destroyed. I knew the risk I took with spot instancing, I had documented my entire setup process, all the hosting. I could replicate that on a fresh instance. I can be back up and live quickly. I even have those half-arsed backups.

## The Half-Arsed Backups

These backups were run manually, it was just a bash script, an `rsync` to backup the "key" configuration and content directories. Remember when I said I didn't check my site a lot? Well, I didn't backup or maintain it a lot either.

I figured I had probably taken a backup since my latest iteration of blog creations so I'd still have my few tech posts. **Oh how I was wrong again.**

I hadn't backed it up and I hadn't documented the solution to that _bloody escape sequence_ issue outside of the server on the VPS.

I wish I had gotten around to setting up proper backups.

## The Now

Currently, I'm running a Linode VPS and self-hosting writefreely for this blog. _I've finally settled on it_. I'm content and ready to create content (or, maybe, re-upload it) and I'm more confident that I won't be losing this instance anytime soon. Despite that, I am backing up more regularly. The same mistake will not be made (how hard can I cross my fingers before _actually_ backing up stuff?).

## The "What Next?"

I still have things to post strewn around. The big XML file to extract posts from, notes and guides I've written up in Joplin, a list of writing prompts. I'll get 'round to it? Soon?

I'm going to take the casual approach to blogging, writing stuff when I feel. Not just loading it up on content from the past just to "have content". Instead, I'll write about whatever I feel like whenever I feel like it!

## The Apology

> I have posts, or at least, I _had_ posts.

The truth may have been embellished a bit there, the only post I lost was the one that helped my parse the XML for those pesky hidden characters. I still have all my old posts, images and such. A cheap attempt at heightening this narrative.

## The "If You Made It This Far"

I suppose this is the end of a rant about lazy self-hosting and blog-indecisiveness, so thanks for reading about such a riveting topic! I hope you had fun and learned the moral of the story:

> Websites are awesome

_My current "other" blog is over at [](

+ 3
- 0
content/ View File

@@ -0,0 +1,3 @@
Welcome to my tech blog!

I've written many different how-to guides and notes on various sysadmin tasks, here is where I'll attempt to get the majority of them up (whenever I can get around to it).

+ 101
- 0
content/ View File

@@ -0,0 +1,101 @@
title: Rails Quickstart - Static Pages & User Manager

## Basic Setup

Create new rails app (note: the nokogiri line is usually needed on MacOS to properly build the dependency)
gem install nokogiri -- --use-system-libraries --with-xml2-include="$(xcrun --show-sdk-path)/usr/include/libxml2"
rails new . --database=postgresql
rails db:create

Launch server (check it's running by going to http://localhost:3000)
rails s

Add some gems to Gemfile
# User management
gem 'devise'
# Bootstrap
gem 'bootstrap', '~> 4.0.0'
# Font Awesome Icons
gem "font-awesome-rails"
# In 'group :development do' add
gem 'rails-erd'

Install gem dependencies
bundle install

Bootstrap support
vim app/assets/stylesheets/application.css
@import "bootstrap";
@import "font-awesome";

Rename `app/assets/stylesheets/application.css` to `app/assets/stylesheets/application.scss` and remove `require` lines

## Static Page Support

Static pages
rails generate controller pages --skip-assets

Add show method to the static pages controller at `app/controllers/pages_controller.rb`
def show
render template: "pages/#{params[:page]}"

Edit `config/routes.rb` to manage static page routing and set root path
get "/:page" => "pages#show"

root "pages#about"

Create `app/view/pages/about.html.erb`, this will be used as the new index page

## Add a User Controller

Install devise things
rails g devise:install

Setup mail configuration for development environment in `config/environments/development.rb`
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

Modify flash notification styles in `app/view/layouts/application.html.erb` (in the `<body>` of the page - remove the backslashes, that's just me working around formatting issues with nanoc)
\<\% flash.each do |name, msg| \%\>
\<\%\= content_tag(:div, msg, class: "alert alert-info text-center") \%\>
\<\% end \%\>

Create user manager and views
rails g devise User
rails g devise:views
rails db:migrate

Additional user fields (this is optional but an example of adding attributes)
rails generate migration add_fields_to_users display_name:text website:text bio:text
rails db:migrate

Hope this helps you, Dan.