# HG changeset patch # User Jie Kang # Date 1482265558 18000 # Node ID e4e0f9654a044fcebfc9f9c03afce4b47f24ca85 # Parent 89807d0b1dfedd3ebe56f268b9aa3b762cd0d395 Make built thermostat image portable Backport of: http://icedtea.classpath.org/hg/thermostat/rev/e635014e3559 PR3238 Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-December/021885.html diff -r 89807d0b1dfe -r e4e0f9654a04 README --- a/README Tue Dec 20 15:24:46 2016 -0500 +++ b/README Tue Dec 20 15:25:58 2016 -0500 @@ -106,13 +106,14 @@ The resulting Thermostat system can now be found under the directory distribution/target/image. - Please note that the resulting build is non-relocatable. If you move it to - some other directory, it will not work. Use the thermostat.home maven - property to set that at build time: + If you want to install thermostat to a system location, use the + thermostat.home maven property to set that at build time: mvn -Dthermostat.home=/path/to/install/thermostat - You will have to move the resulting build to the path manually. + You will have to move the resulting build to the path manually. This property + sets up mostly distribution related files (for services) that need the full + path to Thermostat. It is not required to run thermostat normally. -------------------------------------------------------------------------------- 3. RUNNING THERMOSTAT diff -r 89807d0b1dfe -r e4e0f9654a04 config/src/main/java/com/redhat/thermostat/shared/config/internal/CommonPathsImpl.java --- a/config/src/main/java/com/redhat/thermostat/shared/config/internal/CommonPathsImpl.java Tue Dec 20 15:24:46 2016 -0500 +++ b/config/src/main/java/com/redhat/thermostat/shared/config/internal/CommonPathsImpl.java Tue Dec 20 15:25:58 2016 -0500 @@ -107,16 +107,28 @@ private CommonPathsImpl(File defaultPrefix) { CommonPathsImpl.defaultSystemUserPrefix = defaultPrefix; + + // When THERMOSTAT_HOME is fetched from env, write back the results to + // System properties too so other parts of thermostat (specially the web + // bits) make use of the right THERMOSTAT_HOME + boolean homeFetchedFromEnv = false; + // allow this to be specified also as a property, especially for // tests, this overrides the env setting String home = System.getProperty(THERMOSTAT_HOME); if (home == null) { + homeFetchedFromEnv = true; home = System.getenv(THERMOSTAT_HOME); } if (home == null) { throw new InvalidConfigurationException(t.localize(LocaleResources.SYSHOME_NO_HOME)); } + + if (homeFetchedFromEnv) { + System.setProperty(THERMOSTAT_HOME, home); + } + this.systemHome = new File(home); if (!systemHome.exists()) { throw new InvalidConfigurationException(t.localize(LocaleResources.SYSHOME_DOESNT_EXIST, home)); diff -r 89807d0b1dfe -r e4e0f9654a04 distribution/pom.xml --- a/distribution/pom.xml Tue Dec 20 15:24:46 2016 -0500 +++ b/distribution/pom.xml Tue Dec 20 15:25:58 2016 -0500 @@ -256,6 +256,7 @@ + diff -r 89807d0b1dfe -r e4e0f9654a04 distribution/scripts/thermostat --- a/distribution/scripts/thermostat Tue Dec 20 15:24:46 2016 -0500 +++ b/distribution/scripts/thermostat Tue Dec 20 15:25:58 2016 -0500 @@ -36,8 +36,11 @@ # ##################################################################### +# Source thermostat-functions from same directory as this script +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/thermostat-functions + if [ x"${THERMOSTAT_HOME}" = x ]; then - THERMOSTAT_HOME="@thermostat.home@" + THERMOSTAT_HOME=$(_find_thermostat_home) export THERMOSTAT_HOME fi if [ x"${USER_THERMOSTAT_HOME}" = x ]; then diff -r 89807d0b1dfe -r e4e0f9654a04 distribution/scripts/thermostat-agent-proxy --- a/distribution/scripts/thermostat-agent-proxy Tue Dec 20 15:24:46 2016 -0500 +++ b/distribution/scripts/thermostat-agent-proxy Tue Dec 20 15:25:58 2016 -0500 @@ -44,8 +44,11 @@ echo "usage: $0 " >&2 fi +# Source thermostat-functions from same directory as this script +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/thermostat-functions + if [ x"$THERMOSTAT_INSTALL_DIR" = x ] ; then - THERMOSTAT_INSTALL_DIR="@thermostat.home@" + THERMOSTAT_INSTALL_DIR=$(_find_thermostat_home) fi # Not always are installation directory and thermostat home one and # the same location. diff -r 89807d0b1dfe -r e4e0f9654a04 distribution/scripts/thermostat-agent-sysd --- a/distribution/scripts/thermostat-agent-sysd Tue Dec 20 15:24:46 2016 -0500 +++ b/distribution/scripts/thermostat-agent-sysd Tue Dec 20 15:25:58 2016 -0500 @@ -44,8 +44,11 @@ exit 1 fi +# Source thermostat-functions from same directory as this script +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/thermostat-functions + if [ x"$THERMOSTAT_HOME" = x ] ; then - THERMOSTAT_HOME="@thermostat.home@" + THERMOSTAT_HOME=$(_find_thermostat_home) fi export THERMOSTAT_HOME diff -r 89807d0b1dfe -r e4e0f9654a04 distribution/scripts/thermostat-debug --- a/distribution/scripts/thermostat-debug Tue Dec 20 15:24:46 2016 -0500 +++ b/distribution/scripts/thermostat-debug Tue Dec 20 15:25:58 2016 -0500 @@ -37,8 +37,12 @@ ##################################################################### # # Some necessary variables. + +# Source thermostat-functions from same directory as this script +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/thermostat-functions + if [ x"$THERMOSTAT_HOME" = x ] ; then - THERMOSTAT_HOME="@thermostat.home@" + THERMOSTAT_HOME=$(_find_thermostat_home) fi export THERMOSTAT_HOME diff -r 89807d0b1dfe -r e4e0f9654a04 distribution/scripts/thermostat-devsetup --- a/distribution/scripts/thermostat-devsetup Tue Dec 20 15:24:46 2016 -0500 +++ b/distribution/scripts/thermostat-devsetup Tue Dec 20 15:25:58 2016 -0500 @@ -43,8 +43,11 @@ # file devsetup.input and then copies an appropriate agent.auth # file into the right place. +# Source thermostat-functions from same directory as this script +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/thermostat-functions + if [ "x$THERMOSTAT_HOME" == "x" ]; then - THERMOSTAT_HOME="@thermostat.home@" + THERMOSTAT_HOME=$(_find_thermostat_home) fi THERMOSTAT_SETUP="$THERMOSTAT_HOME/bin/thermostat-setup" DEV_INPUT="$THERMOSTAT_HOME/etc/devsetup.input" diff -r 89807d0b1dfe -r e4e0f9654a04 distribution/scripts/thermostat-setup --- a/distribution/scripts/thermostat-setup Tue Dec 20 15:24:46 2016 -0500 +++ b/distribution/scripts/thermostat-setup Tue Dec 20 15:25:58 2016 -0500 @@ -35,15 +35,10 @@ # to do so, delete this exception statement from your version. # ##################################################################### -if [ x"$THERMOSTAT_INSTALL_DIR" = x ] ; then - THERMOSTAT_INSTALL_DIR="@thermostat.home@" -fi -# Not always are installation directory and thermostat home one and -# the same location. -if [ x"$THERMOSTAT_HOME" = x ] ; then - THERMOSTAT_HOME=${THERMOSTAT_INSTALL_DIR} - export THERMOSTAT_HOME -fi + +# Source thermostat-functions from same directory as this script +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/thermostat-functions + echo "THIS SCRIPT IS DEPRECATED! Please use 'thermostat setup -c' instead." 1>&2 # Call the thermostat non-gui version of setup ${THERMOSTAT_HOME}/bin/thermostat setup -c diff -r 89807d0b1dfe -r e4e0f9654a04 web/server/src/main/java/com/redhat/thermostat/web/server/PropertySettingServletContextListener.java --- a/web/server/src/main/java/com/redhat/thermostat/web/server/PropertySettingServletContextListener.java Tue Dec 20 15:24:46 2016 -0500 +++ b/web/server/src/main/java/com/redhat/thermostat/web/server/PropertySettingServletContextListener.java Tue Dec 20 15:25:58 2016 -0500 @@ -44,7 +44,8 @@ /** * Sets the THERMOSTAT_HOME system property as * configured via said context-param in web.xml. - * + *

+ * Does not set THERMOSTAT_HOME if the system property is already defined. */ public class PropertySettingServletContextListener implements ServletContextListener { @@ -54,7 +55,9 @@ @Override public void contextInitialized(ServletContextEvent sce) { String thermostatHome = sce.getServletContext().getInitParameter(PROPERTY_NAME); - System.setProperty(PROPERTY_NAME, thermostatHome); + if (System.getProperty(PROPERTY_NAME) == null) { + System.setProperty(PROPERTY_NAME, thermostatHome); + } System.setProperty(Constants.IS_PROXIED_STORAGE, Boolean.TRUE.toString()); } diff -r 89807d0b1dfe -r e4e0f9654a04 web/war/src/main/webapp/WEB-INF/web.xml --- a/web/war/src/main/webapp/WEB-INF/web.xml Tue Dec 20 15:24:46 2016 -0500 +++ b/web/war/src/main/webapp/WEB-INF/web.xml Tue Dec 20 15:25:58 2016 -0500 @@ -85,7 +85,12 @@ thermostat-realm - + THERMOSTAT_HOME ${thermostat.home}