How I configured Arch Linux to run my stuff

Agreed, this article is mostly written for future me, when I forgot all about how systemd works.

I have a raspberry pi at home that I want to run a couple of my hobby projects on. I have written a simple reverse proxy server that redirects requests to the appropriate hobby project that is listening on another port. I am running Arch Linux, Arch Linux is using systemd, and I always forget how to tell systemd to start a service.

So how do I start a service?!

All user defined services are located at /etc/systemd/system. In here you can dump a .service file specifying how to run a given service. The file will look like this:

[Unit]
Description=Some human readable description
[Service]
PIDFile=/path/to/pidfile
User=userrunningtheservice
Group=grouprunningtheservice
WorkingDirectory=/path/to/working/directory
Environment=VARIABLE=value
ExecStart=/path/to/service
[Install]
WantedBy=multi-user.target

Once this is in place, the service will start automatically the system boots. If you are impatient, you can start it manually with (as root)

$ systemctl start <unit>

where unit is the name of the .service file. This will of course fail silently if you, for instance, forgot to set the executable bit. To see any output of the service you can ask journald about what has happened

journalctl -u <unit>

But how do I run a service periodically?!

Since systemd completely ditched cron, you need to do this another way; the easiest of course being the systemd way. You basically need to create a .service file for your periodic job and pair that up with a corresponding .timer file. The following will run the service once a day..

[Unit]
Description=Some human readable description
[Timer]
OnBootSec=1m
OnUnitActiveSec=1d
[Install]
wantedBy=timers.target

Hopefully I’ve just saved future me for a lot searching the internet and rtfm.