Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
If your service runs from nohup node server.js & in a terminal, it dies the first time the box reboots, OOMs, or you accidentally close that ssh session. Process supervision means an outside thing watches your process, restarts it when it crashes, captures its logs, and starts it on boot. On Linux that thing is systemd, and writing a 10-line unit file is the difference between 'my service is up 99.9%' and 'my service is up when I'm awake'. This is the smallest, dumbest reliability win you'll ever make.
A systemd service unit lives at /etc/systemd/system/myapp.service. It declares the binary to run, the user to run as, environment files, restart policy, and logging target. Once enabled, the process is restarted on crash, started on boot, and its stdout/stderr go to journald — searchable with journalctl -u myapp -f. The whole file is shorter than the npm script you'd write to do half of what it does.
/etc/systemd/system/, systemctl daemon-reload, then enable --now.kill -9 $(pgrep myapp)). Watch systemctl status myapp — it should be back inside 2 seconds.systemctl enable.journalctl -u myapp --since '1 hour ago' | less to read recent logs. This is your free poor-person's log search until module 2.Use these three in order. Each builds on the one before.
Explain what 'process supervision' means and the three things it gives you for free that running `node server.js &` doesn't.
Walk me through what happens when my app crashes under systemd: the kernel sends SIGSEGV, the kernel reaps the process, systemd's PID 1 notices, then what? How does it decide whether to restart and how fast?
Compare systemd, pm2, supervisord, and 'containerized + restart=always' as process supervisors. For a single-VM Day 0 deploy, which is right and why? When do the trade-offs flip?
# /etc/systemd/system/myapp.service
[Unit]
Description=My App
After=network.target
[Service]
Type=simple
User=app
WorkingDirectory=/srv/myapp
EnvironmentFile=/etc/myapp.env
ExecStart=/usr/bin/node /srv/myapp/server.js
Restart=always
RestartSec=2
# don't restart-bomb on a hard crash loop
StartLimitIntervalSec=60
StartLimitBurst=5
# logs go to journald automatically
StandardOutput=journal
StandardError=journal
SyslogIdentifier=myapp
[Install]
WantedBy=multi-user.targetnode main.js