Search code examples
node.jsbashpm2circleci

Use pm2 with CircleCI


I am using pm2 on my remote ubuntu server and CircleCI for CI, I've got the following configuration files:

version: 2.1
orbs:
  node: circleci/node@1.1.6
jobs:
  deploy-prod:
    docker:
    # specify the version you desire here (you might not want node)
    - image: circleci/node:7.10
    steps:
        - checkout
        - run: ssh -oStrictHostKeyChecking=no -v $DROPLET_USER@$DROPLET_IP ./deploy_project.sh $MICROSERVICE_NAME
workflows:
    build-and-test:
      jobs:
        - deploy-prod:
            filters:
              branches:
                only:
                  - master

In my deploy script I do the following:

cd /var/www/nodejs/$1
git pull git@github.com:DevandScorp/hippocrates_authorizationmicroservice.git
cd ..
pm2 restart ecosystem.config.js --only $1

But I've got the following error:

./deploy_project.sh: line 4: pm2: command not found

Is it possible to run my server's pm2 in CircleCI config or can I reload my microservice automatically in another way?


Solution

  • So, if you want to make anything on your server using CircleCI, it's just a waste of time. CircleCI provides a virtual environment, where you can, for example, make some tests. Also you can push changes on your remote server, but CircleCI will not have any access to your server's system. So if we speak about pm2, you can enable watch mode and relaunch your microservice everytime CircleCI push changes to it