Linux systemd Service Files Cheat Sheet/Basic service file example

Minimal custom service unit.

Section: Authoring Basics

Basic service file example

ini
ini
[Unit]
Description=My App
After=network.target

[Service]
Type=simple
User=myapp
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node /opt/myapp/server.js
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
Explanation

A minimal but production-useful service unit.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Authoring Basics
Create custom service file
Open a new service file under /etc/systemd/system.
OpenIn sheetbashsame section
Reload after creating unit
Refresh manager state after writing a new service.
OpenIn sheetbashsame section
Enable and start custom unit
Activate the new custom service.
OpenIn sheetbashsame section
Set working directory
Run service from a specific directory.
OpenIn sheetini2 tag match
Load variables from EnvironmentFile
Use an external env file.
OpenIn sheetini1 tag match
Restart on failure
Automatic restart policy.
OpenIn sheetini1 tag match