services systemd (unit)
Chester Wyke September 23, 2023 Updated: February 04, 2026 #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
Bash Aliases
Video Cards
Snapcraft
Reset Root Password
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
Scripts
MAN
Terminal
sed
Characters
zsh
Links between files
7z encrypted file
Wayland or x11?
Delete Old Files Automatically
Screen Application
Set IP
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
Bash Aliases
Video Cards
Snapcraft
Reset Root Password
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
Scripts
MAN
Terminal
sed
Characters
zsh
Links between files
7z encrypted file
Wayland or x11?
Delete Old Files Automatically
Screen Application
Set IP
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/
sudo nano /etc/systemd/system/SERVICE_NAME.serviceIf running as non-root user
File should be saved at ~/.config/systemd/user/ . Note that This folder usually won’t exist so create it.
mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/SERVICE_NAME.serviceExample 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). - You can set working directory using
WorkingDirectory=(see here for more). - You can set standard output using
StandardOutput=(see here for more) Note: stderr defaults to use the same path (I think, not tested but based on the docs).
[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'
User=[Only allowed when running as root to set the user to use instead of root (see note above)]
WorkingDirectory=[relative to another option root but absolute paths work]
Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"
StandardOutput=append:/my_folder/output.txt
Type=simple
Restart=always
[Install]
WantedBy=default.targetEnabling and starting the service
If running as root user
sudo systemctl daemon-reload
sudo systemctl enable SERVICE_NAME.service
sudo systemctl start SERVICE_NAMEIf running as non-root user
systemctl --user daemon-reload
systemctl --user enable SERVICE_NAME.service
systemctl --user start SERVICE_NAMEUpdates 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
sudo systemctl daemon-reload
sudo systemctl restart SERVICE_NAMEIf running as non-root user
systemctl --user daemon-reload
systemctl --user restart SERVICE_NAMERemoving Services
Source: https://www.baeldung.com/linux/create-remove-systemd-services#1-removing-custom-systemd-services
If running as root user
sudo systemctl stop SERVICE_NAME
sudo systemctl disable SERVICE_NAME
sudo rm /etc/systemd/system/SERVICE_NAME.service
sudo systemctl daemon-reloadIf running as non-root user
systemctl --user stop SERVICE_NAME
systemctl --user disable SERVICE_NAME
rm ~/.config/systemd/user/SERVICE_NAME.service
systemctl --user daemon-reload