简体   繁体   English

如何在 Cloud Foundry 上重启 NodeJS 应用程序(在 scp 代码更改后)

[英]How restart a NodeJS app on Cloud Foundry (after scp'ing code changes)

I'm attempting to cleanup/fix an existing NodeJS app in IBM's implementation of CloudFoundry.我正在尝试清理/修复 IBM CloudFoundry 实现中的现有 NodeJS 应用程序。

Doing a full build between changes is killing me so I made a script to SCP changes with the cf ssh-code usage.在更改之间进行完整构建让我很沮丧,因此我使用 cf ssh-code 用法为 SCP 更改制作了一个脚本。 Here is the script.这是脚本。 I found I had to keep getting a code for this op, so I paste it to the clipboard (using clip in Windows).我发现我必须不断获取此操作的代码,因此我将其粘贴到剪贴板(在 Windows 中使用剪辑)。 You'd have to just hit paste when prompted for the password:当提示输入密码时,您只需点击粘贴:

#!/bin/bash

ibmcloud cf ssh-code | sed -n '3 p' > one-time-ssh-code && clip < one-time-ssh-code
scp -P 2222 -o User=cf:<APP GUID>/<INSTANCE NUMBER> $1 <SSH ADDRESS...cloud.ibm.com>:/home/vcap/app/$1

if [[ "$2" == "--restart" ]]
        then
                echo "Restarting Cloud Foundary app..."
                ibmcloud cf restart <APP NAME>
fi

For testing I put changes in my app.js for a log to show when the server started up.为了进行测试,我在 app.js 中进行了更改,以便在服务器启动时显示日志。 I pushed those changes in less than a second (much, much faster than doing a build)...我在不到一秒钟的时间内推动了这些更改(比构建快得多)......

$ ./scp-cf app.js
<THE ABOVE CREDENTIALS REFLECTED>'s password:
app.js                                                                                                                                                                100% 4936    32.7KB/s   00:00

I ssh into the container:我 SSH 进入容器:

#!/bin/bash

ibmcloud cf ssh-code | sed -n '3 p' > one-time-ssh-code && clip < one-time-ssh-code
ssh cf:<APP GUID>/0@<SSH ADDR>.cloud.ibm.com -p2222

I can see that the file was just updated!我可以看到文件刚刚更新!

Now, I'll run the same scp-cp app.js with the --restart flag.现在,我将使用--restart标志运行相同的scp-cp app.js --restart I thought this would defeat whatever unknowns regarding no node -v or npm, or yarn, on the remote CF app container.我认为这将击败远程 CF 应用程序容器上关于无节点 -v 或 npm 或纱线的任何未知数。

app.js                                                                                                                                                                100% 4936    31.7KB/s   00:00
Restarting Cloud Foundary app...
Invoking 'cf restart <APP NAME>

I then go look at the file I'd updated before restarting.然后我去看看我在重新启动之前更新的文件。 It is reverted to the file from the last full build...它从上次完整构建中恢复为文件...

My point here is that no matter what I can't get the app to pickup changes.我的观点是,无论如何我都无法让应用程序接收更改。 I'm only familiar with CF in conjunction with a build pipeline, but I was handed this and I really need to speed up development with the constraints that are upon me.我只熟悉 CF 与构建管道的结合,但我得到了这个,我真的需要通过我身上的约束来加速开发。

Can anybody please tell me how to actually restart the NodeJS app so that it will pickup changes?任何人都可以告诉我如何真正重新启动应用程式的NodeJS,使其皮卡的变化? I'll post if I figure it out.如果我弄清楚了,我会发布。

EDIT: So, it seems I'm after behaviour that is anti-CF.编辑:所以,看来我追求的是反 CF 的行为。 I still want to do what I'm asking because, unfortunately, I'm working with an existing project with zero tests and I'm in a crunch to fix it - via debugging via logs, remote only.我仍然想做我所要求的,因为不幸的是,我正在使用一个零测试的现有项目,我正忙于修复它 - 通过日志调试,仅远程。

Could somebody explain why I see node here:有人可以解释为什么我在这里看到节点:

vcap@id:~/app$ ps aux | grep node
vcap         140  0.0  0.0   4636   788 ?        S    17:53   0:00 sh -c node app.js
vcap         141  0.3  0.3 1085252 109356 ?      Sl   17:53   0:01 node app.js
vcap         198  0.0  0.0  63336  1104 pts/0    S+   17:59   0:00 grep --color=auto node

But, not here:但是,不是这里:

vcap@id:~/app$ node -v
bash: node: command not found

You have to do a push to update what it uses when restarting, restaging, or rescaling.您必须进行push以更新它在重新启动、重新分段或重新缩放时使用的内容。

Test locally.本地测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM