From 5b8f68c132f6df1dc4e1567ade0ab2d1dc8de317 Mon Sep 17 00:00:00 2001 From: pvtroshin Date: Mon, 5 Sep 2011 15:11:23 +0000 Subject: [PATCH] Adding listener for setting executable flag on the web application start up git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4563 e3abac25-378b-4346-85de-24260fe3988d --- WEB-INF/web.xml | 7 +- binaries/src/setexecflag.sh | 2 +- .../compbio/ws/server/SetExecutableFlag.java | 89 ++++++++++++++++++++ 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 webservices/compbio/ws/server/SetExecutableFlag.java diff --git a/WEB-INF/web.xml b/WEB-INF/web.xml index 794c4cb..3bf22cf 100644 --- a/WEB-INF/web.xml +++ b/WEB-INF/web.xml @@ -12,9 +12,12 @@ compbio.stat.servlet.StatisticCollector - + + compbio.ws.server.SetExecutableFlag + + com.sun.xml.ws.transport.http.servlet.WSServletContextListener - + diff --git a/binaries/src/setexecflag.sh b/binaries/src/setexecflag.sh index e4d11a0..aa82b3d 100644 --- a/binaries/src/setexecflag.sh +++ b/binaries/src/setexecflag.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh echo "" echo "Setting executable flag for Clustalw..." diff --git a/webservices/compbio/ws/server/SetExecutableFlag.java b/webservices/compbio/ws/server/SetExecutableFlag.java new file mode 100644 index 0000000..dea7cbe --- /dev/null +++ b/webservices/compbio/ws/server/SetExecutableFlag.java @@ -0,0 +1,89 @@ +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.Util; +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 = Util.getCommand(ExecProvider.Local, Muscle.class); + if (compbio.util.Util.isEmpty(command)) { + command = Util.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 exist + 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."); + } + } +} -- 1.7.10.2