Shutting all tasks down for a given Linux User

I like Linux, its speed and reliability are amazing, which is part of the problem, if correctly set-up the servers go for forever before failing, so your initial line of enterprise support tend not to be up to speed with it, which means that if you have a issue or a deployment does not go as planned, you have a mess to untangle and the only person who has rights to the box (you don’t as your the developer), just wants to restart the machine to “please make the nasty none GUI operating system go away”, this is often not something you want to do on a Linux box as they are frequently doing more than one thing, what we want is to just restart the messed up bits

Now in this example we have the same jboss node started twice (actually the first node refused to shutdown via the normal Jboss script, and someone did not check before starting the node back up) ,

Jboss    30341     1  0 13:33 ?        00:00:00 /bin/sh /opt/Jboss/jboss-5.1.0.GA/bin/ -c c -b -Djboss.server.log.dir=/var/opt/log/Jboss/c -Dcom.agcs.jvmRoute=xxxxxxxx
Jboss    30372 30341  6 13:33 ?        00:01:39 /opt/Jboss/jdk1.6.0_18/bin/java -server -Xms512m -Xmx10240M -XX:MaxPermSize=256M -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dg
Jboss    30454     1  0 13:34 ?        00:00:00 /bin/sh /opt/Jboss/jboss-5.1.0.GA/bin/ -c c -b -Djboss.server.log.dir=/var/opt/log/Jboss/c -Dcom.agcs.jvmRoute=xxxxxxxx
Jboss    30485 30454  1 13:34 ?        00:00:23 /opt/Jboss/jdk1.6.0_18/bin/java -server -Xms512m -Xmx10240M -XX:MaxPermSize=256M -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dg

This was got by the following command

> $ ps -fu Jboss

which shows us all the tasks that we started using the Jboss user

if we are at this stage the normal start/stop scripts wont help us, what we want is to kill the processes manually and start a fresh, normally I would identify the spawning tasks and shut them down manually, as in:

> $sudo kill 30372
> $sudo kill 30485

Once that is done you can restart what ever tasks you want in what ever is your normal way, but describing this over the phone is a short cut to hell, so we can use this short but frightening command to do the job for us

> $sudo kill -9 `ps -fu Jboss ' awk '{print $2}' ' sort`

this will go though all the tasks that have been started by the ‘Jboss’ user and kill them in a very nasty and definite way, leaving you with a clean slate.

you can make this more generic (and possibly a bit nicer) by issuing the command while logged in as the user who is running the process (be they Jboss or WebSphere)

> $kill -9 `ps -fu $USER ' awk '{print $2}' ' sort`

this bit

`ps -fu $USER ' awk '{print $2}' ' sort` 

is what actually generates the list of process IDs , you can get very creative if a bit complicated with this bit e.g.

ps -ef' grep java ' grep -v grep ' awk '{print $2}' 

will do the same but for all java tasks on the server, for more examples go Here for ways of identify groups of WebSphere tasks on linux

thus ends my crimes against Linux for the day

Leave a Reply

Your email address will not be published.