Solaris 10 issue with 0.7.10+ builds w/ patch fix

/opt/SunStudioExpress/bin/cc -c -fast -xipo -errwarn=%all -g -I
src/core -I src/event -I src/event/modules -I src/os/unix -I …/pcre-7.6
-I objs
-o objs/src/os/unix/ngx_alloc.o
src/os/unix/ngx_alloc.c src/os/unix/ngx_sunpro_x86.il
“src/os/unix/ngx_alloc.c”, line 55: warning: implicit function
declaration: posix_memalign
cc: acomp failed for src/os/unix/ngx_alloc.c
gmake[1]: *** [objs/src/os/unix/ngx_alloc.o] Error 2
gmake[1]: *** Waiting for unfinished jobs…
gmake[1]: Leaving directory `/opt/extra/work/nginx-0.7.16’
gmake: *** [build] Error 2

Patch fix.

diff -ur src/os/unix/ngx_alloc.c

…/nginx-0.7.16-patched/src/os/unix/ngx_alloc.c
— src/os/unix/ngx_alloc.c Mon Nov 20 00:51:45 2006
+++ …/nginx-0.7.16-patched/src/os/unix/ngx_alloc.c Tue Sep 9 00:23:59
2008
@@ -45,32 +45,11 @@
}

Don’t use the POSIX_MEMALIGN function on solaris. Just my little hack to
get nginx working correctly on Indiana.

-#if (NGX_HAVE_POSIX_MEMALIGN)

void *
ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
{
void *p;

  • if (posix_memalign(&p, alignment, size) == -1) {
  •    ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
    
  •                  "posix_memalign() %uz bytes aligned to %uz
    

failed",

  •                  size, alignment);
    
  • }
  • ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
  •               "posix_memalign: %p:%uz", p, size);
    
  • return p;
    -}

-#elif (NGX_HAVE_MEMALIGN)

-void *
-ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
-{

  • void *p;
  • p = memalign(alignment, size);
    if (p == NULL) {
    ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
    @@ -84,4 +63,3 @@
    return p;
    }

-#endif

On Thu, Sep 11, 2008 at 12:13:15AM +0200, Victor I. wrote:

gmake[1]: Leaving directory `/opt/extra/work/nginx-0.7.16’
gmake: *** [build] Error 2

Don’t use the POSIX_MEMALIGN function on solaris. Just my little hack to
get nginx working correctly on Indiana.

What does ./configure show ?

On OpenSolaris 2008.05 it shows:

checking for posix_memalign() … not found
checking for memalign() … found

Igor S. wrote:

On Thu, Sep 11, 2008 at 12:13:15AM +0200, Victor I. wrote:

