A simple systemd keep-alive script

After spending a few hours trying to get systemd to just keep a simple binary running if it halts, here’s what I’ve learned.

Systemd is a linux service manager. It handles running lots of processes and I wanted it to just run a simple slackbot binary for me. Basically if the bot goes down I want systemd to restart it for me. Since this is a silly thing and doesn’t really need lots of permissions or anything I want it to run for my user on the server and not as root.

First off any user level systemd scripts (called “units”) should be put in ~/.config/systemd/user/. For the slackbot I added a unit called “slackbot.service”.

These units are just text files, for a simple keep-alive script here’s what mine looked like: