step two of jekyll automation

Here is some more technical-guts stuff about jekyll and microblog-automation.

I’ve detailed how I create my posts in 1. In there, I write “On the server, in the checked out working copy directory, I have the following command running:

$ bundle exec jekyll build --watch

”. But what does that even mean? For starters, and in order to get everything set up in the first place, I just used the tmux (screen would work as well) instance that I have running perpetually and started that jekyll command in there. Job done.

BUT. That obviously means that I have to think of doing that whenever the server reboots and wasn’t the whole point of computers automating things so we don’t have to think about them?

Systemd to the rescue! Not that I’m a big believer or proponent of systemd, but in German, we have a term called “Die normative Kraft des Faktischen” which can be translated as “the normative power of the factual”. So .. yeah. Whatever. It exists, it is the default on most distros, I don’t care enough to fight some rearguard action or whatever.

Therefore:

Step one, create the file

/home/<username>/.config/systemd/user/jekyll.service

For me, this file has the following content:

[Unit]
Description=Jekyll Watch Directory Service

[Service]
WorkingDirectory=/home/<username>/microblog
Environment="JEKYLL_ENV=production"
ExecStart=/usr/bin/bundle exec jekyll build --watch --source /home/<username>/microblog
ExecStop=/usr/bin/pkill -f jekyll
Restart=always
TimeoutStartSec=60
RestartSec=60

[Install]
WantedBy=default.target

This can now be run with

$ systemctl --user start jekyll

and the output checked with

$ journalctl --user -f -u jekyll

If everything looks ok, make the service permanent with

$ systemctl --user enable jekyll

This would still only start the jekyll process once one logs into the system and also kill it once one logs out. In order to make it truly permanent, the admin user needs to run the command

% loginctl enable-linger <username>

which causes our jekyll unit to be run on bootup and killed on shutdown.

Documents that helped me figure this out: