Nginx w/ ssh restart

Igor Sysoev is at rambler-co.ru
Wed Sep 17 10:22:00 MSD 2008


On Tue, Sep 16, 2008 at 11:17:43PM -0700, Mansoor Peerbhoy wrote:

> 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) 

nginx calls setsid() in a daemonized process.

-- 
Igor Sysoev
http://sysoev.ru/en/

> ----- 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 





More information about the nginx mailing list