STEP 01An SSH shell is a session, not a service manager
Starting node server.js in a terminal attaches the process to that interactive session. Closing it may terminate the process. nohup or a terminal multiplexer can be useful for temporary work, but they do not provide a complete production startup and recovery plan.
STEP 02Choose one supervisor
For Docker, use the Compose restart policy and ensure Docker itself starts on boot. For a host-installed app, use systemd. Avoid stacking supervisors on the same process. The following unit assumes /usr/bin/node exists, deploy owns /srv/my-app and the environment file is readable by the service.
[Unit]
Description=My application
After=network-online.target
Wants=network-online.target
[Service]
User=deploy
WorkingDirectory=/srv/my-app
EnvironmentFile=/etc/my-app.env
ExecStart=/usr/bin/node /srv/my-app/server.js
Restart=on-failure
RestartSec=5
NoNewPrivileges=true
PrivateTmp=true
[Install]
WantedBy=multi-user.targetSTEP 03Install only for your own application
Save the reviewed unit as /etc/systemd/system/my-app.service, without replacing an unrelated service. Store its environment file outside Git with restricted access. Enable it and inspect the status. A real application may need additional writable paths and hardening.
sudo systemctl daemon-reload
sudo systemctl enable --now my-app
systemctl status my-app --no-pager
journalctl -u my-app -n 50 --no-pagerSTEP 04A restart loop is evidence, not a solution
If the process repeatedly exits, inspect the first error. Common causes are a missing secret, incorrect working directory, unavailable database, port conflict or insufficient memory. Verify logout survival and plan a reboot check during an approved maintenance window.
COPY → YOUR AI
Take the next step to your AI.
A safe starting prompt for this guide. No secrets. Works with ChatGPT, Claude and other assistants.
Sources and technical documentation
systemd service reference ↗Docker documentation ↗This recipe is a pattern for the stated prerequisites. Verify project compatibility and your actual server configuration before applying it to a live service.