If the ansible-playbook has been deployed successfully, then the Node.js processes will be managed by PM2 (Process Manager 2). PM2 has been chosen because of the following features:
- Monitoring
- Log management
- Hot reloading
- Cluster mode
PM2 will run under user that has been defined at the variable "{{ jiskefet_user }}"
(default is jiskefet
) with the json file below.
{
"apps": [
{
"name": "API",
"cwd": "/var/lib/jiskefet/jiskefet-api",
"script": "npm",
"args": "run start",
"instances": "max",
"exec_mode": "cluster",
"autorestart": true,
"watch": false,
"env": {
"NODE_ENV": "dev"
},
"env_dev": {
"NODE_ENV": "dev"
},
"env_staging": {
"NODE_ENV": "staging"
},
"env_prod": {
"NODE_ENV": "prod"
}
}
]
}
- Go to the directory
/var/lib/jiskefet
. - Check if
ecosystem.json
exists in the directory. - Run command the following command in your terminal
$ pm2 start ecosystem.json # starts the application with NODE_ENV=dev
Or specify an environment flag as shown below
$ pm2 start ecosystem.json --env prod # starts the application with variables defined from `env_prod`
- Run
pm2 list
to get an overview of the processes orpm2 monit
to use the monitoring functionality.
- If your
ecosystem.json
has been updated, please runpm2 reload ecosystem.json --update-env
to get the new changes. - If the API has been updated, you need to run the following in order to get the latest API running:
pm2 kill
to stop all the current pm2 processes.pm2 start ecosystem.json
to start pm2 again.pm2 save
to save the new environment for the startup process.