Ask Steves · Daily notes · VPS, 20% off · AI Profit Lab · SEO · Money Hub

17 November 2026 · Practical AI builds

How do I keep a small AI app running after a server restart?

By the end of this note your small AI app will start again by itself whenever the server reboots, with no need to log in and type anything. It suits anyone running a chatbot, form helper or similar tool on a Linux VPS who has noticed it goes quiet after the host does maintenance.

I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.

What you need

Step by step

  1. Check the app runs by hand first, and note the exact command, the folder it runs from and the port it listens on (for example 127.0.0.1:3000).
  2. If you started it with nohup or in a terminal session, stop that copy now so you do not end up with two. Running something after you log out is not the same as surviving a reboot, which is what the rest of this note covers.
  3. Install PM2 with sudo npm install -g pm2, then start the app under it as the normal user that owns the app, not as root.
  4. Run pm2 startup. It does not change anything itself: it prints one line starting with sudo, which you copy and run. That line sets up a system service that starts PM2 at boot.
  5. Run pm2 save. This writes down the list of apps PM2 is running, so it knows what to bring back after a reboot. Run it again whenever you add or remove an app.
  6. If you would rather not use PM2, or the app is not a Node app, write a small systemd service file instead (example below), then run sudo systemctl daemon-reload and sudo systemctl enable --now appname.
  7. If the app runs in Docker, give the container a restart policy such as --restart unless-stopped (or restart: unless-stopped in a compose file) and check Docker itself starts at boot with sudo systemctl is-enabled docker.
  8. Test it properly with sudo reboot. Wait a minute, log back in and check the app is running and answering.

The commands for PM2 look like this:

cd /home/appuser/appname
pm2 start server.js --name appname
pm2 startup
# copy and run the sudo line it prints, then:
pm2 save

A systemd service file goes in /etc/systemd/system/appname.service:

[Unit]
Description=appname
After=network-online.target
Wants=network-online.target

[Service]
User=appuser
WorkingDirectory=/home/appuser/appname
ExecStart=/usr/bin/node server.js
EnvironmentFile=/home/appuser/appname/.env
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Use the full path to the program in ExecStart. You can find it with which node or which python3. If you are still choosing how to set the server up in the first place, the note on what you need to run a small AI app on a VPS covers the basics.

What good looks like

After a reboot, pm2 list shows your app as online (or systemctl status appname shows active (running)), and curl http://127.0.0.1:3000 gets a sensible reply without you starting anything. The public address works again in a browser once nginx is up. The restart count stays low. If it keeps climbing, the app is crashing and being started again over and over, and the logs (pm2 logs appname or journalctl -u appname) will say why.

Watch out for

The most common slip is forgetting pm2 save after a change, so PM2 brings back an old list after the reboot. A close second is running pm2 startup as a different user from the one that runs the apps, so the boot service starts an empty PM2. If you installed Node with a version manager and later upgrade it, the path in the startup service can go stale. Run pm2 unstartup, then pm2 startup again.

Also remember that coming back is not the same as working correctly. An AI app can start fine and still fail on every request because an API key expired or a database was not ready. Keep API keys in an environment file the app reads, not typed into the start command, and check a real request after any reboot that matters.

Questions people ask

Should I use PM2 or systemd?

PM2 is friendlier for Node apps and gives you easy logs and a quick list of everything running. systemd needs nothing extra installed and suits any language, so either is a sound choice for a small app.

Will this also restart the app if it crashes?

Yes. PM2 restarts crashed apps by default, and the Restart=on-failure line does the same for systemd. If an app crashes the moment it starts, both will give up or slow down after repeated failures, so read the logs rather than hoping it settles.

Put plainly, you hand the app to a process manager, tell it to start at boot, and prove it with a real reboot. Do that once and the app comes back on its own whenever the server restarts.

You can get the same kind of VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.

Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.

Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.

GET A VPS, 20% OFF →

Affiliate link.

Related AI builds: What do I need to run a small AI app on a VPS? · How do I back up a small AI app and its data on a VPS? · How do I draft replies to common customer emails with AI? · All daily notes