Interview Prep/Linux/Processes, Signals & systemd

How do you run a one-off command as a transient systemd unit?

AdvancedConceptProcesses, Signals & systemd
Answer
sudo systemd-run --unit=reindex -p MemoryMax=2G -p CPUQuota=50% /opt/app/bin/reindex
sudo systemd-run --on-active=30m /usr/bin/systemctl restart api   # delayed one-shot
journalctl -u reindex -f

It gets a proper cgroup, limits and logs, survives SSH disconnects, and is much better than nohup for ad-hoc long jobs.

All Linux questions Roadmap: Linux

More on Processes, Signals & systemd