我已经使用微服务架构构建了nodejs应用程序。以下是架构。
根文件夹有多个微服务文件夹。 demo-ms-bootstrap有pm2生态系统文件。
我的问题是,微服务代码中的任何内容都会发生变化,它不会监视更改并重新启动服务器。如果我为每个微服务文件夹单独设置pm2进程,那么它将正常运行。
我没有在每个微服务文件夹中放置单独的pm2服务,而是在demo-ms-bootstrap文件夹中创建了一个单独的ecosystem.config.js,其中所有微服务相关的pm2配置。
我知道如果我将我的demo-ms-bootstrap ecosystem.config.js代码放在根文件夹中,那么它可能会起作用。但是我不想这样做,因为除了移动pm2 ecosytem.config.js之外我需要做很多返工。
demo-ms-bootstrap文件夹中还有其他配置。
ecosystem.config.js
module.exports = {
"apps": [
{
name: 'demo-ms-gateway',
script: '../demo-ms-gateway/bin/exec',
env: {
NODE_ENV: 'development',
APP_PROTOCOL: 'http',
APP_NAME: 'demo',
APP_HOST: '0.0.0.0',
APP_PORT: 3001,
DB_HOST: 'localhost',
DB_USER: 'dbuser',
DB_PASSWORD: 'dbuser123',
DB_NAME: 'demo',
DB_DIALECT: 'postgres',
SERVICE_NAME: 'demo-gateway'
},
log_file: "../demo-ms-gateway/logs/demo-ms-gateway.log",
error_file: "../demo-ms-gateway/logs/demo-ms-gateway.error.log",
out_file: "../demo-ms-gateway/logs/demo-ms-gateway.out.log",
pid_file: "../demo-ms-gateway/logs/demo-ms-gateway.pid",
merge_logs: true,
log_date_format: "YYYY-MM-DD HH:mm Z",
next_gen_js: true,
autorestart: true,
exec_mode: "cluster",
instances: 1,
watch: true,
watch_options: {
followSymlinks: true,
usePolling: true,
interval: 5
},
ignore_watch: [
'../demo-ms-gateway/logs',
'../demo-ms-gateway/node_modules',
'../demo-ms-gateway/.gitignore',
'../demo-ms-gateway/.sequelizerc',
'../demo-ms-gateway/package-lock.json',
'../demo-ms-gateway/package.json',
'../demo-ms-gateway/README.md'
],
node_args: ["--harmony", "--inspect"]
},
{
name: 'demo-ms-authentication',
script: '../demo-ms-authentication/bin/exec',
env: {
NODE_ENV: 'development',
APP_PROTOCOL: 'http',
APP_NAME: 'demo',
APP_HOST: '0.0.0.0',
APP_PORT: 3002,
DB_HOST: 'localhost',
DB_USER: 'dbuser',
DB_PASSWORD: 'dbuser123',
DB_NAME: 'demo',
DB_DIALECT: 'postgres',
JWT_SECRET_KEY: '.auth/.demo_id_ecdsa',
SERVICE_NAME: 'demo-authentication'
},
log_file: "../demo-ms-authentication/logs/demo-ms-authentication.log",
error_file: "../demo-ms-authentication/logs/demo-ms-authentication.error.log",
out_file: "../demo-ms-authentication/logs/demo-ms-authentication.out.log",
pid_file: "../demo-ms-authentication/logs/demo-ms-authentication.pid",
merge_logs: true,
log_date_format: "YYYY-MM-DD HH:mm Z",
next_gen_js: true,
autorestart: true,
exec_mode: "cluster",
instances: 1,
watch: true,
watch_options: {
followSymlinks: true,
usePolling: true,
interval: 5
},
ignore_watch: [
'../demo-ms-authentication/logs',
'../demo-ms-authentication/node_modules',
'../demo-ms-authentication/.gitignore',
'../demo-ms-authentication/.sequelizerc',
'../demo-ms-authentication/package-lock.json',
'../demo-ms-authentication/package.json',
'../demo-ms-authentication/README.md'
],
node_args: ["--harmony", "--inspect"]
},
{
name: 'demo-ms-user',
script: '../demo-ms-user/bin/exec',
env: {
NODE_ENV: 'development',
APP_PROTOCOL: 'http',
APP_NAME: 'demo',
APP_HOST: '0.0.0.0',
APP_PORT: 3003,
DB_HOST: 'localhost',
DB_USER: 'dbuser',
DB_PASSWORD: 'dbuser123',
DB_NAME: 'demo',
DB_DIALECT: 'postgres',
SERVICE_NAME: 'demo-user'
},
log_file: "../demo-ms-user/logs/demo-ms-user.log",
error_file: "../demo-ms-user/logs/demo-ms-user.error.log",
out_file: "../demo-ms-user/logs/demo-ms-user.out.log",
pid_file: "../demo-ms-user/logs/demo-ms-user.pid",
merge_logs: true,
log_date_format: "YYYY-MM-DD HH:mm Z",
next_gen_js: true,
autorestart: true,
exec_mode: "cluster",
instances: 1,
watch: true,
watch_options: {
followSymlinks: true,
usePolling: true,
interval: 5
},
ignore_watch: [
'../demo-ms-user/logs',
'../demo-ms-user/node_modules',
'../demo-ms-user/.gitignore',
'../demo-ms-user/.sequelizerc',
'../demo-ms-user/package-lock.json',
'../demo-ms-user/package.json',
'../demo-ms-user/README.md'
],
node_args: ["--harmony", "--inspect"]
},
{
name: 'demo-ms-product-manage',
script: '../demo-ms-product-manage/bin/exec',
env: {
NODE_ENV: 'development',
APP_PROTOCOL: 'http',
APP_NAME: 'demo',
APP_HOST: '0.0.0.0',
APP_PORT: 3004,
DB_HOST: 'localhost',
DB_USER: 'dbuser',
DB_PASSWORD: 'dbuser123',
DB_NAME: 'demo',
DB_DIALECT: 'postgres',
AWS_ACCESS_KEY_ID: '',
AWS_SECRET_ACCESS_KEY: '',
AWS_BUCKET_NAME: 'demo-assets',
AWS_ACL: 'public-read-write',
AWS_API_VERSION: '2010-12-01',
AWS_REGION: 'us-east-1',
SERVICE_NAME: 'demo-product-manage'
},
log_file: "../demo-ms-product-manage/logs/demo-ms-product-manage.log",
error_file: "../demo-ms-product-manage/logs/demo-ms-product-manage.error.log",
out_file: "../demo-ms-product-manage/logs/demo-ms-product-manage.out.log",
pid_file: "../demo-ms-product-manage/logs/demo-ms-product-manage.pid",
merge_logs: true,
log_date_format: "YYYY-MM-DD HH:mm Z",
next_gen_js: true,
autorestart: true,
exec_mode: "cluster",
instances: 1,
watch: true,
watch_options: {
followSymlinks: true,
usePolling: true,
interval: 5
},
ignore_watch: [
'../demo-ms-product-manage/logs',
'../demo-ms-product-manage/node_modules',
'../demo-ms-product-manage/.gitignore',
'../demo-ms-product-manage/.sequelizerc',
'../demo-ms-product-manage/package-lock.json',
'../demo-ms-product-manage/package.json',
'../demo-ms-product-manage/README.md'
],
node_args: ["--harmony", "--inspect"]
},
{
name: 'demo-ms-product-feed',
script: '../demo-ms-product-feed/bin/exec',
env: {
NODE_ENV: 'development',
APP_NAME: 'demo',
APP_HOST: '0.0.0.0',
APP_PORT: 3005,
DB_HOST: 'localhost',
DB_USER: 'dbuser',
DB_PASSWORD: 'dbuser123',
DB_NAME: 'demo',
DB_DIALECT: 'postgres',
SERVICE_NAME: 'demo-product-feed'
},
log_file: "../demo-ms-product-feed/logs/demo-ms-product-feed.log",
error_file: "../demo-ms-product-feed/logs/demo-ms-product-feed.error.log",
out_file: "../demo-ms-product-feed/logs/demo-ms-product-feed.out.log",
pid_file: "../demo-ms-product-feed/logs/demo-ms-product-feed.pid",
merge_logs: true,
log_date_format: "YYYY-MM-DD HH:mm Z",
next_gen_js: true,
autorestart: true,
exec_mode: "cluster",
instances: 1,
watch: true,
watch_options: {
followSymlinks: true,
usePolling: true,
interval: 5
},
ignore_watch: [
'../demo-ms-product-feed/logs',
'../demo-ms-product-feed/node_modules',
'../demo-ms-product-feed/.gitignore',
'../demo-ms-product-feed/.sequelizerc',
'../demo-ms-product-feed/package-lock.json',
'../demo-ms-product-feed/package.json',
'../demo-ms-product-feed/README.md'
],
node_args: ["--harmony", "--inspect"]
},
{
name: 'demo-ms-utility',
script: '../demo-ms-utility/bin/exec',
env: {
NODE_ENV: 'development',
APP_PROTOCOL: 'http',
APP_NAME: 'demo',
APP_HOST: '0.0.0.0',
APP_PORT: 3006,
DB_HOST: 'localhost',
DB_USER: 'dbuser',
DB_PASSWORD: 'dbuser123',
DB_NAME: 'demo',
DB_DIALECT: 'postgres',
SERVICE_NAME: 'demo-utility'
},
log_file: "../demo-ms-utility/logs/demo-ms-utility.log",
error_file: "../demo-ms-utility/logs/demo-ms-utility.error.log",
out_file: "../demo-ms-utility/logs/demo-ms-utility.out.log",
pid_file: "../demo-ms-utility/logs/demo-ms-utility.pid",
merge_logs: true,
log_date_format: "YYYY-MM-DD HH:mm Z",
next_gen_js: true,
autorestart: true,
exec_mode: "cluster",
instances: 1,
watch: true,
watch_options: {
followSymlinks: true,
usePolling: true,
interval: 5
},
ignore_watch: [
'../demo-ms-utility/logs',
'../demo-ms-utility/node_modules',
'../demo-ms-utility/.gitignore',
'../demo-ms-utility/.sequelizerc',
'../demo-ms-utility/package-lock.json',
'../demo-ms-utility/package.json',
'../demo-ms-utility/README.md'
],
node_args: ["--harmony", "--inspect"]
}]
};
任何人都可以有替代解决方案吗?