Stop Using nohup java -jar: Three Production-Grade Ways to Daemonize Spring Boot
A Spring Boot process launched with `nohup &` will not restart after a crash or server reboot, logs will eventually exhaust the disk, and the service likely runs as root — a combination that turns a routine outage into a security incident. Adopting systemd or a container orchestrator eliminates these failure modes with a few lines of configuration and no new dependencies.
The `nohup java -jar &` one-liner is a development convenience that becomes a liability the moment a server reboots at 3 a.m. or a log file silently fills the disk. Production Spring Boot deployments need a process supervisor that can restart crashed services, rotate logs, and run under a dedicated non-root user.
Systemd, built into every modern Linux distribution, is the first choice: a service unit file defines the JVM arguments, the run-as user, restart policy, and log destination, all without installing extra software. For older CentOS 6 systems or cross-language environments, Supervisor provides a lightweight alternative with explicit control over process groups and log rotation. Teams already on containers get automatic restarts, rolling updates, and health checks from Kubernetes.
A production checklist rounds out the guidance — dedicated user accounts, explicit heap settings, externalized config, graceful shutdown via SIGTERM, log rotation, and firewall rules. The core message is that “it runs” is not enough; the service must survive reboots, crashes, and operator mistakes without manual intervention.
The gap between a development invocation and a production deployment is not about complexity — it is about failure modes that only surface at 3 a.m., and systemd closes that gap with a dozen lines of declarative config.
Supervisor’s requirement for absolute paths and explicit process-group killing reveals how many ‘mysterious’ production hangs trace back to orphaned Netty or thread-pool child processes that a simple kill missed.
Systemd user-mode with linger is an underused escape hatch in locked-down enterprise environments; it gives developers process supervision without sudo, provided an admin runs a single command once.