如何从python shell命令启动节点服务器?

时间:2020-05-09 16:47:41

标签: python node.js shell nohup

我在从Python启动节点服务器时遇到问题。我尝试这样称呼它:

[debug] [2020-05-09T16:18:57.519Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2020-05-09T16:18:57.519Z] > authorizing via signed-in user
[debug] [2020-05-09T16:18:57.526Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[debug] [2020-05-09T16:18:57.527Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token  
 <request body omitted>
[debug] [2020-05-09T16:18:57.722Z] <<< HTTP RESPONSE 200 {"content-type":"application/json; charset=utf-8","vary":"X-Origin, Referer, Origin,Accept-Encoding","date":"Sat, 09 May 2020 16:18:57 GMT","server":"scaffolding on HTTPServer2","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","accept-ranges":"none","transfer-encoding":"chunked"}
[debug] [2020-05-09T16:18:57.738Z] >>> HTTP REQUEST GET https://firebase.googleapis.com/v1beta1/projects/-/webApps/[projectId]/config  

[debug] [2020-05-09T16:18:57.969Z] <<< HTTP RESPONSE 400 {"vary":"X-Origin, Referer, Origin,Accept-Encoding","content-type":"application/json; charset=UTF-8","date":"Sat, 09 May 2020 16:18:57 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","accept-ranges":"none","transfer-encoding":"chunked"}
[debug] [2020-05-09T16:18:57.969Z] <<< HTTP RESPONSE BODY {"error":{"code":400,"message":"Request contains an invalid argument.","status":"INVALID_ARGUMENT"}}
[debug] [2020-05-09T16:18:57.972Z] HTTP Error: 400, Request contains an invalid argument.
[debug] [2020-05-09T16:18:57.975Z] FirebaseError: HTTP Error: 400, Request contains an invalid argument.

但是我收到以下错误

    os.system("nohup node /opt/solvoerp/solvo-erp/w_sender/app.js")

如果我从外壳执行命令,则节点服务器执行正确,可能是外壳问题。

1 个答案:

答案 0 :(得分:0)

在os.system或子进程结束调用该进程后,节点服务器关闭,因此我使用pm2来守护节点服务器,如下所示:

from subprocess import call,check_call

check_call(['pm2', 'start', 'node /opt/solvoerp/solvo-erp/w_sender/app.js'])