Index: /trunk/devel/run
===================================================================
--- /trunk/devel/run	(revision 1118)
+++ /trunk/devel/run	(revision 1119)
@@ -1,4 +1,15 @@
 #!/bin/bash
 # this script is for developers only
+stopfpm() {
+	if [[ -f $pidfile ]]; then
+		pid=`cat $pidfile 2>/dev/null || true`
+		if [[ $pid -gt 0 ]]; then
+			echo
+			echo Stopping fpm $pid @ $pidfile
+			kill $pid || true
+		fi
+	fi
+}
+
 set -e
 MAKE=/usr/bin/make
@@ -93,4 +104,16 @@
 esac
 
+case "${args[0]}" in
+fpm)
+	pidfile=devel.pid
+	stopfpm
+	;;
+stopfpm)
+	pidfile=devel.pid
+	stopfpm
+	exit
+	;;
+esac
+
 basename=$(basename $(pwd))
 if echo $basename | grep -- - >/dev/null; then :; else
@@ -112,4 +135,5 @@
 xcachebasename=${basename%%-*}
 xcachesrcdir=../$xcachebasename
+pidfile=../$xcachebasename/devel.pid
 
 case "$type" in
@@ -192,6 +216,7 @@
 		;;
 	fpm)
-		cmd=(./php-fpm -c devel.ini)
-		args=(-y devel.fpm)
+		echo Starting fpm ...
+		cmd=(./php-fpm -c devel.ini -y devel.fpm -g $(readlink -f $pidfile))
+		args=()
 		;;
 	*)
@@ -244,4 +269,16 @@
 
 export XCACHE_SKIP_FCGI_WARNING=1
-echo "${tracer[@]}" "${cmd[@]}" "${args[@]}"
-exec "${tracer[@]}" "${cmd[@]}" "${args[@]}"
+commandLine=("${tracer[@]}" "${cmd[@]}" "${args[@]}")
+
+case "${cmd[0]}" in
+*php-fpm*)
+	stopfpm
+	"${commandLine[@]}"
+	echo -n "Ctrl-C to stop"
+	trap stopfpm SIGINT SIGTERM
+	cat > /dev/null || true
+	;;
+*)
+	exec "${commandLine[@]}"
+	;;
+esac
