Use systemctl to control the service and journalctl to read its logs.
Control the service:
systemctl status apishows if the unit is active, its main PID, its memory use and its latest log lines.sudo systemctl restart apirestarts it.stopstops it andstartstarts it.sudo systemctl enable apimakes it start when the machine boots.- After you edit the unit file, run
sudo systemctl daemon-reloadfirst.
systemd saves the service's stdout and stderr in the journal (its log store). Read the logs:
journalctl -u apishows the service's logs.-ffollows new lines live, liketail -f.-n 100shows the last 100 lines.--since "10 min ago"limits the time window.-bshows only logs from the current boot.
If the service keeps dying, systemctl status shows the exit code or the signal that killed it. journalctl -k shows kernel messages, such as OOM kills (the kernel killing a process because memory ran out).
Useful unit settings for a Node app:
Restart=on-failureUser=Environment=LimitNOFILE=
systemctlhasstatus,start,stop,restartandenable.- Run
daemon-reloadafter you edit a unit file. journalctl -u <unit>shows a service's logs, with-f,-nand--sinceto filter.journalctl -kshows kernel messages, such as OOM kills.