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.
More on Processes, Signals & systemd
What is the difference between a program, a process and a thread?BeginnerHow are new processes created in Linux?IntermediateWhat is a zombie process, and how do you get rid of it?IntermediateWhat is an orphan process?BeginnerExplain the process states shown in ps (R, S, D, T, Z).IntermediateWhy can't you kill a process in D state?Advanced