systemd Mastery: Essential Commands and Custom Service Creation
Utkarsh Maurya
Low-Level & Blockchain Developer | LFX'23 @Hyperledger | Mentor@SWoC '24
Systemd is a linux service manager. It's what I personally use on my arch config, and it's how I create custom background services.
Basic Commands
? Show System Status
systemctl status
? List Running Units -
systemctl or systemctl list-units
? Show System Status
systemctl status
? Show Process Status -
systemctl status [process]
? Start A Process -
systemctl start [process]
? Restart A Process -
systemctl relead [process]
? Start A Process At Boot -
systemctl enable [process]
? Disable Start On Boot -
systemctl disable [process]
? Reload Everything -
systemctl daemon-reload
Creating Custom Services - Starting A Docker Image
I have a docker image running ArchiveBox on my main workstation as a systemd service. Here's how I did it.
Here's the short bash script I wrote to start my docker image:
#!/bin/bash
cd /home/jakeg/archivebox
sudo docker-compose up
I used chmod +x [file].sh to give systemd execution access to the script. In the systemd directory /etc/systemd/system I wrote the file archivebox.service with the contents:
[Unit]
Description=archivebox service
[Service]
type=simple
ExecStart=/bin/bash /home/utkarsh/archivebox/run.sh
[Install]
WantedBy=multi-user.target
References