Your team has a Python API that someone starts with `nohup python app.py &`. Make it a proper service running as a non-root user.
BeginnerScenarioProcesses, services and systemd
Answer
Situation read → Turn an ad-hoc process into a managed, restartable systemd unit.
What I'd do →
sudo useradd --system --shell /usr/sbin/nologin --home /opt/api api- Create
/etc/systemd/system/api.service:
[Unit]
Description=Orders API
After=network-online.target
Wants=network-online.target
[Service]
User=api
Group=api
WorkingDirectory=/opt/api
EnvironmentFile=/etc/api/api.env
ExecStart=/opt/api/venv/bin/gunicorn -b 0.0.0.0:8000 app:app
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable --now api- Check
systemctl status apiandjournalctl -u api -f.
Why → systemd restarts on crash, starts at boot, captures logs and runs it as a locked-down user.
Interview tip → Mention Restart=on-failure vs always, and that ExecStart needs an absolute path.
More on Processes, services and systemd
The service you created must bind to port 443, but it runs as a non-root user. How?BeginnerYou need to change one setting (memory limit) in a vendor-supplied unit file without editing it. How?BeginnerA service depends on a database on the same host and fails at boot because the DB isn't ready. How do you fix the ordering?IntermediateA service keeps crashing and systemd stops restarting it after a few attempts. How do you tune this?IntermediateA long-running app must reload its config without dropping connections. How do you wire this into systemd?IntermediateA script needs to run once at boot after networking, then exit. How do you do it with systemd?Beginner