Min Yang Jung   Software, Safety, and Medical Robotics

How to add new systemd services in Linux

Basics on Systemd Services

Some articles on the basics of the systemd services in Linux:

Notes

Location of Service Unit Files

  • /lib/systemd/system: The default place where service unit files are installed on the system. Lowest priority.
  • /run/systemd/system: The location for run-time unit definitions. Higher priority than /lib/systemd/system but lower than /etc/systemd/system.
  • /etc/systemd/system: The system-wide unit definitions with the highest priority. Can override unit files in the other locations on the filesystem.

Editing and Testing Service Files

Check if a new service is enabled:

systemctl is-enabled my_new_app.service

Start a new service and verify it is successfully started:

sudo systemctl start my_new_app.service
systemctl status my_new_app.service

If it fails to start, use journalctl for detailed logs:

sudo journalctl -xe

After modifying a service file, the systemd process should be reloaded:

sudo systemctl daemon-reload
SOFTWARE LINUX SYSTEM_MANAGEMENT