<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Arial; font-size: 10pt; color: #000000'>BTW:<br>NGINX itself has a call to setsid()<br><br>./src/os/unix/ngx_daemon.c:&nbsp;&nbsp;&nbsp; if (setsid() == -1) {<br>./src/os/unix/ngx_daemon.c:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "setsid() failed");<br><br>So it looks like it may be the sysv service script<br><br>HTH<br>Mansoort<br><br><br><br>----- Original Message -----<br>From: "Mansoor Peerbhoy" &lt;mansoor@zimbra.com&gt;<br>To: nginx@sysoev.ru<br>Sent: Wednesday, September 17, 2008 11:47:43 AM GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi<br>Subject: Re: Nginx w/ ssh restart<br><br><style>p { margin: 0; }</style><div style="font-family: Arial; font-size: 10pt; color: rgb(0, 0, 0);">Hi Clint<br><br>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.<br>That is not the same thing as closing stdout/stdin/stderr. <br><br>That is because signals like SIGINT get delivered to the foreground process by means of the controlling terminal, which interprets special keystrokes like ^C<br><br>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.<br><br>There is an IOCTL that allows you to do this, and it is called TIOCNOTTY. See tty_ioctl(4) for details.<br>There is also the setsid() library call which, according to the man page:<br><br>&lt;quote&gt;<br><br>DESCRIPTION<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setsid() creates a new session if the calling process is not a process group leader.&nbsp; The calling process is the leader of the new session, the process group leader of the new process<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; group, and has no controlling tty.&nbsp; The process group ID and session ID of the calling process are set to the PID of the calling process.&nbsp; The calling process will be the only process<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in this new process group and in this new session.<br><br>&lt;/quote&gt;<br><br><br>Therefore, it appears that setsid() would eventually end up detaching the calling process from the controlling terminal.<br><br>You are in luck. It appears that there is a setsid shell program that does the same thing, but to a new process. <br><br>So you can run nginx in a new session by saying<br><br>setsid /path/to/nginx -c /path/to/nginx/conf<br><br>After that, I daresay you should be OK (though I haven't tried it myself)<br><br><br><br>Thanks<br>Mansoor<br><br><br><br><br>----- Original Message -----<br>From: "Clint Priest" &lt;cpriest@warpmail.net&gt;<br>To: nginx@sysoev.ru<br>Sent: Monday, September 15, 2008 5:49:02 AM GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi<br>Subject: Nginx w/ ssh restart<br><br>I'm having trouble getting nginx to restart via an ssh shell. &nbsp;From a <br>remote machine doing "ssh root@web1 service nginx restart" is causing <br>the ssh shell to not disconnect once nginx restarts.<br><br>I've had similar trouble with my own daemons which I have solved by <br>ensuring all file descriptors are closed before or after the daemon <br>fork. &nbsp;Does nginx do this?<br><br>Any other ideas which would cause nginx to hang the shell?<br><br>Thanks,<br><br>-Clint<br><br></div></div></body></html>