1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
package compbio.ws.server;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import compbio.engine.client.Executable.ExecProvider;
import compbio.engine.client.EngineUtil;
import compbio.engine.conf.PropertyHelperManager;
import compbio.runner.disorder.IUPred;
import compbio.runner.msa.Muscle;
import compbio.util.SysPrefs;
/**
* Run setexecflag.sh script if executable flag is not set
*
* @author pvtroshin
*
*/
public class SetExecutableFlag implements ServletContextListener {
private final Logger log = Logger.getLogger(SetExecutableFlag.class);
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// do nothing
}
/**
* This listener is designed to run only once when the web application is
* deployed to set executable flag for binaries.
*
* @param arg0
* - ignored
*/
@Override
public void contextInitialized(ServletContextEvent arg0) {
// Assume at least one of these is configured
// Do not even bother with cluster execution, sysadmins set the flag
// themselves
String command = EngineUtil.getCommand(ExecProvider.Local, Muscle.class);
if (compbio.util.Util.isEmpty(command)) {
command = EngineUtil.getCommand(ExecProvider.Local, IUPred.class);
}
boolean isExec = true;
if (!compbio.util.Util.isEmpty(command)) {
File file = new File(command);
isExec = file.canExecute();
}
String workDir = PropertyHelperManager.getLocalPath() + "binaries/src";
String script = "setexecflag.sh";
// Run only one once if not on Windows
if (!SysPrefs.isWindows && !isExec) {
// verify script exists
File scriptFile = new File(workDir, script);
if (!scriptFile.exists()) {
log.debug("Setexecflag.sh script is NOT found in " + scriptFile.getAbsolutePath());
return;
} else {
scriptFile.setExecutable(true);
log.debug("Setexecflag.sh script is found");
}
try {
log.debug("Executable flag is NOT set for the binaries - attemping to set it");
ProcessBuilder pb = new ProcessBuilder(scriptFile.getAbsolutePath());
pb.directory(new File(workDir));
Process process = pb.start();
process.waitFor();
process.destroy();
} catch (IOException e) {
log.debug("Failed to execute set executable flag script due to IOException! Please run it manually!");
log.debug(e.getMessage(), e);
} catch (InterruptedException e) {
log.debug("Failed to execute set executable flag script due to Interruption! Please run it manually!");
}
} else {
log.debug("Executable flag is already set for the binaries.");
}
}
}
|