This guide will help you set up Cloudflare Tunnel Manager to auto-start on server boot using PM2.
- ✅ No systemd configuration needed - simpler than systemd
- ✅ No root permissions required for tunnel management
- ✅ Auto-restart on crashes - keeps the app running
- ✅ Easy log management - built-in log rotation
- ✅ Process monitoring - see app status anytime
- ✅ Works perfectly with tunnel auto-startup feature
sudo npm install -g pm2cd "/home/dragan/Desktop/Cloudflare Tunnel"
npm run pm2:startYou should see:
[PM2] Starting /home/.../server.js in fork_mode (1 instance)
[PM2] Done.
┌─────┬──────────────────────────────┬─────────┬─────────┐
│ id │ name │ status │ restart │
├─────┼──────────────────────────────┼─────────┼─────────┤
│ 0 │ cloudflare-tunnel-manager │ online │ 0 │
└─────┴──────────────────────────────┴─────────┴─────────┘
npm run pm2:startupThis will output a command like:
sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u your-user --hp /home/your-userCopy and run that exact command (it needs sudo).
npm run pm2:saveThis saves the current running apps so they restart on boot.
- Open browser:
http://localhost:3000 - Go to Settings → Configure Cloudflare API
- Create tunnels
- Enable "Auto-startup" checkbox on critical tunnels
# Restart the server
npm run pm2:restart
# The app restarts and auto-startup tunnels should start automatically
# Check the logs:
npm run pm2:logsYou should see:
Checking for auto-startup tunnels...
Auto-starting tunnel: my-tunnel
Tunnel started successfully
npm run pm2:statusnpm run pm2:logs
# Or view just errors:
pm2 logs cloudflare-tunnel-manager --err
# View last 100 lines:
pm2 logs cloudflare-tunnel-manager --lines 100npm run pm2:restartnpm run pm2:stopnpm run pm2:start- Server boots → PM2 auto-starts → Tunnel Manager starts
- App initialization → Checks
data/tunnels.json - Finds tunnels with
autoStartup: true - Auto-starts those tunnels
- Health checks begin monitoring
- Discord notifications sent if configured
You have 3 tunnels:
prod-api(autoStartup: ✓, environment: production)staging-web(autoStartup: ✗, environment: staging)dev-test(autoStartup: ✗, environment: development)
Server reboots:
- PM2 starts Tunnel Manager
prod-apiautomatically startsstaging-webanddev-teststay stopped- You can manually start the others when needed
pm2 listpm2 monitpm2 show cloudflare-tunnel-managerpm2 flush# Re-run startup configuration
npm run pm2:startup
# Run the sudo command it provides
npm run pm2:save# Check logs
npm run pm2:logs
# Check if port 3000 is in use
sudo lsof -i :3000
# Delete and restart
pm2 delete cloudflare-tunnel-manager
npm run pm2:start# Check logs for errors
npm run pm2:logs
# Verify autoStartup is enabled
cat data/tunnels.json | grep autoStartup
# Manual test: stop PM2 and start normally
pm2 stop cloudflare-tunnel-manager
npm start
# Watch the console for "Auto-starting tunnel: ..."# Stop and remove from PM2
pm2 delete cloudflare-tunnel-manager
# Remove from startup
pm2 unstartup systemd
# Optionally remove PM2 globally
sudo npm uninstall -g pm2| Feature | Without PM2 | With PM2 |
|---|---|---|
| Auto-start on boot | ❌ Manual | ✅ Automatic |
| Crash recovery | ❌ Stays down | ✅ Auto-restarts |
| Log management | ❌ Manual | ✅ Built-in |
| Process monitoring | ❌ None | ✅ pm2 status |
| Tunnel auto-startup | ✅ Fully automatic | |
| Root permissions | ❌ Not needed | ❌ Not needed |
| Systemd config | ❌ Not needed | ❌ Not needed |
PM2 + Auto-Startup = Production-Ready Automation 🚀