Answer
Use a systemd unit with ExecStart launching the jar, Restart=on-failure with RestartSec, User= for a non-root account, SuccessExitStatus=143 so a SIGTERM exit isn't treated as a crash, and TimeoutStopSec to bound graceful shutdown. systemd then supervises restarts and you read logs via journalctl -u myapp --since '1 hour ago' instead of tailing a file. This is more robust than a hand-rolled start/stop script with a PID file because systemd handles restart backoff, log capture, dependency ordering (After=network.target), and resource limits like LimitNOFILE in one place.
Common mistakes
- Using nohup and a PID file in production.
- Not knowing journalctl -u service -f.