Deployment hooks can't see pm2

I have a bit customized deployment where I need to run “pm2 restart app-name” at one point over a deploy hook. But the issue is the pm2 within deploying cannot see the actual pm2 instances running on the machine. In terminal as “cleavr” user when you run “pm2 status” or “pm2 list” I get the apps currently running, but when run as a deployment hook it has access to pm2 but returns empty list. I tried using sudo to specify cleavr as user, even tried creating, putting it in project dir and then running that from the hook, and even adding “export PM2_HOME=/home/cleavr/.pm2”, but I just can’t get deployment hook scripts to see the actual pm2 instance (the one I can see when I’m in terminal as cleavr). Any insight into this?

Hello @dino,

If we understand your query correctly, the PM2 installation is located at /opt/pm2. We suggest updating your script file with the following content:

env PM2_HOME=/opt/pm2 pm2 restart /home/{{ serverUser }}/{{ domain }}/.cleavr.config.js

OR, create a custom deployment hook with the following script:

env PM2_HOME=/opt/pm2 pm2 restart {{ projectPath }}/.cleavr.config.js

We hope that our response to your query was helpful. If it did not address your issue, please let us know so that we can better assist you.