7

I am running ssh somehost "service XXX restart" and the shell hangs.

The service is nodeJS and I see express is listening on port ... print I made in server.js and that's it, it does not return to prompt, it simply hangs.

I tried nohup and & but it does not help. What else can I try?

2 Answers 2

9

turns out that using -t resolves the issue.

ssh -t root@somehost "service XXX restart" does not hang.

other suggestions from the comments that might resolve this:

  • node myScript.js & disown
  • exec node myScript.js &
Sign up to request clarification or add additional context in comments.

4 Comments

This also terminates the backend process that actually hangs your command.
@AlanDuan I've used this on a webservice for years. Actually still using it.. and it works fine..
Future readers might want to try node myScript.js & disown or exec node myScript.js & in order to detach itself from current process. See more info here.
If you're running this ssh within a script, you may have to double the -t, like ssh -tt root@somehost "command" . This worked for me!
0

Using ssh -t does not hang, but it terminates the remote process too.

What works for me is just to run the remote process in background as shown below:

ssh somehost /path/to/some/script augment1 augment2 &

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.