Reputation: 8783
I am using a Jenkins job to run a few simple shell commands (over ssh, via the Jenkins SSH Plugin); the commands are supposed to shut down a running Tomcat server:
sudo /opt/tomcat/bin/catalina.sh stop
ps xu | awk '/[t]omcat/{print $2}' | xargs -r kill -9
The job executes fine and does terminate the Tomcat, but unfortunately it also fails; the full output is:
[SSH] executing pre build script:
sudo /opt/tomcat/bin/catalina.sh stop
ps xu | awk '/[t]omcat/{print $2}' | xargs kill -9
[SSH] exit-status: -1
Finished: FAILURE
Any idea why the exit code of the command if -1? I have tried several variations without any luck.
Thanks.
Upvotes: 1
Views: 3709
Reputation: 158
The questions is a bit old but as I stumbled upon that, here's another suggestion.
ps xu | awk '/[t]omcat/{print $2}'
returns the running tomcat AND the awk process itself, see here
<user> 2370 0.0 0.0 26144 1440 pts/7 R+ 10:51 0:00 awk /[t]omcat/{print $2}
The awk process instantly ends itself before running xargs on it, so one of the xargs has an exit code unequal 0.
Try running killall tomcat
Upvotes: 1
Reputation: 4593
I suspect that Jenkins doesn't like the no process killed
that the kill command prints of it doesn't run. Try redirecting stdout to /dev/null.
Upvotes: 1
Reputation: 3624
You should examine the output of ps xu
. Since kill
will kill the processes sequentially, it may be the case that if there are multiple tomcat
processes yielded by ps xu
, the other ones will automatically terminate after the first one is terminated. Then kill
attempts to terminate processes that no longer exist.
Upvotes: 1