diff --git a/.gitignore b/.gitignore index 4c585b5..73bcd41 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,9 @@ next-env.d.ts /media /pastor-letters +# PM2 logs +/logs + # SQLite database files *.db *.db-shm diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs new file mode 100644 index 0000000..94db4d4 --- /dev/null +++ b/ecosystem.config.cjs @@ -0,0 +1,45 @@ +// PM2 process definition for db-ministerial (Next.js + Payload CMS). +// +// The package is ESM ("type": "module"), so this config MUST be .cjs. +// +// Deploy flow on the server: +// pnpm install --frozen-lockfile +// cp .env.example .env # then set a real PAYLOAD_SECRET +// pnpm build # production build (.next/) +// pnpm import:pastors # one-time: load pastors from the CSV +// pm2 start ecosystem.config.cjs +// pm2 save # persist across reboots (see `pm2 startup`) +// +// Env vars (DATABASE_URI, PAYLOAD_SECRET, …) are read from the project's .env +// by Next.js automatically. Anything set in `env` below overrides that. + +module.exports = { + apps: [ + { + name: 'db-ministerial', + // Run the Next.js binary directly so PM2 doesn't depend on pnpm being + // on its PATH. Equivalent to `next start`. + script: 'node_modules/next/dist/bin/next', + args: 'start', + cwd: __dirname, + + instances: 1, + exec_mode: 'fork', + autorestart: true, + watch: false, + max_memory_restart: '1G', + + env: { + NODE_ENV: 'production', + NODE_OPTIONS: '--no-deprecation', + PORT: 3000, + }, + + // Logs (relative to cwd). Create ./logs or change these paths. + error_file: './logs/db-ministerial-error.log', + out_file: './logs/db-ministerial-out.log', + merge_logs: true, + time: true, + }, + ], +}