github.com/mackerelio/mackerel-agent-plugins@v0.89.3/mackerel-plugin-php-fpm/testdata/tests.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  if ! which -s php-fpm
     4  then
     5  	echo "$(basename $0): php-fpm not found" >&2
     6  	exit 2
     7  fi
     8  
     9  run_plugin()
    10  {
    11  	sleep 1
    12  	go run ../main.go "$@"
    13  	sleep 1
    14  }
    15  
    16  d=$(mktemp -d -t mackerel-plugin-php-fpm)
    17  cleanup()
    18  {
    19  	local status=$?
    20  	rm -rf $d
    21  	pkill php-fpm
    22  	exit $status
    23  }
    24  trap cleanup HUP INT QUIT TERM EXIT
    25  
    26  #
    27  # tests
    28  #
    29  sock_tcp=tcp://localhost:9000
    30  sock_unix=unix:///tmp/php-fpm.sock
    31  protocols=(tcp unix)
    32  for proto in "${protocols[@]}"
    33  do
    34  	pidfile=$d/php-fpm.$proto.pid
    35  	mkfifo $pidfile
    36  	php-fpm -y php-fpm.$proto.conf -g $pidfile -D
    37  	pid=$(cat $pidfile)
    38  	sock=sock_$proto
    39  	run_plugin -socket "${!sock}" -url 'http://localhost:9000/status?json'
    40  	kill $pid
    41  	while ps -p $pid >/dev/null
    42  	do
    43  		sleep 1
    44  	done
    45  done