Wednesday, April 6, 2022

[SOLVED] AWS EC2 AMI User Data run PM2

Issue

I want to start my application on an instance boot. I used the following user data, but I'm unable to see any process running in pm2.

Note: Creating an instance using an AMI. NodeJs, PM2 and all the dependencies areinstalled. I can SSH to server and start my application using pm2 manually.

#!/bin/bash
pm2 start /home/ubuntu/foyrinfrasubscription/server/server.js --name "ReportSub"
pm2 save
pm2 resurrect

Solution

I recommend using pm2 startup command to create init services script

Manual:

https://pm2.keymetrics.io/docs/usage/startup/

Example:

https://futurestud.io/tutorials/pm2-restart-processes-after-system-reboot



Answered By - AWS PS
Answer Checked By - Mildred Charles (WPSolving Admin)