SYSXPERTS Blog

Linux fundamentalist, Virtualization beadsman, and Storage agnostic

  • Subscribe

  • Blog Archives

  • Twitter

Prepare a shared cifs mount for JBoss deploy

Posted by sysxperts on June 1, 2010

PROBLEM: An application is failing to deploy files to a cifs share mounted on linux because users have files open which the deployment process is trying to overwrite.

SOLUTION: Needed to kill all processes for user accounts with open files in the /data cifs mount other than my deployment and root user accounts.

for i in `fuser -u -v /data 2>&1 |grep -v root|grep -v deploy|awk ‘$2 !~ /[a-z]/’`; do kill -9 $i; done

The “fuser -u -v /data 2>&1 |grep -v root|grep -v deploy” portion of command finds all processes with open files on /data for all users other than root and deploy. Note that the “2>&1” was used because fuser was generating some output to stderr and other to stdout so I combined them by sending stderr to stdout to allow grep to work as desired in this case.

The “awk ‘$2 !~ /[a-z]/'” portion simply removes the PID and any alpha character lines from output and prints all the resulting numeric PID’s each on it’s own line from the fuser command.

Finally “do kill -9 $i” kills all the PID’s returned from command above without prejudice, so beware, goodbye – gone – finito to them all!

I would not want to do this against files which I would want to keep! This should only be done for files that will be deleted or replaced anyway since the integrity of the files after running this command cannot be guaranteed in any way. At a minimum a full backup and verification should be performed prior testing.

An even safer version of the command above would target specific files or subdirectories to prevent killing processes unrelated to the deploy. For example, instead of /data as above you might run multiple commands with each specific file passed to fuser such as /data/file1 for the first iteration and so on through /data/filex.

To perform as a regular user you can update sudo by adding something like the following to /etc/sudoers:

%deploy ALL = NOPASSWD: /sbin/fuser -u -v /data

Then update the above command as follows to run as your deploy(regular) user:

for i in `sudo /sbin/fuser -u -v /data 2>&1 |grep -v root|grep -v deploy|awk ‘$2 !~ /[a-z]/ {print $2}’`; do kill -9 $i; done

Leave a comment