# Next.js frontend for /var/www/boundary-fastapiandnextjs # IMPORTANT: Must use STANDALONE (node server.js), NOT "npm start" / "next start". # "next start" does not work with output: standalone and uses more memory → OOM kills. # # Requires Node.js >= 20.9.0 (Next.js 16). If you see "Node.js version >=20.9.0 is required": # sudo bash /var/www/boundary-fastapiandnextjs/scripts/install_node20_ubuntu.sh # sudo systemctl restart nextjs # # Install service: # sudo cp /var/www/boundary-fastapiandnextjs/scripts/nextjs.service /etc/systemd/system/nextjs.service # sudo systemctl daemon-reload # sudo systemctl enable nextjs # sudo systemctl start nextjs # # If you use nvm: systemd does not load nvm, so /usr/bin/node may not exist → 203/EXEC. # Run "which node" and set ExecStart to that path, e.g.: # ExecStart=/root/.nvm/versions/node/v20.20.0/bin/node server.js # (Or set PATH to include that bin dir: Environment=PATH=/root/.nvm/versions/node/v20.20.0/bin:/usr/bin:/bin) # # Memory: Node heap 1536M for 4GB RAM; set 512 for 2GB. Standalone = lower memory. # Deploy: use scripts/build_nextjs_artifact.sh locally, upload tarball, run scripts/unpack_and_start_nextjs.sh on server. # Or: cd plagis-nextjs && npm run build && cp -r public .next/standalone/public, then copy this unit. # See docs/PRODUCTION_NEXTJS_OOM.md [Unit] Description=Next.js Application (Boundary Commission) After=network.target [Service] Type=simple User=root # Standalone server – must exist (run unpack_and_start_nextjs.sh with nextjs-standalone.tar.gz) WorkingDirectory=/var/www/boundary-fastapiandnextjs/plagis-nextjs/.next/standalone Environment=NODE_ENV=production Environment=PORT=3000 # 1536M for 4GB RAM; use 512 for 2GB droplets Environment=NODE_OPTIONS=--max-old-space-size=1536 # PATH for NodeSource; for nvm replace ExecStart with full path from "which node" Environment=PATH=/usr/local/bin:/usr/bin:/bin # NodeSource: /usr/bin/node. For nvm use: ExecStart=/root/.nvm/versions/node/v20.20.0/bin/node server.js ExecStart=/usr/bin/node server.js ExecStartPre=-/bin/sh -c 'test -f /var/www/boundary-fastapiandnextjs/plagis-nextjs/.next/standalone/server.js || (echo "Missing standalone: run unpack_and_start_nextjs.sh with nextjs-standalone.tar.gz"; exit 1)' Restart=always RestartSec=5 # Optional: cap memory so OOM kills this service instead of SSH (4GB box: 1536M; 2GB: 768M) # MemoryMax=1536M [Install] WantedBy=multi-user.target