I made the react app by cra in typescript. I tried to deploy by pm2, so I set the shell script like this.
startup.sh
#!/bin/bash
npm install
# Install pm2 globally
npm install -g pm2
pm2 install pm2-logrotate
pm2 set pm2-logrotate:rotateInterval 50 * * * *
pm2 set pm2-logrotate:dateFormate YYYY-MM-DD_HH-mm-ss
# Build the project in production mode
pm2 start ecosystem.config.js --env production
# Save the pm2 process list
pm2 save
# Configure pm2 to start automatically on system boot
pm2 startup
# Generate a startup script for pm2
pm2 save
# Restart the application if it stops for any reason
pm2 resurrect
# Install serve to serve the build
npm install -g serve
# Serve the build on port 3000
pm2 --name "my-app" serve $STH_HOME/build 3000 --spa
so when I execute the startup.sh, then the app starts well. However, in the ecosystem.config.js, I set the data logs to be into the specific directory. But the application runs seperately.
ecosystem.config.js
module.exports = {
apps: [
{
name: "my-app",
script: "node_modules/react-scripts/scripts/build.js",
instances: "1",
watch: false,
exec_mode: "cluster",
restart_delay: "5000",
listen_timeout: 50000,
kill_timeout: 5000,
out_file: "/mylogs/my-app/my-app.out",
error_file: "/mylogs/my-app/my-app.err",
log_date_format: "YYYY-MM-DD HH:mm Z",
env_development: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
},
},
],
};
I expected only one app(my-app) running in my server, but there are two different my-app running in my server when I checked by pm2 list
.
I guess that's why my log data didn't accumulate in the exact directory that I wanted. I'm aware with setting pm2 log-rotate with ecosystem.config.js is not possible.
how to store log data exact directory where I want ??