Nginx w/ ssh restart

Mansoor Peerbhoy mansoor at zimbra.com
Wed Sep 17 10:27:07 MSD 2008


BTW: 
NGINX itself has a call to setsid() 

./src/os/unix/ngx_daemon.c: if (setsid() == -1) { 
./src/os/unix/ngx_daemon.c: ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "setsid() failed"); 

So it looks like it may be the sysv service script 

HTH 
Mansoort 



----- Original Message ----- 
From: "Mansoor Peerbhoy" <mansoor at zimbra.com> 
To: nginx at sysoev.ru 
Sent: Wednesday, September 17, 2008 11:47:43 AM GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi 
Subject: Re: Nginx w/ ssh restart 


Hi Clint 

It is not sufficient to merely close your file descriptors -- you must also ensure that any process that you start via ssh detaches from its controlling terminal. 
That is not the same thing as closing stdout/stdin/stderr. 

That is because signals like SIGINT get delivered to the foreground process by means of the controlling terminal, which interprets special keystrokes like ^C 

As long as any process started by SSH is still controlled by the terminal that was given to SSH, then SSH shell will not exit cleanly. 

There is an IOCTL that allows you to do this, and it is called TIOCNOTTY. See tty_ioctl(4) for details. 
There is also the setsid() library call which, according to the man page: 

<quote> 

DESCRIPTION 
setsid() creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session, the process group leader of the new process 
group, and has no controlling tty. The process group ID and session ID of the calling process are set to the PID of the calling process. The calling process will be the only process 
in this new process group and in this new session. 

</quote> 


Therefore, it appears that setsid() would eventually end up detaching the calling process from the controlling terminal. 

You are in luck. It appears that there is a setsid shell program that does the same thing, but to a new process. 

So you can run nginx in a new session by saying 

setsid /path/to/nginx -c /path/to/nginx/conf 

After that, I daresay you should be OK (though I haven't tried it myself) 



Thanks 
Mansoor 




----- Original Message ----- 
From: "Clint Priest" <cpriest at warpmail.net> 
To: nginx at sysoev.ru 
Sent: Monday, September 15, 2008 5:49:02 AM GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi 
Subject: Nginx w/ ssh restart 

I'm having trouble getting nginx to restart via an ssh shell. From a 
remote machine doing "ssh root at web1 service nginx restart" is causing 
the ssh shell to not disconnect once nginx restarts. 

I've had similar trouble with my own daemons which I have solved by 
ensuring all file descriptors are closed before or after the daemon 
fork. Does nginx do this? 

Any other ideas which would cause nginx to hang the shell? 

Thanks, 

-Clint 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20080916/d44249ef/attachment.html>


More information about the nginx mailing list