Linux for Developers Course
Linux for Developers
/
Advanced

Systemd Units

Definition

The plain-text configuration files (usually ending in `.service`, `.target`, or `.timer`) that teach systemd exactly how to manage, start, and stop a specific application.

Explain Like I'm New

The instruction manual for your custom app. If you write a Python app, Linux doesn't know how to run it as a background service until you write a Unit File telling Linux exactly which command to run.

Real World Example

A developer writes a custom Node.js bot. They create a file `/etc/systemd/system/bot.service` containing `ExecStart=/usr/bin/node /opt/bot/app.js`. Now, they can magically use `systemctl start bot` just like any professional software.

Common Use Cases

  • •Deploying custom code as a service
  • •Automatic restart on crash

Interview Questions

basic

  • What mandatory command must you run after editing or creating a new systemd unit file?

intermediate

  • What does the `Restart=always` line do inside a `.service` file?

Flash Cards

Question

What command after edit?

Click to reveal answer
Answer

`sudo systemctl daemon-reload`. This forces systemd to read the hard drive and recognize your new file.

Question

What is Restart=always?

Click to reveal answer
Answer

It acts as a babysitter. If your custom application suddenly crashes due to a bug, systemd will automatically reboot the app within milliseconds, keeping it online.