gmake[1]: Leaving directory `/opt/extra/work/nginx-0.7.16’
gmake: *** [build] Error 2

Don’t use the POSIX_MEMALIGN function on solaris. Just my little hack to
get nginx working correctly on Indiana.

What does ./configure show ?

On OpenSolaris 2008.05 it shows:

checking for posix_memalign() … not found
checking for memalign() … found

checking for posix_memalign() … found
checking for memalign() … found

Igor S. wrote:

On Fri, Sep 12, 2008 at 12:52:53AM +0200, Victor I. wrote:

On OpenSolaris 2008.05 it shows:

checking for posix_memalign() … not found
checking for memalign() … found

checking for posix_memalign() … found
checking for memalign() … found

What does

grep memalign /usr/include/stdlib.h

show ?

Included Sun Express Studio headers as well, which don’t have any
memalign functions.

grep memalign /usr/include/stdlib.h

extern void *memalign(size_t, size_t);
extern void *memalign();

grep memalign /opt/SunStudioExpress/prod/include/CC/stlport4/stdlib.h

grep memalign

/opt/SunStudioExpress/prod/include/CC/stlport4/stdlib.h.SUNWCCh

I’m having trouble getting nginx to restart via an ssh shell. From a
remote machine doing “ssh root@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

On Fri, Sep 12, 2008 at 12:52:53AM +0200, Victor I. wrote:

On OpenSolaris 2008.05 it shows:

checking for posix_memalign() … not found
checking for memalign() … found

checking for posix_memalign() … found
checking for memalign() … found

What does

grep memalign /usr/include/stdlib.h

show ?

On Sun, Sep 14, 2008 at 07:19:02PM -0500, Clint P. wrote:

I’m having trouble getting nginx to restart via an ssh shell. From a
remote machine doing “ssh root@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?

During daemon fork nginx does not close at least listen sockets and log
files.
Otherwise it will can not work. However, I think it should not hang a
shell.

Do you use “daemon off” in nginx.conf ?

On Tue, Sep 16, 2008 at 02:21:37AM +0200, Victor I. wrote:

So anything?

I still have no idea how configure had found posix_memalign().
Could you send a whole ./configure output ?

So anything?

Victor I. wrote:

Included Sun Express Studio headers as well, which don’t have any
memalign functions.

grep memalign /usr/include/stdlib.h

extern void *memalign(size_t, size_t);
extern void *memalign();

grep memalign /opt/SunStudioExpress/prod/include/CC/stlport4/stdlib.h

grep memalign

/opt/SunStudioExpress/prod/include/CC/stlport4/stdlib.h.SUNWCCh

No, I don't have it set either way.š I just tried setting it to on, same effect.

What happens on your end trying to restart via ssh remotely?

Igor S. wrote:
On Sun, Sep 14, 2008 at 07:19:02PM -0500, Clint P. 
wrote:
  
I'm having trouble getting nginx to restart via an ssh 
shell.  From a
remote machine doing "ssh root@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?

During daemon fork nginx does not close at least listen sockets and log 
files.
Otherwise it will can not work. However, I think it should not hang a 
shell.

Do you use “daemon off” in nginx.conf ?

Too ironic that your address is @warpmail.net :wink:

On Tue, Sep 16, 2008 at 11:17:14PM -0500, Clint P. wrote:

No, I don’t have it set either way. I just tried setting it to on,
same effect.
What happens on your end trying to restart via ssh remotely?

I usually do not use restart (as stop/start sequence), because graceful
reconfiguration using -HUP or online binary upgrade are enough.

On fresh servers I start nginx using:
/usr/local/nginx/nginx
or
/usr/local/etc/rc.d/nginx.sh start
This is always run via ssh and I never saw any ssh issues.
Just tried to start using
ssh root@host /usr/local/etc/rc.d/nginx.sh start
without any problems.

The problem is probably in “service” utility. What is it ?

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:

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.

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 P.” [email protected]
To: [email protected]
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@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

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 P.” [email protected]
To: [email protected]
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:

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.

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 P.” [email protected]
To: [email protected]
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@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

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

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 S.
http://sysoev.ru/en/

On Tue, Sep 16, 2008 at 10:35 PM, Igor S. [email protected] wrote:

The problem is probably in “service” utility. What is it ?

redhat style init

i install nginx on redhat using this:

cp /usr/src/build/extras/nginx.initd /etc/init.d/nginx
/sbin/chkconfig --add nginx

then ‘service’ works properly

this is the nginx.initd script:

#!/bin/sh

Init file for nginx

chkconfig: 2345 55 25

description: Nginx web server

processname: nginx

config: /usr/local/nginx/nginx.conf

pidfile: /usr/local/nginx/nginx.pid

Description: Startup script for nginx webserver on Debian. Place in

/etc/init.d and

run ‘sudo update-rc.d nginx defaults’, or use the appropriate command

on your

distro. For CentOS/Redhat run: ‘/sbin/chkconfig --add nginx’

Author: Ryan N. [email protected]

Modified: Geoffrey Grosenbach http://topfunky.com

Modified: David K. http://davidhq.com

Modified: Vishnu G. http://vish.in

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC=“nginx daemon”
NAME=nginx
DAEMON=/usr/sbin/nginx
CONFIGFILE=/etc/nginx/nginx.conf
PIDFILE=/var/run/nginx.pid
SCRIPTNAME=/etc/init.d/nginx

Gracefully exit if the package has been removed.

test -x $DAEMON || exit 0

d_start() {
$DAEMON -c $CONFIGFILE || echo -en “\n already running”
}

d_stop() {
kill -QUIT cat $PIDFILE || echo -en “\n not running”
}

d_reload() {
kill -HUP cat $PIDFILE || echo -en “\n can’t reload”
}

case “$1” in
start)
echo -n “Starting $DESC: $NAME”
d_start
echo “.”
;;
stop)
echo -n “Stopping $DESC: $NAME”
d_stop
echo “.”
;;
reload)
echo -n “Reloading $DESC configuration…”
d_reload
echo “.”
;;
restart)
echo -n “Restarting $DESC: $NAME”
d_stop
# One second might not be time enough for a daemon to stop,
# if this happens, d_start will fail (and dpkg will break if
# the package is being upgraded). Change the timeout if needed
# be, or change d_stop to have start-stop-daemon use --retry.
# Notice that using --retry slows down the shutdown process
somewhat.
sleep 1
d_start
echo “.”
;;
*)
echo “Usage: $SCRIPTNAME {start|stop|restart|reload}” >&2
exit 3
;;
esac

exit 0

On Wed, Sep 17, 2008 at 10:42:19AM +0400, Igor S. wrote:

cp /usr/src/build/extras/nginx.initd /etc/init.d/nginx

chkconfig: 2345 55 25

DAEMON=/usr/sbin/nginx

echo -n "Starting $DESC: $NAME"
d_reload
sleep 1
d_start
echo "."

BTW, this restart may not work, because -QUIT is a graceful exit, and
it may hang for long time, and new nginx will can not bind to listen sockets.
It should be changed to somethig like this:

  echo -n "Restarting $DESC: $NAME"
  • d_stop
    
  • kill `cat $PIDFILE` || echo -en "\n not running"
    

I’m wrong, -QUIT should work in this case, because upon the -QUIT signal
reception a master and worker processes close listening sockets and this
allows a new master process to bind them. So existant d_stop is better
then
-TERM signal.

On Tue, Sep 16, 2008 at 11:51 PM, Igor S. [email protected] wrote:

I’m wrong, -QUIT should work in this case, because upon the -QUIT signal
reception a master and worker processes close listening sockets and this
allows a new master process to bind them. So existant d_stop is better then
-TERM signal.

Thanks for investigating, either way :slight_smile:

I actually am not sure where I got the init script, either. But it’s
been working great and I’ve included it as part of my build process (I
have a similar one for Ubuntu)

On Tue, Sep 16, 2008 at 11:29:36PM -0700, mike wrote:

Modified: Geoffrey Grosenbach http://topfunky.com

PIDFILE=/var/run/nginx.pid
kill -QUIT cat $PIDFILE || echo -en “\n not running”
echo “.”
;;
echo “.”
BTW, this restart may not work, because -QUIT is a graceful exit, and
it may hang for long time, and new nginx will can not bind to listen
sockets.
It should be changed to somethig like this:

  echo -n "Restarting $DESC: $NAME"
  • d_stop
    
  • kill `cat $PIDFILE` || echo -en "\n not running"
    
I ended up writing my own debian init.d script which also included spawn-fcgi which apparently is what's causing the problem, commenting out the start lines for that and there's no problem via ssh.

Is there an official debian start init.d script somewhere?

Igor S. wrote:
On Tue, Sep 16, 2008 at 11:17:14PM -0500, Clint P. 
wrote:
  
   No, I don't have it set either way.  I just tried 
setting it to on,
   same effect.
   What happens on your end trying to restart via ssh remotely?
    
I usually do not use restart (as stop/start sequence), because graceful
reconfiguration using -HUP or online binary upgrade are enough.

On fresh servers I start nginx using:
/usr/local/nginx/nginx
or
/usr/local/etc/rc.d/nginx.sh start
This is always run via ssh and I never saw any ssh issues.
Just tried to start using
ssh root@host /usr/local/etc/rc.d/nginx.sh start
without any problems.

The problem is probably in “service” utility. What is it ?

   Igor S. wrote:

On Sun, Sep 14, 2008 at 07:19:02PM -0500, Clint P. wrote:

I’m having trouble getting nginx to restart via an ssh shell. From a
remote machine doing “ssh root@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?

During daemon fork nginx does not close at least listen sockets and log
files.
Otherwise it will can not work. However, I think it should not hang a
shell.

Do you use “daemon off” in nginx.conf ?

</pre>