I am running a web service on a reasonably standard MERN stack on a Ubuntu server. I am not overly familiar with web deployment or web programming but I have found myself with this project.
The web service has a pretty extensive list of instructions on how to deploy the service, but it has no instructions on how to undeploy / redeploy it. In addition, it was the sellers of the service's code that deployed it on our server.
I have made some minor changes to the code (fixing spelling, removing / adding functionality) and I cannot seem to work out how to safely undeploy or redeploy the service.
The list of instructions for deployment is, essentially:
yarn
yarn build
yarn start:prod
pm2 start dist/main.js
Doing this as-is while the old service is running obviously doesn't work as the port that I am trying to relaunch on is being watched. Stopping the pm2 process allowed me to redeploy using the above method but has now caused a 502 Gateway error when I relaunch the process.
What is the safe method to undeploy and / or redeploy a service using this tech stack?
You first may want to have a look around on your ubuntu server.
PM2 is like a service manager. To get a list of running services, run this command.
pm2 ls
A typical output:
Typically when you install an update, you just need to restart them.
pm2 restart <service-name>
e.g. pm2 restart cache in my example
Related
The pipelines and releases seem to work finely as they get the artifact deployed on the app service or so it seems as the output error happens on start of the PM2 process.
I haven't found anything on this error on google, and don't know if there is a way to update PM2 on the app service machine as PM2 itself suggests.
These are the logs.
Error message
summary image
I was expecting the app to work and no longer show an application error as I fixed both build and release pipelines.
This is a picture of the important bit of info of the error as its really long
Check the below steps to run nextjs with PM2.
First create a nextJS app.
Run npm run dev command to run the app in development.
Deploy the app to Azure Linux App Service.
Open the SSH of the Azure App Service to run the PM2 commands.
We can open directly with the below URL.
Path to SSH - https://YourDeployedAppName.scm.azurewebsites.net/
OR
Navigate to the deployed Azure Linux App => Advanced Tools => Go => SSH.
Run the below command to install PM2.
npm install pm2 -g
Thanks #Azure OSS Developer Support for the commands.
In Configuration section => General Settings add the Startup command.
pm2 start site/root/index.js --name mynpmnextapp
Your path may differ for the index.js file.
My app entry point is index.js.For some apps it can be server.js.Change it according to your app.
cannot find module `../build/output/log'
Make sure you are not running the PM2 with the output folder. As mentioned above it has to be the entry point either server.js or index.js based on your code files.
don't know if there is a way to update PM2 on the app service
In the KUDU Console use npm install pm2#latest -g to update the PM2.
References taken from MSDoc and npmjs.
I have a React SPA which runs in Azure Web Apps, Node stack (Node 16 LTS), via the startup command:
pm2 serve /home/site/wwwroot --no-daemon --spa
I would like to add a response header (specifically, a Content-Security-Policy header) for every outgoing request.
Things I have tried:
adding a .htaccess file
adding a web.config file
looking for an evironment setting, or way to configure either pm2, or node
I don't have any node code to change (so I can't add headers there), and doing it in React feels "too late" - I think it's something that node on the server, or Azure needs to do.
My nuclear option is to wrap Front Door around it and do it there, but I'm hoping there is way to achieve this without that.
In App Service Linux, React application can be started with PM2, npm start or custom command.
The container automatically starts your app with PM2 when one of the common Node.js files is found in your project:
Also Note that Starting from Node 14 LTS, the container doesn't automatically start your app with PM2. To start your app with PM2, set the startup command to pm2 start <.js-file-or-PM2-file> --no-daemon.
Be sure to use the --no-daemon argument because PM2 needs to run in the foreground for the container to work properly.
Reference: https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs?pivots=platform-linux
I have been using pm2 to manage my node apps for a while. In deployment steps, pm2 restart is added after deployment finished. But it throws unhandledrejection event in promise js and service becomes unavailable.
when i manually restart pm2 manually issue vanishes. we are using same deployment steps on qa and production. But this issue of taking manual restart of pm2 is only happening at qa environment.
we have tried restart pm2 script in cron job as well but that also doesn't solved our issue.
I suspect may be due to diff in npm, node versions at prod and qa env, the behaviour is different.
There many tools to deploy expressjs application, such as strongloop,pm2.
But they do not work well on windows.
I have install [pm2]2 in my window computer, and start my app.
https://i.stack.imgur.com/ZpOIa.jpg
But when i log off my computer and log in again. the service is disappear.
So I install pm2-windows-service and install pm2 as a window service. It failed again.
Anyone have a good expressjs deployment plan?
You need to make a pm2 save when you started your app. PM2 need to know which apps were started and their state to restart them after a reboot, and thats the aim of the pm2 save command which will save the state of all apps in the pm2 directory.
I'm fairly new with node.js platform.
I'm working on deploying a node.js app to production in windows sever.
Currently I'm using forever for my production server, and pm2 for development server(just to see how different process managers work.)
What I noticed is my app is down after a while (normally couple days).
I think it might be because my user session which runs the process is closed.
Can you share with me the "correct" deployment steps?
The steps I take to deploy are:
1. Run node cmd as administrator
2. Go to site root
3. Run forever start server.js or pm2 start server.js
Thanks in advance.