SSH hangs while restarting services

Kevin Oberman rkoberman at gmail.com
Tue Nov 4 05:13:35 UTC 2014


On Mon, Nov 3, 2014 at 4:48 PM, Denny Lin <dennylin93 at hs.ntnu.edu.tw> wrote:

> Hi,
>
> Recently I've been trying to restart services remotely using SSH using a
> command instead of entering the shell:
> ssh host "sudo service postgresql restart"
>
> PostgreSQL is able to restart successfully, but SSH just hangs there
> instead of exiting. I've noticed that this seems to affect any command
> which spawns a child process which doesn't exit.
>
> Is there any way to get SSH terminate? Thanks.
>
> --
> Denny Lin
>

Try "ssh -f host "sudo service postgresql restart". If a socket is open,
ssh will not exist and something in the startup is leaving something link
STDOUT open. Use of '-f'' should work around this issue. From ssh(1):
     -f      Requests ssh to go to background just before command execution.
             This is useful if ssh is going to ask for passwords or
             passphrases, but the user wants it in the background.  This
             implies -n.  The recommended way to start X11 programs at a
             remote site is with something like ssh -f host xterm.

             If the ExitOnForwardFailure configuration option is set to
“yes”,
             then a client started with -f will wait for all remote port
for‐
             wards to be successfully established before placing itself in
the
             background.
--
R. Kevin Oberman, Network Engineer, Retired
E-mail: rkoberman at gmail.com


More information about the freebsd-ports mailing list