I have a remote server in which I serve a webserver using node (express) and nginx. I have a ./devops/deploy.sh
script which starts the webserver and restarts nginx. Said script works correctly if I manually connect to the instance (ssh <user>@<ip>
) and then run
cd my-repo
git pull
./devops/deploy.sh
I can not however set up a script which automates this. I tried with this script
#!/bin/bash
set -euo pipefail
usage() {
cat << EOF
Usage: ./devops/update-instance.sh <user@ip>
EOF
exit -1
}
CONNECTION_STRING=${1:-""}
if [ -z $CONNECTION_STRING ]; then
usage
fi
ssh -t $CONNECTION_STRING << EOF
cd my-repo
git pull
./devops/deploy.sh
EOF
but it gives me nohup: failed to run command 'node': No such file or directory
. This is the deploy script which I'm running locally from my machine
#!/bin/bash
set -euo pipefail
lsof -ti:3000 && kill $(lsof -ti:3000)
echo bar
echo $(node -v)
nohup node runner.js &
NGINX_CONFIG_PATH=/etc/nginx/sites-enabled/my-repo
rm -rf $NGINX_CONFIG_PATH
cp devops/nginx-config $NGINX_CONFIG_PATH
nginx -t
nginx -s reload
node runner.js
simply starts an express app, so nothing weird there.
What I want to achieve is very similar to this other post https://askubuntu.com/questions/349262/run-a-nohup-command-over-ssh-then-disconnect but no mention of this nohup + node error is given.
After looking at it I realized I'm most probably doing something wrong in how I call my deploy script but I don't really understand what it could be. In the update script I tried doing nohup ./devops/deploy.sh &
instead of simply ./devops/deploy.sh
but got the same nohup: failed to run command 'node': No such file or directory
error.
If I put the content of the ./devops/deploy.sh
script inside the ssh ... << EOF <content here> EOF
I also get the same nohup: failed to run command 'node': No such file or directory
error
Switched the ssh command to
export NVM_DIR="\$HOME/.nvm"
\. "\$NVM_DIR/nvm.sh"
\. "\$NVM_DIR/bash_completion"
cd my-repo
git pull
nohup ./devops/deploy.sh 1>api.stdout 2>api.stderr &