Skip to content
oldwisenir edited this page Aug 24, 2016 · 3 revisions

pm2 usage

installation

npm install pm2@latest -g

deployment

create a folder pm2 scripts which will contain all proccesses config files

mkdir pm2-scripts

api-micro-services.json config file example

{
  apps : [{
    name        : "api-services",
    script		: "app.js",
    cwd     	: "/home/linnovate3/vod/replay-api/api-service",
    watch       : true,
    env 		: {
	MONGO_DATABASE: "replay_dev",
	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  },
  {
    name        : "query-service",
    script		: "app.js",
    cwd     	: "/home/linnovate3/vod/replay-api/query-service",
    watch       : true,
    env 		: {
	MONGO_DATABASE: "replay_dev",
	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  },
  {
    name        : "media-url-provider",
    script		: "app.js",
    cwd     	: "/home/linnovate3/vod/replay-api/media-url-provider",
    watch       : true,
    env 		: {
	MONGO_DATABASE: "replay_dev",
	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  }
 ]
}

consumers.json config file example

{
  apps : [{
    name        : "save-video",
    script      : "index.js",
    cwd			: "/home/linnovate3/vod/replay-infra/consumer",
    watch       : true,
    args		: "SaveVideo",
    env 		: {
	MONGO_DATABASE: "replay_dev",
	STORAGE_PATH: "/home/linnovate3/vod_storage_data",
   	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  },
  {
    name        : "metadata-parser",
    script      : "index.js",
    cwd			: "/home/linnovate3/vod/replay-infra/consumer",
    watch       : true,
    args		: "MetadataParser",
    env 		: {
	MONGO_DATABASE: "replay_dev",
	STORAGE_PATH: "/home/linnovate3/vod_storage_data",
   	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  },
  {
    name        : "metadata-to-mongo",
    script      : "index.js",
    cwd			: "/home/linnovate3/vod/replay-infra/consumer",
    watch       : true,
    args		: "MetadataToMongo",
    env 		: {
	MONGO_DATABASE: "replay_dev",
	STORAGE_PATH: "/home/linnovate3/vod_storage_data",
   	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  },
  {
    name        : "video-boundries",
    script      : "index.js",
    cwd			: "/home/linnovate3/vod/replay-infra/consumer",
    watch       : true,
    args		: "VideoBoundingPolygon",
    env 		: {
	MONGO_DATABASE: "replay_dev",
	STORAGE_PATH: "/home/linnovate3/vod_storage_data",
   	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  },
  {
    name        : "metadata-to-captions",
    script      : "index.js",
    cwd			: "/home/linnovate3/vod/replay-infra/consumer",
    watch       : true,
    args		: "MetadataToCaptions",
    env 		: {
	MONGO_DATABASE: "replay_dev",
	STORAGE_PATH: "/home/linnovate3/vod_storage_data",
	CAPTIONS_PATH: "captions",
   	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  }
  ]
}

replay-ui.json config file example

{
  apps : [{
    name        : "replay-ui",
    script		: "gulp",
    cwd     	: "/home/linnovate3/vod/replay",
    watch       : false,
    env 		: {
	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  }]
}

video-recorder.json config file example

{
  apps : [{
    name        : "video-recorder",
    script		: "index.js",
    cwd     	: "/home/linnovate3/vod/replay-infra/video-recorder",
    watch       : true,
    env 		: {
    INDEX 		: "102",
	MONGO_DATABASE: "replay_dev",
	MONGO_HOST 	: "localhost",
	MONGO_PORT	: "27017",
	STORAGE_PATH: "/home/linnovate3/vod_storage_data",
	NODE_ENV: "development"
    },
    env_production: {
       NODE_ENV: "production"
    }
  }]
}

note: you might need to change cwd paths on deployment

running pm2

to run all our node process.json description file use:

pm2 start /path/to/directory/pm2-scripts/* 

Keymetrics

Keymetrics is the pm2 monitoring gui

in order to use keyframe you need to link it to a pm2 instance

Configuring

go here https://app.keymetrics.io/#/

  1. add new Bucket (free versions allow only 1 bucket at a time)
  2. use the link command specified after creating the bucket