Instead of starting the process you want to kill from the exec task (selenium server in your case). Use the exec task to run the script (I used bash, but ruby, python, etc. will work too). this script will run the desired task and repeat the pid. Replace the required path and the executable that you want to run below.
#!bin/bash ./path_to_executable/process_to_run & echo $!
Pay attention to the "&" this puts the process in the background and allows phing to continue building your project. The last line prints a pid, which can then be captured and saved to a file using the phing exec task. To save this pid, add the output parameter to the phing exec task:
<exec command="your_script" spawn="true" output="./pid.txt" />
the output option will save the output of the exec task to the pid.txt file in the current directory. Please note that you may need this file (for the user performing phing) so that it can be read later.
In a separate task, you can read the pid from a file, and then use the exec task to kill the process.
<loadfile property="pid" file="./pid.txt" /> <exec command="kill ${pid}" dir="./" />
Note: in the example above, you may need to add sudo to the kill command (depending on who owns the process and how it was started.
Optional, but worth considering adding a task to delete the pid.txt file. This will prevent any chance of killing the wrong process (based on an obsolete pid). You can also check that the contents of the pid.txt file are correct, because in case of an error, it may contain something other than pid.
Although this may not be the most direct or optimal solution, it really works.
Steve robillard
source share