运行 带有 PM2 的 Gatsby JS
Running Gatsby JS with PM2
此 post 已根据调试更新了新信息
我正在尝试使用 pm2 为 EC2 上的 GatsbyJS 站点进行部署。我以前能够使用 pm2 在 ec2 上手动将 Gatsby 设置为 运行,但不能通过部署。
这是我的 ecosystem.config.js
文件
module.exports = {
apps : [{
name: 'wispyCo',
script: 'npm',
args : 'start',
watch: '.',
env:{
NODE_ENV: "production",
MY_SANITY_TOKEN : "fdsa",
SANITY_TOKEN_WRITE : "fdsaf",
SLACK_WEBHOOK_URL : "fds"
}
},
],
deploy : {
production : {
user : 'ubuntu',
host : 'ec2-54-226-83-78.compute-1.amazonaws.com',
ref : 'origin/development',
repo : 'git@github.com:fdsafa',
path : '/home/ubuntu/wispyDeploy',
'pre-deploy-local': '',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production',
'pre-setup': '',
}
}
};
这是我的 package.json for Gatsby
脚本
"scripts": {
"develop": "gatsby develop -H 0.0.0.0 --port 8000",
"start": "run-p start:**",
"start:app": "npm run develop",
"start:lambda": "netlify-lambda serve src/lambda",
"build": "gatsby build && netlify-lambda build src/lambda",
"build:app": "gatsby build",
"build:lambda": "netlify-lambda build src/lambda"
}
发生的事情是 pm2 一直在重新加载,看起来像这样。
PM2 | 2020-05-07T13:29:35: PM2 log: pid=31900 msg=process killed
PM2 | 2020-05-07T13:29:35: PM2 log: App [wispyCo:0] starting in -fork mode-
PM2 | 2020-05-07T13:29:35: PM2 log: App [wispyCo:0] online
PM2 | 2020-05-07T13:29:37: PM2 log: Change detected on path lambda/hello.js for app wispyCo - restarting
PM2 | 2020-05-07T13:29:37: PM2 log: Stopping app:wispyCo id:0
PM2 | 2020-05-07T13:29:37: PM2 log: App [wispyCo:0] exited with code [0] via signal [SIGINT]
PM2 | 2020-05-07T13:29:38: PM2 log: pid=32016 msg=process killed
PM2 | 2020-05-07T13:29:38: PM2 log: App [wispyCo:0] starting in -fork mode-
PM2 | 2020-05-07T13:29:38: PM2 log: App [wispyCo:0] online
PM2 | 2020-05-07T13:29:40: PM2 log: Change detected on path lambda/hello.js for app wispyCo - restarting
PM2 | 2020-05-07T13:29:40: PM2 log: Stopping app:wispyCo id:0
PM2 | 2020-05-07T13:29:40: PM2 log: App [wispyCo:0] exited with code [0] via signal [SIGINT]
PM2 | 2020-05-07T13:29:40: PM2 log: pid=32132 msg=process killed
PM2 | 2020-05-07T13:29:40: PM2 log: App [wispyCo:0] starting in -fork mode-
PM2 | 2020-05-07T13:29:40: PM2 log: App [wispyCo:0] online
/home/ubuntu/.pm2/logs/wispyCo-error.log last 15 lines:
/home/ubuntu/.pm2/logs/wispyCo-out.log last 15 lines:
0|wispyCo | > run-p start:**
0|wispyCo |
0|wispyCo |
0|wispyCo | > gatsby-starter-default@0.1.0 start:app /home/ubuntu/wispyDeploy/source
0|wispyCo | > npm run develop
0|wispyCo |
0|wispyCo |
0|wispyCo | > gatsby-starter-default@0.1.0 start:lambda /home/ubuntu/wispyDeploy/source
0|wispyCo | > netlify-lambda serve src/lambda
0|wispyCo |
0|wispyCo |
0|wispyCo | > gatsby-starter-default@0.1.0 develop /home/ubuntu/wispyDeploy/source
0|wispyCo | > gatsby develop -H 0.0.0.0 --port 8000
0|wispyCo |
0|wispyCo | netlify-lambda: Starting server
PM2 | Change detected on path lambda/hello.js for app wispyCo - restarting
PM2 | Stopping app:wispyCo id:0
0|wispyCo | Hash: d0c09734a446097dbcc4
0|wispyCo | Version: webpack 4.41.5
0|wispyCo | Time: 1141ms
0|wispyCo | Built at: 05/07/2020 1:29:43 PM
0|wispyCo | Asset Size Chunks Chunk Names
0|wispyCo | hello.js 131 KiB 0 [emitted] hello
0|wispyCo | slack.js 277 KiB 1 [emitted] slack
0|wispyCo | Entrypoint hello = hello.js
0|wispyCo | Entrypoint slack = slack.js
0|wispyCo | [0] /home/ubuntu/wispyDeploy/source/node_modules/object-assign/index.js 2.06 KiB {0} [built]
0|wispyCo | [2] external "stream" 42 bytes {0} {1} [built]
0|wispyCo | [3] external "url" 42 bytes {0} {1} [built]
0|wispyCo | [5] external "http" 42 bytes {0} {1} [built]
0|wispyCo | [8] external "https" 42 bytes {0} {1} [built]
0|wispyCo | [14] external "fs" 42 bytes {0} {1} [built]
0|wispyCo | [15] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/filter.js 66 bytes {0} [built]
0|wispyCo | [16] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/map.js 57 bytes {0} [built]
0|wispyCo | [18] /home/ubuntu/wispyDeploy/source/node_modules/dotenv/lib/main.js 2.93 KiB {0} {1} [built]
0|wispyCo | [19] external "path" 42 bytes {0} {1} [built]
0|wispyCo | [23] external "querystring" 42 bytes {0} {1} [built]
0|wispyCo | [58] /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js 7.93 KiB {1} [built]
0|wispyCo | [59] ./hello.js 1.79 KiB {0} [built]
0|wispyCo | [60] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/client/lib/sanityClient.js 3.43 KiB {0} [built]
0|wispyCo | [155] ./slack.js 1000 bytes {1} [built]
0|wispyCo | + 165 hidden modules
0|wispyCo | WARNING in /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/iconv-loader.js 9:12-34
0|wispyCo | Critical dependency: the request of a dependency is an expression
0|wispyCo | @ /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/encoding.js
0|wispyCo | @ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/lib/body.js
0|wispyCo | @ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js
0|wispyCo | @ ./slack.js
PM2 | App [wispyCo:0] exited with code [0] via signal [SIGINT]
PM2 | pid=32248 msg=process killed
PM2 | App [wispyCo:0] starting in -fork mode-
PM2 | App [wispyCo:0] online
0|wispyCo | > gatsby-starter-default@0.1.0 start /home/ubuntu/wispyDeploy/source
0|wispyCo | > run-p start:**
0|wispyCo | > gatsby-starter-default@0.1.0 start:lambda /home/ubuntu/wispyDeploy/source
0|wispyCo | > netlify-lambda serve src/lambda
0|wispyCo | > gatsby-starter-default@0.1.0 start:app /home/ubuntu/wispyDeploy/source
0|wispyCo | > npm run develop
0|wispyCo | > gatsby-starter-default@0.1.0 develop /home/ubuntu/wispyDeploy/source
0|wispyCo | > gatsby develop -H 0.0.0.0 --port 8000
0|wispyCo | netlify-lambda: Starting server
pm2.log 如下所示
2020-05-07T13:31:26: PM2 log: Change detected on path lambda/hello.js for app wispyCo - restarting
2020-05-07T13:31:26: PM2 log: Stopping app:wispyCo id:0
2020-05-07T13:31:26: PM2 log: App [wispyCo:0] exited with code [0] via signal [SIGINT]
2020-05-07T13:31:26: PM2 log: pid=4137 msg=process killed
2020-05-07T13:31:26: PM2 log: App [wispyCo:0] starting in -fork mode-
2020-05-07T13:31:26: PM2 log: App [wispyCo:0] online
不是 error.log 而是 out.log 看起来像下面的 pm2 再次重启
> gatsby-starter-default@0.1.0 start /home/ubuntu/wispyDeploy/source
> run-p start:**
> gatsby-starter-default@0.1.0 start:lambda /home/ubuntu/wispyDeploy/source
> netlify-lambda serve src/lambda
> gatsby-starter-default@0.1.0 start:app /home/ubuntu/wispyDeploy/source
> npm run develop
> gatsby-starter-default@0.1.0 develop /home/ubuntu/wispyDeploy/source
> gatsby develop -H 0.0.0.0 --port 8000
netlify-lambda: Starting server
Hash: d0c09734a446097dbcc4
Version: webpack 4.41.5
Time: 1117ms
Built at: 05/07/2020 1:35:58 PM
Asset Size Chunks Chunk Names
hello.js 131 KiB 0 [emitted] hello
slack.js 277 KiB 1 [emitted] slack
Entrypoint hello = hello.js
Entrypoint slack = slack.js
[0] /home/ubuntu/wispyDeploy/source/node_modules/object-assign/index.js 2.06 KiB {0} [built]
[2] external "stream" 42 bytes {0} {1} [built]
[3] external "url" 42 bytes {0} {1} [built]
[5] external "http" 42 bytes {0} {1} [built]
[8] external "https" 42 bytes {0} {1} [built]
[14] external "fs" 42 bytes {0} {1} [built]
[15] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/filter.js 66 bytes {0} [built]
[16] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/map.js 57 bytes {0} [built]
[18] /home/ubuntu/wispyDeploy/source/node_modules/dotenv/lib/main.js 2.93 KiB {0} {1} [built]
[19] external "path" 42 bytes {0} {1} [built]
[23] external "querystring" 42 bytes {0} {1} [built]
[58] /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js 7.93 KiB {1} [built]
[59] ./hello.js 1.79 KiB {0} [built]
[60] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/client/lib/sanityClient.js 3.43 KiB {0} [built]
[155] ./slack.js 1000 bytes {1} [built]
+ 165 hidden modules
WARNING in /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/iconv-loader.js 9:12-34
Critical dependency: the request of a dependency is an expression
@ /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/encoding.js
@ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/lib/body.js
@ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js
@ ./slack.js
Lambda server is listening on 9000
> gatsby-starter-default@0.1.0 start /home/ubuntu/wispyDeploy/source
> run-p start:**
最终对我有用的是以下我删除了集群模式,将 watch 更改为 false 并在两个地方将 nod env 更改为 development
module.exports = {
apps: [
{
name: "wispyCo",
script: "npm",
args: "start",
watch: false,
env: {
NODE_ENV: "development",
SANITY_TOKEN:
"fdsf",
SENDGRID_API_KEY:
"fsdafs",
SENDGRID_TO_EMAIL: "fdsfa.org",
},
},
],
deploy: {
production: {
user: "ubuntu",
host: "fdsaf.amazonaws.com",
ref: "origin/development",
repo: "git@github.com:fdsfa.git",
path: "/home/ubuntu/wispyDeploy",
"pre-deploy-local": "",
"post-deploy":
"npm install && pm2 reload ecosystem.config.js --env development && npm install -g gatsby-cli",
"pre-setup": "",
},
},
}
此 post 已根据调试更新了新信息
我正在尝试使用 pm2 为 EC2 上的 GatsbyJS 站点进行部署。我以前能够使用 pm2 在 ec2 上手动将 Gatsby 设置为 运行,但不能通过部署。
这是我的 ecosystem.config.js
文件
module.exports = {
apps : [{
name: 'wispyCo',
script: 'npm',
args : 'start',
watch: '.',
env:{
NODE_ENV: "production",
MY_SANITY_TOKEN : "fdsa",
SANITY_TOKEN_WRITE : "fdsaf",
SLACK_WEBHOOK_URL : "fds"
}
},
],
deploy : {
production : {
user : 'ubuntu',
host : 'ec2-54-226-83-78.compute-1.amazonaws.com',
ref : 'origin/development',
repo : 'git@github.com:fdsafa',
path : '/home/ubuntu/wispyDeploy',
'pre-deploy-local': '',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production',
'pre-setup': '',
}
}
};
这是我的 package.json for Gatsby
脚本"scripts": {
"develop": "gatsby develop -H 0.0.0.0 --port 8000",
"start": "run-p start:**",
"start:app": "npm run develop",
"start:lambda": "netlify-lambda serve src/lambda",
"build": "gatsby build && netlify-lambda build src/lambda",
"build:app": "gatsby build",
"build:lambda": "netlify-lambda build src/lambda"
}
发生的事情是 pm2 一直在重新加载,看起来像这样。
PM2 | 2020-05-07T13:29:35: PM2 log: pid=31900 msg=process killed
PM2 | 2020-05-07T13:29:35: PM2 log: App [wispyCo:0] starting in -fork mode-
PM2 | 2020-05-07T13:29:35: PM2 log: App [wispyCo:0] online
PM2 | 2020-05-07T13:29:37: PM2 log: Change detected on path lambda/hello.js for app wispyCo - restarting
PM2 | 2020-05-07T13:29:37: PM2 log: Stopping app:wispyCo id:0
PM2 | 2020-05-07T13:29:37: PM2 log: App [wispyCo:0] exited with code [0] via signal [SIGINT]
PM2 | 2020-05-07T13:29:38: PM2 log: pid=32016 msg=process killed
PM2 | 2020-05-07T13:29:38: PM2 log: App [wispyCo:0] starting in -fork mode-
PM2 | 2020-05-07T13:29:38: PM2 log: App [wispyCo:0] online
PM2 | 2020-05-07T13:29:40: PM2 log: Change detected on path lambda/hello.js for app wispyCo - restarting
PM2 | 2020-05-07T13:29:40: PM2 log: Stopping app:wispyCo id:0
PM2 | 2020-05-07T13:29:40: PM2 log: App [wispyCo:0] exited with code [0] via signal [SIGINT]
PM2 | 2020-05-07T13:29:40: PM2 log: pid=32132 msg=process killed
PM2 | 2020-05-07T13:29:40: PM2 log: App [wispyCo:0] starting in -fork mode-
PM2 | 2020-05-07T13:29:40: PM2 log: App [wispyCo:0] online
/home/ubuntu/.pm2/logs/wispyCo-error.log last 15 lines:
/home/ubuntu/.pm2/logs/wispyCo-out.log last 15 lines:
0|wispyCo | > run-p start:**
0|wispyCo |
0|wispyCo |
0|wispyCo | > gatsby-starter-default@0.1.0 start:app /home/ubuntu/wispyDeploy/source
0|wispyCo | > npm run develop
0|wispyCo |
0|wispyCo |
0|wispyCo | > gatsby-starter-default@0.1.0 start:lambda /home/ubuntu/wispyDeploy/source
0|wispyCo | > netlify-lambda serve src/lambda
0|wispyCo |
0|wispyCo |
0|wispyCo | > gatsby-starter-default@0.1.0 develop /home/ubuntu/wispyDeploy/source
0|wispyCo | > gatsby develop -H 0.0.0.0 --port 8000
0|wispyCo |
0|wispyCo | netlify-lambda: Starting server
PM2 | Change detected on path lambda/hello.js for app wispyCo - restarting
PM2 | Stopping app:wispyCo id:0
0|wispyCo | Hash: d0c09734a446097dbcc4
0|wispyCo | Version: webpack 4.41.5
0|wispyCo | Time: 1141ms
0|wispyCo | Built at: 05/07/2020 1:29:43 PM
0|wispyCo | Asset Size Chunks Chunk Names
0|wispyCo | hello.js 131 KiB 0 [emitted] hello
0|wispyCo | slack.js 277 KiB 1 [emitted] slack
0|wispyCo | Entrypoint hello = hello.js
0|wispyCo | Entrypoint slack = slack.js
0|wispyCo | [0] /home/ubuntu/wispyDeploy/source/node_modules/object-assign/index.js 2.06 KiB {0} [built]
0|wispyCo | [2] external "stream" 42 bytes {0} {1} [built]
0|wispyCo | [3] external "url" 42 bytes {0} {1} [built]
0|wispyCo | [5] external "http" 42 bytes {0} {1} [built]
0|wispyCo | [8] external "https" 42 bytes {0} {1} [built]
0|wispyCo | [14] external "fs" 42 bytes {0} {1} [built]
0|wispyCo | [15] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/filter.js 66 bytes {0} [built]
0|wispyCo | [16] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/map.js 57 bytes {0} [built]
0|wispyCo | [18] /home/ubuntu/wispyDeploy/source/node_modules/dotenv/lib/main.js 2.93 KiB {0} {1} [built]
0|wispyCo | [19] external "path" 42 bytes {0} {1} [built]
0|wispyCo | [23] external "querystring" 42 bytes {0} {1} [built]
0|wispyCo | [58] /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js 7.93 KiB {1} [built]
0|wispyCo | [59] ./hello.js 1.79 KiB {0} [built]
0|wispyCo | [60] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/client/lib/sanityClient.js 3.43 KiB {0} [built]
0|wispyCo | [155] ./slack.js 1000 bytes {1} [built]
0|wispyCo | + 165 hidden modules
0|wispyCo | WARNING in /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/iconv-loader.js 9:12-34
0|wispyCo | Critical dependency: the request of a dependency is an expression
0|wispyCo | @ /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/encoding.js
0|wispyCo | @ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/lib/body.js
0|wispyCo | @ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js
0|wispyCo | @ ./slack.js
PM2 | App [wispyCo:0] exited with code [0] via signal [SIGINT]
PM2 | pid=32248 msg=process killed
PM2 | App [wispyCo:0] starting in -fork mode-
PM2 | App [wispyCo:0] online
0|wispyCo | > gatsby-starter-default@0.1.0 start /home/ubuntu/wispyDeploy/source
0|wispyCo | > run-p start:**
0|wispyCo | > gatsby-starter-default@0.1.0 start:lambda /home/ubuntu/wispyDeploy/source
0|wispyCo | > netlify-lambda serve src/lambda
0|wispyCo | > gatsby-starter-default@0.1.0 start:app /home/ubuntu/wispyDeploy/source
0|wispyCo | > npm run develop
0|wispyCo | > gatsby-starter-default@0.1.0 develop /home/ubuntu/wispyDeploy/source
0|wispyCo | > gatsby develop -H 0.0.0.0 --port 8000
0|wispyCo | netlify-lambda: Starting server
pm2.log 如下所示
2020-05-07T13:31:26: PM2 log: Change detected on path lambda/hello.js for app wispyCo - restarting
2020-05-07T13:31:26: PM2 log: Stopping app:wispyCo id:0
2020-05-07T13:31:26: PM2 log: App [wispyCo:0] exited with code [0] via signal [SIGINT]
2020-05-07T13:31:26: PM2 log: pid=4137 msg=process killed
2020-05-07T13:31:26: PM2 log: App [wispyCo:0] starting in -fork mode-
2020-05-07T13:31:26: PM2 log: App [wispyCo:0] online
不是 error.log 而是 out.log 看起来像下面的 pm2 再次重启
> gatsby-starter-default@0.1.0 start /home/ubuntu/wispyDeploy/source
> run-p start:**
> gatsby-starter-default@0.1.0 start:lambda /home/ubuntu/wispyDeploy/source
> netlify-lambda serve src/lambda
> gatsby-starter-default@0.1.0 start:app /home/ubuntu/wispyDeploy/source
> npm run develop
> gatsby-starter-default@0.1.0 develop /home/ubuntu/wispyDeploy/source
> gatsby develop -H 0.0.0.0 --port 8000
netlify-lambda: Starting server
Hash: d0c09734a446097dbcc4
Version: webpack 4.41.5
Time: 1117ms
Built at: 05/07/2020 1:35:58 PM
Asset Size Chunks Chunk Names
hello.js 131 KiB 0 [emitted] hello
slack.js 277 KiB 1 [emitted] slack
Entrypoint hello = hello.js
Entrypoint slack = slack.js
[0] /home/ubuntu/wispyDeploy/source/node_modules/object-assign/index.js 2.06 KiB {0} [built]
[2] external "stream" 42 bytes {0} {1} [built]
[3] external "url" 42 bytes {0} {1} [built]
[5] external "http" 42 bytes {0} {1} [built]
[8] external "https" 42 bytes {0} {1} [built]
[14] external "fs" 42 bytes {0} {1} [built]
[15] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/filter.js 66 bytes {0} [built]
[16] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/map.js 57 bytes {0} [built]
[18] /home/ubuntu/wispyDeploy/source/node_modules/dotenv/lib/main.js 2.93 KiB {0} {1} [built]
[19] external "path" 42 bytes {0} {1} [built]
[23] external "querystring" 42 bytes {0} {1} [built]
[58] /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js 7.93 KiB {1} [built]
[59] ./hello.js 1.79 KiB {0} [built]
[60] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/client/lib/sanityClient.js 3.43 KiB {0} [built]
[155] ./slack.js 1000 bytes {1} [built]
+ 165 hidden modules
WARNING in /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/iconv-loader.js 9:12-34
Critical dependency: the request of a dependency is an expression
@ /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/encoding.js
@ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/lib/body.js
@ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js
@ ./slack.js
Lambda server is listening on 9000
> gatsby-starter-default@0.1.0 start /home/ubuntu/wispyDeploy/source
> run-p start:**
最终对我有用的是以下我删除了集群模式,将 watch 更改为 false 并在两个地方将 nod env 更改为 development
module.exports = {
apps: [
{
name: "wispyCo",
script: "npm",
args: "start",
watch: false,
env: {
NODE_ENV: "development",
SANITY_TOKEN:
"fdsf",
SENDGRID_API_KEY:
"fsdafs",
SENDGRID_TO_EMAIL: "fdsfa.org",
},
},
],
deploy: {
production: {
user: "ubuntu",
host: "fdsaf.amazonaws.com",
ref: "origin/development",
repo: "git@github.com:fdsfa.git",
path: "/home/ubuntu/wispyDeploy",
"pre-deploy-local": "",
"post-deploy":
"npm install && pm2 reload ecosystem.config.js --env development && npm install -g gatsby-cli",
"pre-setup": "",
},
},
}