Last active
May 12, 2018 21:47
-
-
Save agentzh/2baa7619f49699f144ca02488dd62850 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export PATH=/opt/gdb-git/bin:$PATH | |
gdb --version | |
count=200 | |
pidfile=logs/nginx.pid | |
port=8081 | |
mkdir -p conf logs || exit 1 | |
cat << EOF > conf/nginx.conf | |
daemon on; | |
master_process on; | |
worker_processes 2; | |
pid $pidfile; | |
events { | |
accept_mutex off; | |
worker_connections 1024; | |
} | |
http { | |
server { | |
listen 127.0.0.1:$port reuseport; | |
location / { | |
return 200 "test\\n"; | |
} | |
} | |
} | |
EOF | |
if [ -f $pidfile ]; then | |
pid=`cat logs/nginx.pid` | |
if [ -n "$pid" ]; then | |
kill -QUIT $pid; | |
sleep 0.2 | |
fi | |
fi | |
nginx -p $PWD/ -c conf/nginx.conf || exit 1 | |
sleep 0.2 | |
pid=`cat $pidfile` | |
if [ -z "$pid" ]; then | |
sleep 1 | |
pid=`cat $pidfile` | |
if [ -z "$pid" ]; then | |
echo "failed to get pid from $pidfile" > /dev/stderr | |
exit 1 | |
fi | |
fi | |
out=`pgrep -P $pid` | |
if [ -z "$out" ]; then | |
echo "failed to get nginx worker processes under pid $pid" > /dev/stderr | |
exit 1 | |
fi | |
pids=(${out// / }) | |
pid0=${pids[0]} | |
pid1=${pids[1]} | |
echo "pid 0: $pid0" | |
echo "pid 1: $pid1" | |
gdb --nx --batch \ | |
-ex 'set schedule-multiple on' \ | |
-ex 'set non-stop on' \ | |
-ex "attach $pid0" \ | |
-ex add-inferior \ | |
-ex 'inferior 2' \ | |
-ex "attach $pid1" \ | |
-ex 'i inferiors' \ | |
-ex 'b ngx_http_handler' \ | |
-ex 'continue -a' \ | |
-ex 'delete' \ | |
-ex quit & | |
gdb_pid=$! | |
#echo "HERE:" > /dev/stderr | |
ps aux|grep nginx | |
sleep 1 | |
echo sending SIGINT to gdb process $gdb_pid ... | |
kill -s SIGINT $gdb_pid || exit 1 | |
for i in $(seq 1 $count); do | |
curl -Ss http://127.0.0.1:$port/ > /dev/null \ | |
|| { echo $i; ps aux|grep nginx; exit 1; } | |
done | |
echo success! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment