Skip to content

Instantly share code, notes, and snippets.

@agentzh agentzh/test.sh
Last active May 12, 2018

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.