I encountered a problem that I don't known how to debug a FCGI program which written in C++ and based on fastcgi.
The program is managed by Lighttpd spawn-fcgi and called by nginx fastcgi module.
I wrote a shell script to restart spawn-cgi:
#! /bin/bash
cgi_default="index.cgi"
process_pid="pid"
param_ip="127.0.0.1"
param_port="9000"
if [ -f "$process_pid" ]; then
pid=`cat $process_pid`
kill -9 $pid &> /dev/null
rm $process_pid
fi
spawn_out=`/usr/local/bin/spawn-fcgi -a $param_ip -p $param_port $cgi_default`
# spawn-fcgi: child spawned successfully: PID: 6423
pid=`echo $spawn_out | cut -d " " -f6`
expr $pid + 0 &> /dev/null
[ $? -eq "0" ] && echo "$pid" > $process_pid
The program index.cgi was successfully built and just printf some strings to out stream.
And my configuration in nginx:
location / {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
Now I am wroking on index.cgi, change some code (maybe with faulty logic). The program crashed and 502 Bad Gateway was returned in my browser.
It's hard for me to find out what is wrong in my program because the fcgi progam acts as a callback function of nginx. So I cannot press Debug button and bebug my program normally.
So how can I debug my program properly and conveniently?