services systemd (unit)
Chester Wyke September 23, 2023 Updated: April 15, 2025 #debian
debian (Series)
MAC Address Change
Set permissions recursively on directory structure
Touch (Set file modified date)
Android Apps on Linux
Blacklist Module
Calender Notifications Popup Disable
CUPS PDF Printer
gping
Hide Mounts
Nautilus
Power
Smartgit
Video Cards
Snapcraft
Acrobat Reader
Audio
Shortcuts (Important)
DNS
Mounting Drives
Setup Network Shares
Cron
Startup
Users and Groups
Paths to remember
Manually Removing Old Kernels
Set Icon for Application
Strange Problems and Fixes
Redirecting stderr
Extensions
Ubuntu Software
Show Seconds on Clock Display
Create Bootable Flash Drive
Compressed Files
services systemd (unit)
SCP
SSH
Updating
Useful commands
Firewall
View Whitespace
OpenVPN
PPP logs
MAN
Terminal
sed
Characters
zsh
Links between files
7z encrypted file
Wayland or x11?
Delete Old Files Automatically
MAC Address Change
Set permissions recursively on directory structure
Touch (Set file modified date)
Android Apps on Linux
Blacklist Module
Calender Notifications Popup Disable
CUPS PDF Printer
gping
Hide Mounts
Nautilus
Power
Smartgit
Video Cards
Snapcraft
Acrobat Reader
Audio
Shortcuts (Important)
DNS
Mounting Drives
Setup Network Shares
Cron
Startup
Users and Groups
Paths to remember
Manually Removing Old Kernels
Set Icon for Application
Strange Problems and Fixes
Redirecting stderr
Extensions
Ubuntu Software
Show Seconds on Clock Display
Create Bootable Flash Drive
Compressed Files
services systemd (unit)
SCP
SSH
Updating
Useful commands
Firewall
View Whitespace
OpenVPN
PPP logs
MAN
Terminal
sed
Characters
zsh
Links between files
7z encrypted file
Wayland or x11?
Delete Old Files Automatically
Source: linuxhandbook
Sending output to a file
Source: https://unix.stackexchange.com/questions/245037/saving-process-output-to-a-file-in-systemd-unit-file
Commands are not subject to shell parsing eg “< > << >> and &” are not treated specially. Use /bin/sh 'script.sh > out'
to get around this.
File location
If running as root user
File should be saved at etc/systemd/system/
If running as non-root user
File should be saved at ~/.config/systemd/user/
. Note that This folder usually won’t exist so create it.
Example Contents
- This is the same for both (with a few exceptions). See the linuxhandbook for more info on what should be set in the file.
- You can find a list of targets here.
- You can also set the user to run as for system wide services (see here).
- You can set environment variables using
Environment=
(see here for more).
[Unit]
Description=User Facing name of service
After=network.target
[Service]
ExecStart=/bin/bash -c '/usr/bin/my_awesome_program >> /home/user/out.txt 2>&1'
Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"
Type=simple
Restart=always
[Install]
WantedBy=default.target
Enabling and starting the service
If running as root user
If running as non-root user
Updates to service config
This section applies if you’ve made changes to the service’s configuration and want to apply those changes
If running as root user
If running as non-root user
Removing Services
Source: https://www.baeldung.com/linux/create-remove-systemd-services#1-removing-custom-systemd-services
If running as root user
If running as non-root user