Is it possible to change a PID in Supervisord - nginx

I have a /bin/NginxWrapper script that runs NGINX:
#!/bin/env sh
export LD_LIBRARY_PATH=$ENVIRONMENT_ROOT/lib/:$LD_LIBRARY_PATH
/bin/nginx
Supervisord config command points the above script, so that when we kick off Nginx, supervisor will first call this script
[program:nginx]
command=/bin/NginxWrapper -c /nginx/nginx.conf -g "daemon off;"
The problem is, Superisord is now storing the PID of this script, instead of the PID of Nginx. And if i try to send HUP to Nginx, its unable to.
Is it possible to change the PID in supervisord so that it's Nginx's PID?
OR
Is there a way to chain Supersivord command so that i dont need the wrapper, and can just chain something like
[program:nginx]
command= export LD_LIBRARY_PATH=$ENVIRONMENT_ROOT/lib/:$LD_LIBRARY_PATH && /bin/NginxWrapper -c /nginx/nginx.conf -g "daemon off;"
Many thanks...

Change
/bin/nginx
to
exec /bin/nginx

Related

What is the difference between the presence and absence of the -g option in nginx?

https://en.wikipedia.org/wiki/Debug_symbol
When running nginx on the docker, I was curious about -g option.
CMD ["nginx", "-g", "daemon off;"]
Searching wikipedia, it is so hard for me.
-g option, can I use new commands? or Is there any other difference?
Plz, Tell me. Thanks! :D
The -g option of NGINX is used for specifying NGINX flags, daemon off in this case.
It has nothing to do with GCC's -g option or the mentioned Wikipedia link.
For NGINX command line options, see:
https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
For explanation about the daemon off setting:
What is the difference between nginx daemon on/off option?

starting nginx -g 'daemon off;' from a script does not stay in front

I am trying to start nginx from a script and want to see it running in foreground.
It is already running when I run the script. Therefore I am trying with the following:
nginx -s stop
sleep 5
nginx -g 'daemon off;'
The problem is that it still runs as a deamon - not in the foreground. And it ends the process?

Restarting nginx: nginxnginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

When I try to restart nginx with sudo /etc/init.d/nginx restart I get the message from the subject.
I discovered that the reason is most likely that the script doesn't know how to stop the deamon because the pid file (/var/run/nginx.pid) is not created on start.
I have two installations on two different servers... one was compiled from source and the other came with phusion passenger.
I tried this command:
start-stop-daemon --start --quiet --pidfile /var/run/nginx.pid --exec /usr/sbin/nginx -- -c /etc/nginx/nginx.conf
on both machines and on one the pid file is created and on the other it is not - on that machine the paths are a bit different (but I don't think this is relevant):
start-stop-daemon --start --quiet --pidfile /var/run/nginx.pid --exec /opt/nginx/sbin/nginx -- -c /opt/nginx/conf/nginx.conf
The process starts and pid is not written...
I'm on Debian...
Any suggestions?
The solution is to uncomment this line in nginx.conf:
pid /var/run/nginx.pid;
It looks like different installations do it differently but the right thing is to uncomment it.
I was able to fix this by running the following fuser command
$ sudo fuser -k 80/tcp
which kills whatever process is using port 80..hopefully didn't screw anything else.
Credit for this goes to:
https://goo.gl/6oc0xD
$ sudo nginx -t
to see all processes, sometimes you do not have the full permission

Nginx pid keeps changing every few second after killing the master process

I'm using the following Upstart script to keep Nginx up and running on Ubuntu server:
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/usr/sbin/nginx
env CONF=/etc/nginx/nginx.conf
respawn
respawn limit 10 5
pre-start script
$DAEMON -t
if [ $? -ne 0 ]; then
exit $?
fi
end script
exec $DAEMON -c $CONF -g "daemon off;" > /dev/null 2>&1
This script works fine except when I'm killing the Nginx master process using the kill command. After killing the master process /var/run/nginx.pid remains the same but Nginx pid keeps changing every few seconds (this means Nginx is restarting all the time?). Any idea how to fix this?

How to gracefully reload a spawn-fcgi script for nginx

My stack is nginx that runs python web.py fast-cgi scripts using spawn-fcgi. I am using runit to keep the process alive as a Daemon. I am using unix sockets fior the spawed-fcgi.
The below is my runit script called myserver in /etc/sv/myserver with the run file in /etc/sv/myserver/run.
exec spawn-fcgi -n -d /home/ubuntu/Servers/rtbTest/ -s /tmp/nginx9002.socket -u www-data -f /home/ubuntu/Servers/rtbTest/index.py >> /var/log/mylog.sys.log 2>&1
I need to push changes to the sripts to the production servers. I use paramiko to ssh into the box and update the index.py script.
My question is this, how do I gracefully reload the index.py using best practice to update to the new code.
Do I use:
sudo /etc/init.d/nginx reload
Do I restart the the runit script:
sudo sv start myserver
Or do I use both:
sudo /etc/init.d/nginx reload
sudo sv start myserver
Or none of the above?
Basically you have to re-start the process that's loaded your Python script. This is spawn-cgi and not nginx itself. nginx only communicates with spawn-cgi via the Unix socket and will happily re-connect if the connection is lost due to a restart of the spawn-cgi process.
Therefore I'd suggest a simple sudo sv restart myserver. No need to re-start/re-load nginx itself.

Resources