Tag Archives: systemd

Smarter Coffee and Systemd User Units

One of the particularly handy features that systemd supports is the ability to set up unit files on a per-user basis. You simply put the unit files in your home directory and tell systemd to start using them.

I have a couple of these and, because I can never remember the details, I’m putting them here to save me trawling through the interwebs next time I change something.

The user level unit files all go in ~/.config/systemd/user

If this folder doesn’t already exists, you will need to create it.

You can then manage the unit by adding a --user switch to the normal systemctl commands.

Clear as mud, I know, so here’s an example.

Back in October I was given a Smarter Coffee coffee machine — this is a filter coffee machine that can connect to your home network in order to send alerts to your phone. On receiving this, my first thought was to wonder if I could direct these alerts to my laptop.

Some searching revealed that not only is this possible but someone else has already done it. So I forked nanab’s repository and started playing around with the code, managing to direct the notifications to the Gnome notifications area. All of this is available on GitHub, but the systemd bit is described below.

First, I should mention that I have a small binary file (smartercoffee) in /usr/local/bin that points to the actual code. This looks like this:

#! /bin/bash
python2 /path/to/smartercoffee/pollingStatusMessage.py --notify GNOME

So the service file (smartercoffee.service), which needs to be dropped in ~/.config/systemd/user, looks like this:

[Unit]
Description=Monitor the coffee machine

[Service]
Type=simple
ExecStart=/usr/local/bin/smartercoffee
StandardOutput=journal
Restart=on-abort

[Install]
WantedBy=basic.target

You can enable the service with:
systemctl --user enable smartercoffee

And start it with:
systemctl --user start smartercoffee

So now, whenever I boot up my laptop, the first thing it does is tells me the status of the coffee machine.

Flattr this!