Neil Gaetano Lindberg
Neil Gaetano Lindberg

Reputation: 2945

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.

Doing a full build between changes is killing me so I made a script to SCP changes with the cf ssh-code usage. 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). 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. 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:

#!/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. I thought this would defeat whatever unknowns regarding no node -v or npm, or yarn, on the remote CF app container.

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.

Can anybody please tell me how to actually restart the NodeJS app so that it will pickup changes? I'll post if I figure it out.

EDIT: So, it seems I'm after behaviour that is anti-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

Upvotes: 0

Views: 448

Answers (1)

nitind
nitind

Reputation: 20013

You have to do a push to update what it uses when restarting, restaging, or rescaling.

Test locally.

Upvotes: 2

Related Questions