The script below never prints done
unless you manually hit the enter key. The dev machine is osx, the server ubuntu 22.04.
It's a script to restart the remote web server. Web server uses bun.js
javascript server, the remote command first kills any bun
process, and then starts server with nohup
.
function remote() {
ssh -l root -p $PORT $HOST "source ~/.bash_profile && $1"
}
echo " restarting server"
remote "killall -r bun || true && nohup /apps/run_server.ts > /logs/server.txt 2>&1 < /dev/null &"
echo " done"
The /apps/run_server.ts
content, a javascript (typescript) code with shebang:
#!/usr/bin/env bun
import 'my_server'
run_myserver()
&
applies to the whole line, including the killall command. Try to put nohup in a subshell
.. && (nohup /apps/run_server.ts > /logs/server.txt 2>&1 < /dev/null &)