-
Notifications
You must be signed in to change notification settings - Fork 138
Open
Description
I'm trying to do the following: when a request is received, an immediate response 202 should be given, while a long background process is started.
In nginx.conf:
location /do-something {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
# Fastcgi parameters, include the standard ones
include /etc/nginx/fastcgi_params;
# Adjust non standard parameters (SCRIPT_FILENAME)
fastcgi_param SCRIPT_FILENAME /usr/local/bin/do-something.sh;
}
/usr/local/bin/do-something.sh
#!/bin/bash
echo "Status: 202"
echo -e "Content-type: text/plain\n"
echo "Calling child process..."
/usr/local/bin/do-process.sh &
echo "Returned from child process."
exit 0
/usr/local/bin/do-process.sh
#!/bin/bash
echo "Starting child process..."
sleep 10
echo "Child process done."
exit 0
The expected result is that ampersand used in calling do-process.sh should detach the child process, and 202 code should be returned immediately, as when calling /usr/local/bin/do-something.sh from console. But when I make a request via nginx:
curl -i http://127.0.0.1/do-something
the response is not given immediately, but after 10 seconds.
I'm using spawn with config /etc/sysconfig/spawn-fcgi:
FCGI_SOCKET=/var/run/fcgiwrap.socket
FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
FCGI_USER=nginx
FCGI_GROUP=nginx
FCGI_EXTRA_OPTIONS="-M 0770"
OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"
in a CentOS 7 computer.
Is this the right way of calling a process and start a child process without waiting it to finish?
Metadata
Metadata
Assignees
Labels
No labels