Although there are couple of similar questions over here I did not manage to find the one that answers my needs.
So what I need is to run a script that will deploy my application on the remote server. So when my CI runs all tests successfully it should run deployment script.
So I obviously wanted for my CI to run that script on the remote machine.
What I found is that I have couple of ways for my CI to run script on remote server:
ssh user@remote_server 'SOME_ENV_VARS=staging_vars bash -s' < deploy.sh
This works almost perfectly.
My deploy script is something like this:
cd project killall node; bash start.sh -s & <- THIS IS IMPORTANT exit;
I also tried:
nohup ./start.sh -s < /dev/null >/dev/null 2>&1 & exit;
screen -dmS important_server bash start.sh -s
The start.sh script is a never ending process (it starts server). It works normally but it never disconnects from ssh so my CI cannot finish the build.
The the best I actually managed to do is with Gaurav's proposal. The process did remain in background after termination of ssh connection. But I still needed to terminate it manually because my CI job was hanging 🙁
I must have done something wrong.