SHARE
TWEET

Untitled

a guest Oct 4th, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Configuration file '/opt/rasdaman/etc/petascope.properties'
  2.  ==> Modified (by you or by a script) since installation.
  3.  ==> Package distributor has shipped an updated version.
  4.    What would you like to do about it ?  Your options are:
  5.     Y or I  : install the package maintainer's version
  6.     N or O  : keep your currently-installed version
  7.       D     : show the differences between the versions
  8.       Z     : start a shell to examine the situation
  9.  The default action is to keep your current version.
  10. *** petascope.properties (Y/I/N/O/D/Z) [default=N] ? N
  11.  
  12.  
  13.  
  14. """
  15.  *
  16.  * This file is part of rasdaman community.
  17.  *
  18.  * Rasdaman community is free software: you can redistribute it and/or modify
  19.  * it under the terms of the GNU General Public License as published by
  20.  * the Free Software Foundation, either version 3 of the License, or
  21.  * (at your option) any later version.
  22.  *
  23.  * Rasdaman community is distributed in the hope that it will be useful,
  24.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  26.  * See the GNU  General Public License for more details.
  27.  *
  28.  * You should have received a copy of the GNU  General Public License
  29.  * along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
  30.  *
  31.  * Copyright 2003 - 2016 Peter Baumann / rasdaman GmbH.
  32.  *
  33.  * For more information please see <http://www.rasdaman.org>
  34.  * or contact Peter Baumann via <baumann@rasdaman.com>.
  35.  *
  36. """
  37. import json
  38. import os
  39. import sys
  40. import tempfile
  41. import glob
  42. from abc import abstractmethod
  43. from time import sleep
  44.  
  45. from config_manager import ConfigManager
  46. from helper.commands import chmod, make_backup, merge_properties, move, remove, copy, make_directory
  47. from helper.executor import UserInfo
  48. from helper.fileutil import replace_in_file, find_line_containing_token_in_file, get_all_filepaths, \
  49.     append_to_file, read_file, write_to_file
  50. from helper.log import log
  51. from helper.stringutil import strip_whitespace
  52. from helper.sudo_commands import sudo_chown, sudo_chmod, sudo_remove, sudo_copy, sudo_move, sudo_mkdir
  53. from helper.distrowrapper import InitDTypes
  54. from services import executor, rasdaman_service, tomcat_service, rasdaman_system_service, linux_distro
  55.  
  56.  
  57. class Finalizer:
  58.     def __init__(self):
  59.         """
  60.         Base class for finalizer classes that execute after the system is installed and running.
  61.         Example of such classes are ones that provide functionality to insert demo data
  62.         """
  63.         pass
  64.  
  65.     @abstractmethod
  66.     def finalize(self):
  67.         """
  68.         Called to finalize the installation
  69.         """
  70.         pass
  71.  
  72.  
  73. class FinalizerBasis(Finalizer):
  74.     def __init__(self):
  75.         """
  76.         Class to be used as the basis of the decorator hierarchy
  77.         """
  78.         Finalizer.__init__(self)
  79.  
  80.     def finalize(self):
  81.         pass
  82.  
  83.  
  84. class FinalizerDecorator(Finalizer):
  85.     def __init__(self, finalizer):
  86.         """
  87.         Decorator class to be used by finalizer classes
  88.         :param Finalizer finalizer: the finalizer to decorate around
  89.         """
  90.         Finalizer.__init__(self)
  91.         self.finalizer = finalizer
  92.  
  93.     def finalize(self):
  94.         self.finalizer.finalize()
  95.  
  96.  
  97. class RasdamanDemoDataFinalizer(FinalizerDecorator):
  98.     def __init__(self, finalizer, install_path):
  99.         """
  100.         Ingests the rasdaman demo data
  101.         :param Finalizer finalizer: the finalizer to decorate
  102.         :param str install_path: the install path of rasdaman
  103.         """
  104.         FinalizerDecorator.__init__(self, finalizer)
  105.         self.install_path = install_path
  106.  
  107.     def need_to_ingest_demo_data(self, bin_path):
  108.         out, err, rc = executor.execute([bin_path + "/rasql", "--out", "string", "-q",
  109.                                         "SELECT C FROM RAS_COLLECTIONNAMES AS C"],
  110.                                         throw_on_error_code=False)
  111.         if "mr2" in out or "rgb" in out or "mr" in out or rc != 0:
  112.             # demo data already loaded or some problem executing rasql
  113.             return False
  114.         else:
  115.             return True
  116.  
  117.     def finalize(self):
  118.         FinalizerDecorator.finalize(self)
  119.         rasdaman_service.start()
  120.         bin_path = self.install_path + "/bin"
  121.         if self.need_to_ingest_demo_data(bin_path):
  122.             try:
  123.                 log.info("Installing rasdaman demo data...")
  124.                 images_path = self.install_path + "/share/rasdaman/examples/images"
  125.                 executor.execute([bin_path + "/rasdaman_insertdemo.sh", "localhost",
  126.                                  "7001", images_path, "rasadmin", "rasadmin"],
  127.                                  throw_on_error_code=False)
  128.             finally:
  129.                 rasdaman_service.stop()
  130.                 log.info("Rasdaman demo data installed successfully.")
  131.  
  132.  
  133. class PetascopeDemoDataFinalizer(FinalizerDecorator):
  134.     def __init__(self, finalizer, install_path):
  135.         """
  136.         Ingests the petascope demo data
  137.         :param Finalizer finalizer: the finalizer to decorate
  138.         :param str install_path: the install path of rasdaman
  139.         """
  140.         FinalizerDecorator.__init__(self, finalizer)
  141.         self.install_path = install_path
  142.  
  143.     def need_to_ingest_demo_data(self, bin_path):
  144.         out, err, rc = executor.execute([bin_path + "/rasql", "--out", "string", "-q",
  145.                                         "SELECT C FROM RAS_COLLECTIONNAMES AS C"],
  146.                                         throw_on_error_code=False)
  147.         if "AverageTemperature" in out or "AverageChloro" in out or rc != 0:
  148.             # demo data already loaded or some problem executing rasql
  149.             return False
  150.         else:
  151.             return True
  152.  
  153.     def finalize(self):
  154.         FinalizerDecorator.finalize(self)
  155.         rasdaman_service.start()
  156.         tomcat_service.restart()
  157.         bin_path = self.install_path + "/bin"
  158.         if self.need_to_ingest_demo_data(bin_path):
  159.             try:
  160.                 log.info("Installing Petascope demo data...")
  161.                 executor.execute(["wget", "http://localhost:8080/def/crs/EPSG/0/4326",
  162.                                  "-O", "/tmp/secore"], throw_on_error_code=False)
  163.                 executor.execute(["wget", "http://localhost:8080/rasdaman/ows?"
  164.                                           "service=WCS&version=2.0.1&request=GetCapabilities",
  165.                                  "-O", "/tmp/petascope"], throw_on_error_code=False)
  166.                 executor.execute([bin_path + "/petascope_insertdemo.sh"],
  167.                                  no_wait=True, throw_on_error_code=False)
  168.                 sleep(20)
  169.             finally:
  170.                 log.info("Petascope demo data installed successfully.")
  171.  
  172.  
  173. class MoveInstallerFinalizer(FinalizerDecorator):
  174.     def __init__(self, finalizer, main_path):
  175.         """
  176.         Moves the installer directory inside the rasdaman main path
  177.         :param Finalizer finalizer: the finalizer to decorate
  178.         :param str main_path: the main path to rasdaman
  179.         """
  180.         FinalizerDecorator.__init__(self, finalizer)
  181.         self.main_path = main_path
  182.  
  183.     def finalize(self):
  184.         FinalizerDecorator.finalize(self)
  185.         installer_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
  186.         installer_new_path = self.main_path + "/installer"
  187.         log.info("Copying install.sh to '{}'...".format(installer_new_path))
  188.  
  189.         make_directory(installer_new_path)
  190.         # copy install.sh script to /opt/rasdaman/installer
  191.         copy(installer_dir + "/install.sh", installer_new_path, False)
  192.         sudo_chown(self.main_path, ConfigManager.default_user)
  193.         sudo_chown(installer_new_path, ConfigManager.default_user)
  194.  
  195.         log.info("install.sh script file copied successfully.")
  196.  
  197.  
  198. class InstallerLogFinalizer(FinalizerDecorator):
  199.     def __init__(self, finalizer, source_path, profile_path, main_path, install_path):
  200.         """
  201.         Saves the installation profile in the rasdaman main path and adds any needed extra information, e.g. build hash
  202.         :param Finalizer finalizer: the finalizer to decorate
  203.         :param str source_path: path to the rasdaman source
  204.         :param str profile_path: the path to the installation profile
  205.         :param str main_path: the main path of rasdaman
  206.         :param str install_path: the path to the installer
  207.         :return:
  208.         """
  209.         FinalizerDecorator.__init__(self, finalizer)
  210.         self.profile_path = profile_path
  211.         self.source_path = source_path
  212.         self.main_path = main_path
  213.         self.install_path = install_path
  214.  
  215.     def _generate_update_rasdaman(self, profile_path):
  216.         update_rasdaman_contents = """
  217. #!/usr/bin/env bash
  218. {}/install.sh -j {}
  219. """.format(self.main_path + "/installer/", profile_path)
  220.         # NOTE: the update_rasdaman.sh is generated in /opt/rasdaman/bin by default, it is not in installer folder
  221.         updater_path = self.install_path + "/bin/update_rasdaman.sh"
  222.         log.info("Installing update script at '{}'...".format(updater_path))
  223.         write_to_file(updater_path, update_rasdaman_contents)
  224.         sudo_chown(updater_path, ConfigManager.default_user)
  225.         chmod(updater_path, "+x")
  226.         log.info("Update script installed successfully.")
  227.  
  228.     def finalize(self):
  229.         FinalizerDecorator.finalize(self)
  230.         profile_resting_path = self.main_path + "/install_profile.json"
  231.         log.info("Updating the installation profile file at '{}'...".format(profile_resting_path))
  232.         jsprofile = json.load(open(self.profile_path))
  233.         jsprofile['update'] = True
  234.         out, _, _ = executor.execute(["git", "rev-parse", "HEAD"], self.source_path)
  235.         jsprofile['version_hash'] = out.replace("\n", "")
  236.         fp = open(profile_resting_path, "w")
  237.         json.dump(jsprofile, fp, indent=4)
  238.         fp.close()
  239.         sudo_chown(profile_resting_path, ConfigManager.default_user)
  240.         chmod(profile_resting_path, "755")
  241.         log.info("Installation profile updated successfully.")
  242.         self._generate_update_rasdaman(profile_resting_path)
  243.  
  244.  
  245. class ServiceInitDFinalizer(FinalizerDecorator):
  246.     def __init__(self, finalizer, install_path, user, profile, automatic_start=True):
  247.         """
  248.         Creates a init.d script to be used to stop and start rasdaman
  249.         :param Finalizer finalizer: the finalizer to decorate
  250.         :param str install_path: the installation path where the bin file can be found
  251.         :param str user: the user that needs to execute rasdaman services
  252.         :param Profile profile: the whole profile object
  253.         :param bool automatic_start: set to false if rasdaman should not start at startup
  254.         """
  255.         FinalizerDecorator.__init__(self, finalizer)
  256.         self.install_path = install_path
  257.         self.profile = profile
  258.         self.user = user
  259.         self.automatic_start = automatic_start
  260.  
  261.     def __initialize_sysv_script(self):
  262.         contents = read_file(os.path.dirname(os.path.realpath(__file__)) + "/rasdaman.sh")
  263.         contents = contents.replace("start_rasdaman.sh", self.install_path + "/bin/start_rasdaman.sh")
  264.         contents = contents.replace("stop_rasdaman.sh", self.install_path + "/bin/stop_rasdaman.sh")
  265.         contents = contents.replace("RUN_AS_USER", linux_distro.get_runuser(self.user))
  266.         return contents
  267.  
  268.     def __install_sysv_script(self):
  269.         contents = self.__initialize_sysv_script()
  270.         initd_path = "/etc/init.d/rasdaman"
  271.         write_to_file(initd_path, contents)
  272.         sudo_chmod(initd_path, "755")
  273.  
  274.     def __install_systemd_script(self):
  275.         if linux_distro.get_initd_type() == InitDTypes.SYSTEMD:
  276.             service_contents = read_file(os.path.dirname(os.path.realpath(__file__)) + "/rasdaman.service")
  277.             service_path = "/etc/systemd/system/rasdaman.service"
  278.             write_to_file(service_path, service_contents)
  279.             sudo_chmod(service_path, "644")
  280.         if self.automatic_start:
  281.             rasdaman_system_service.enable()
  282.  
  283.     def finalize(self):
  284.         FinalizerDecorator.finalize(self)
  285.         log.info("Creating service script...")
  286.         self.__install_sysv_script()
  287.         self.__install_systemd_script()
  288.         log.info("Service script created successfully.")
  289.  
  290.  
  291. class CopyOldConfigFromPackagesFinalizer(FinalizerDecorator):
  292.     def __init__(self, finalizer, installation_path):
  293.         """
  294.         Copies configuration files from /etc that pertain to rasdaman from old installations that used
  295.         / as rmanhome
  296.         :param Finalizer finalizer: the finalizer to decorate
  297.         :param str installation_path: the installation path
  298.         """
  299.         FinalizerDecorator.__init__(self, finalizer)
  300.         self.installation_path = installation_path
  301.  
  302.     def finalize(self):
  303.         FinalizerDecorator.finalize(self)
  304.         log.info("Looking for any existing configuration files from deprecated packages to migrate...")
  305.         etc_path = self.installation_path + "/etc/"
  306.         copied = False
  307.         for path in ["rasmgr.conf", "rmankey"]:
  308.             source = "/etc/rasdaman/" + path
  309.             if os.path.exists(source):
  310.                 dest = etc_path + path
  311.                 sudo_copy(source, dest, throw_on_error_code=False)
  312.                 sudo_chown(dest, ConfigManager.default_user)
  313.                 copied = True
  314.         if copied:
  315.             log.info("All previous configuration files migrated successfully.")
  316.         else:
  317.             log.info("No previous configuration files found to migrate.")
  318.  
  319.  
  320. class EnsureExistingConfigPersistFinalizer(FinalizerDecorator):
  321.     def __init__(self, finalizer, installation_path):
  322.         """
  323.         Copies configuration files from /etc that pertain to rasdaman from old installations that used
  324.         / as rmanhome
  325.         :param Finalizer finalizer: the finalizer to decorate
  326.         :param str installation_path: the installation path
  327.         """
  328.         FinalizerDecorator.__init__(self, finalizer)
  329.         self.installation_path = installation_path
  330.  
  331.     def finalize(self):
  332.         FinalizerDecorator.finalize(self)
  333.         log.info("Restoring configuration files...")
  334.         etc_path = self.installation_path + "/etc/"
  335.         copied = False
  336.         for path in ["rasmgr.conf", "petascope.properties", "secore.properties", "wms_service.properties"]:
  337.             source = "/tmp/rasdaman-backup/etc/" + path
  338.             if os.path.exists(source):
  339.                 dest = etc_path + path
  340.                 if path == "petascope.properties":
  341.                     # Get the new properties file from package which is renamed as petascope.properties.rpmnew (in ***rpm*** package)
  342.                     # NOTE: if this file does not exist which means old petascope.properties also does not exist, then nothing to update
  343.                     petascope_properties_rpm_new_array = glob.glob(self.installation_path + "/etc/petascope.properties.*new")
  344.                     if len(petascope_properties_rpm_new_array) == 1:                        
  345.                         new_petascope_properties_path = petascope_properties_rpm_new_array[0]
  346.                         log.info("update petascope.properties configuration from " + source + " to " + new_petascope_properties_path + "...")
  347.                         # Run the update_properties.sh to update the changes between user's old file and source's new file
  348.                         # The output is a combined petascope.properties file which will be copied back to installation path
  349.                         executor.executeSudo([self.installation_path + "/bin/update_properties.sh", source, new_petascope_properties_path], throw_on_error_code=True)                                    
  350.                         log.info("petascope.properties updated successfully.")
  351.                     # Get the new properties file from package which is renamed as petascope.properties.dkpg-dist (in ***deb*** package)
  352.                     # NOTE: if this file does not exist which means old petascope.properties also does not exist, then nothing to update
  353.                     petascope_properties_rpm_new_array = glob.glob(self.installation_path + "/etc/petascope.properties.*dist")
  354.                     if len(petascope_properties_rpm_new_array) == 1:                        
  355.                         new_petascope_properties_path = petascope_properties_rpm_new_array[0]
  356.                         log.info("update petascope.properties configuration from " + source + " to " + new_petascope_properties_path + "...")
  357.                         # Run the update_properties.sh to update the changes between user's old file and source's new file
  358.                         # The output is a combined petascope.properties file which will be copied back to installation path
  359.                         executor.executeSudo([self.installation_path + "/bin/update_properties.sh", source, new_petascope_properties_path], throw_on_error_code=True)                                    
  360.                         log.info("petascope.properties updated successfully.")
  361.                    
  362.                 executor.executeSudo(["cp", "-v", source, dest], throw_on_error_code=False)
  363.                 sudo_chown(dest, ConfigManager.default_user)
  364.                 copied = True
  365.                 log.info("Copied " + source + " to " + dest)
  366.         if copied:
  367.             log.info("All previous configuration files restored successfully.")
  368.         else:
  369.             log.info("No previous configuration files found to restore.")
  370.  
  371.  
  372. class PropertiesMigrationFinalizer(FinalizerDecorator):
  373.     def __init__(self, finalizer, install_path, osgeo=False):
  374.         """
  375.         Migrate properties, e.g. log4j.properties into petascope.properties
  376.         :param Finalizer finalizer: the finalizer to decorate
  377.         :param str install_path: the installation path of rasdaman
  378.         """
  379.         FinalizerDecorator.__init__(self, finalizer)
  380.         self.install_path = install_path
  381.         self.osgeo = osgeo
  382.  
  383.     def migrate_log4j_properties(self):
  384.         """
  385.         Move log4j.properties to petascope.properties if needed.
  386.         """
  387.         log4j_properties = self.install_path + "/etc/log4j.properties"
  388.         petascope_properties = self.install_path + "/etc/petascope.properties"
  389.         if os.path.exists(log4j_properties) and os.path.exists(petascope_properties):
  390.             line = find_line_containing_token_in_file(petascope_properties, "log4j")
  391.             if line is None:
  392.                 log.info("Migrating '{}' to '{}'...".format(log4j_properties, petascope_properties))
  393.                 make_backup(petascope_properties)
  394.                 append_to_file(petascope_properties, """
  395. # ---------------------------------------------------------------------
  396. #
  397. # log4j configuration
  398. #
  399.         """)
  400.                 merge_properties(petascope_properties, log4j_properties)
  401.                 if self.osgeo:
  402.                     sudo_move(log4j_properties, log4j_properties + ".unused")
  403.                 else:
  404.                     move(log4j_properties, log4j_properties + ".unused")
  405.                 tomcat_service.restart()
  406.                 log.info("Logging configuration migrated to petascope.properties.")
  407.  
  408.     def finalize(self):
  409.         FinalizerDecorator.finalize(self)
  410.         self.migrate_log4j_properties()
  411.  
  412.  
  413. class PermissionFixFinalizer(FinalizerDecorator):
  414.     def __init__(self, finalizer, install_path):
  415.         """
  416.         Make sure the install_path is owned by the rasdaman user
  417.         :param Finalizer finalizer: the finalizer to decorate
  418.         :param str install_path: the installation path of rasdaman
  419.         """
  420.         FinalizerDecorator.__init__(self, finalizer)
  421.         self.install_path = install_path
  422.  
  423.     def finalize(self):
  424.         FinalizerDecorator.finalize(self)
  425.         sudo_chown(self.install_path, ConfigManager.default_user)
  426.  
  427.  
  428. class DataSymlinkFinalizer(FinalizerDecorator):
  429.     def __init__(self, finalizer, data_directory, install_path):
  430.         """
  431.         Adds a symlink in the install path if the folder does not exist.
  432.         :param Finalizer finalizer: the finalizer to decorate for
  433.         :param str data_directory: the real data directory
  434.         :param str install_path: the rasdaman installation path
  435.         """
  436.         FinalizerDecorator.__init__(self, finalizer)
  437.         self.data_directory = data_directory
  438.         self.install_path = install_path
  439.  
  440.     def finalize(self):
  441.         FinalizerDecorator.finalize(self)
  442.         data_install_path = self.install_path + "/data/"
  443.         if not os.path.exists(data_install_path):
  444.             log.info("Creating a symlink for the data directory...")
  445.             executor.execute(["ln", "-s", self.data_directory, "data"], self.install_path)
  446.             log.info("Symlink created successfully.")
  447.  
  448.  
  449. class RasimportFinalizer(FinalizerDecorator):
  450.     def __init__(self, finalizer, peta_db_name, peta_user, peta_pass):
  451.         """
  452.         Sets up rasimport by configuring the rasconnect file
  453.         :param Finalizer finalizer: the finalizer to decorate
  454.         :param str peta_db_name: the petascope db name
  455.         :param str peta_user: the petascope user
  456.         :param str peta_pass: the password for peta user
  457.         """
  458.         FinalizerDecorator.__init__(self, finalizer)
  459.         self.peta_db_name = peta_db_name
  460.         self.peta_user = peta_user
  461.         self.peta_pass = peta_pass
  462.  
  463.     def finalize(self):
  464.         FinalizerDecorator.finalize(self)
  465.         log.info("Configuring rasimport...")
  466.         home_dir = UserInfo(ConfigManager.default_user).user_home_dir
  467.         rasconnect_file = strip_whitespace(home_dir) + "/.rasdaman/rasconnect"
  468.         if os.path.isfile(rasconnect_file):
  469.             replace_in_file(rasconnect_file, {
  470.                 "petadbname=petascopedb": "petadbname=" + self.peta_db_name.split("/")[-1],
  471.                 "petauser=petauser": "petauser=" + self.peta_user,
  472.                 "petapassword=petapasswd": "petapassword=" + self.peta_pass
  473.             })
  474.             # if the rasconnect was changed before, make sure the password is correct
  475.             line = find_line_containing_token_in_file(rasconnect_file, "petapassword")
  476.             if line is not None:
  477.                 replace_in_file(rasconnect_file, {
  478.                     line: "petapassword=" + self.peta_pass
  479.                 })
  480.             log.info("rasimport configured successfully.")
  481.         else:
  482.             log.warn("Could not configure rasimport, config file could not be found at: " + rasconnect_file)
  483.  
  484.  
  485. class ServiceShutdownFinalizer(FinalizerDecorator):
  486.     def __init__(self, finalizer):
  487.         """
  488.         Shuts down any existing services that might be used by the current user
  489.         :param Finalizer finalizer: the finalizer to wrap around
  490.         """
  491.         FinalizerDecorator.__init__(self, finalizer)
  492.  
  493.     def finalize(self):
  494.         FinalizerDecorator.finalize(self)
  495.         tomcat_service.stop()
  496.         rasdaman_service.stop()
  497.  
  498.  
  499. class OSGeoFinalizer(FinalizerDecorator):
  500.     def __init__(self, finalizer, installation_path):
  501.         """
  502.         Creates certain customizations that are needed for OSGeo Live DVD
  503.         :param Finalizer finalizer: the finalizer to decorate
  504.         :param str installation_path: the installation path
  505.         :return:
  506.         """
  507.         FinalizerDecorator.__init__(self, finalizer)
  508.         self.installation_path = installation_path
  509.  
  510.     def create_demo_scripts(self):
  511.         rasdaman_demo_contents = """#!/bin/sh
  512. if [ ! -f {rasdaman_demo_created_file} ]; then
  513.     echo "Ingesting rasdaman data..."
  514.     {rasdaman_insert_demo} localhost 7001 {install_path}/share/rasdaman/examples/images rasadmin rasadmin
  515.     touch {rasdaman_demo_created_file}
  516.     echo "Rasdaman data ingested successfully."
  517. fi
  518. """.format(rasdaman_demo_created_file=self.installation_path + "/rasdaman_demo_success",
  519.            rasdaman_insert_demo=self.installation_path + "/bin/rasdaman_insertdemo.sh",
  520.            install_path=self.installation_path)
  521.  
  522.         petascope_demo_contents = """#!/bin/sh
  523. if [ ! -f {petascope_demo_created_file} ]; then
  524.     echo "Ingesting Petascope data..."
  525.     {petascope_insert_demo}
  526.     {wcst_import} {ingest_path}/NIR.json
  527.     {wcst_import} {ingest_path}/NN3_1.json
  528.     {wcst_import} {ingest_path}/lena.json
  529.     touch {petascope_demo_created_file}
  530.     echo "Petascope data ingested successfully."
  531. fi
  532. """.format(petascope_demo_created_file=self.installation_path + "/petascope_demo_success",
  533.            petascope_insert_demo=self.installation_path + "/bin/petascope_insertdemo.sh",
  534.            ingest_path=self.installation_path + "/ingest",
  535.            wcst_import=self.installation_path + "/bin/wcst_import.sh")
  536.  
  537.         demo_scripts = {
  538.             "rasdaman-osgeo-demo.sh": rasdaman_demo_contents,
  539.             "petascope-osgeo-demo.sh": petascope_demo_contents
  540.         }
  541.         for filename, contents in demo_scripts.iteritems():
  542.             full_path = self.installation_path + "/bin/" + filename
  543.             write_to_file(full_path, contents)
  544.             sudo_chown(full_path, ConfigManager.default_user)
  545.             chmod(full_path, "775")
  546.  
  547.     def create_bin_starters(self):
  548.         bin_starters = {
  549.             "rasdaman-start.sh": """#!/bin/bash
  550. sudo service tomcat8 start
  551. sudo service rasdaman start
  552. echo "Preparing demo data..."
  553. {install_path}/bin/rasdaman-osgeo-demo.sh &> /dev/null
  554. {install_path}/bin/petascope-osgeo-demo.sh &> /dev/null
  555. echo "Demo data prepared successfully."
  556. zenity --info --text "Rasdaman started"
  557. echo -e "\033[0;32mRasdaman was started correctly. You can close this window now.\033[0m"
  558. """.format(install_path=self.installation_path),
  559.             "rasdaman-stop.sh": """
  560. #!/bin/sh
  561. sudo service tomcat8 stop
  562. sudo service rasdaman stop
  563. zenity --info --text "Rasdaman stopped"
  564. """
  565.         }
  566.         bin_path = self.installation_path + "/bin/"
  567.         for filename, contents in bin_starters.iteritems():
  568.             complete_path = bin_path + filename
  569.             write_to_file(complete_path, contents)
  570.             sudo_chown(complete_path, ConfigManager.default_user)
  571.             chmod(complete_path, "755")
  572.  
  573.     def create_desktop_applications(self):
  574.         bin_path = self.installation_path + "/bin"
  575.         desktop_files = {
  576.             "start_rasdaman_server.desktop": """[Desktop Entry]
  577. Type=Application
  578. Encoding=UTF-8
  579. Name=Start Rasdaman Server
  580. Comment=Start Rasdaman Server
  581. Categories=Application;Education;Geography;
  582. Exec=gksudo bash {}/rasdaman-start.sh
  583. Icon=gnome-globe
  584. Terminal=true
  585. StartupNotify=false
  586. """.format(bin_path),
  587.             "stop_rasdaman_server.desktop": """[Desktop Entry]
  588. Type=Application
  589. Encoding=UTF-8
  590. Name=Stop Rasdaman Server
  591. Comment=Stop Rasdaman Server
  592. Categories=Application;Education;Geography;
  593. Exec=gksudo bash {}/rasdaman-stop.sh
  594. Icon=gnome-globe
  595. Terminal=true
  596. StartupNotify=false
  597. """.format(bin_path),
  598.             "rasdaman-earthlook-demo.desktop": """
  599. [Desktop Entry]
  600. Type=Application
  601. Encoding=UTF-8
  602. Name=Rasdaman-Earthlook Demo
  603. Comment=Rasdaman Demo and Tutorial
  604. Categories=Application;Education;Geography;
  605. Exec=firefox  http://localhost/rasdaman-demo/
  606. Icon=gnome-globe
  607. Terminal=false
  608. StartupNotify=false
  609. """
  610.         }
  611.         desktop_paths = ["/usr/local/share/applications/", '/home/user/Desktop/']
  612.         for path in desktop_paths:
  613.             sudo_mkdir(path)
  614.             for filename, contents in desktop_files.iteritems():
  615.                 complete_path = path + filename
  616.                 write_to_file(complete_path, contents)
  617.                 sudo_chown(complete_path, ConfigManager.default_user)
  618.                 chmod(complete_path, "755")
  619.  
  620.     def deploy_earthlook(self):
  621.         tmp = tempfile.gettempdir() + "/earthlook"
  622.         make_directory(tmp)
  623.         executor.execute(["wget", "http://kahlua.eecs.jacobs-university.de/~earthlook/osgeo/earthlook.tar.gz", "-O",
  624.                           "earthlook.tar.gz"], tmp)
  625.         executor.execute(["tar", "-xzvf", "earthlook.tar.gz"], tmp)
  626.         rasdaman_demo_path = "/var/www/html/rasdaman-demo"
  627.         sudo_remove(rasdaman_demo_path)
  628.         sudo_move("public_html", rasdaman_demo_path, working_dir=tmp)
  629.         sudo_chown(rasdaman_demo_path, ConfigManager.default_user)
  630.         chmod(rasdaman_demo_path, "755")
  631.         remove(tmp)
  632.  
  633.     def ingest_data(self):
  634.         ingredients_template = """
  635. {
  636.   "config": {
  637.     "service_url": "http://localhost:8080/rasdaman/ows",
  638.     "tmp_directory": "/tmp/",
  639.     "crs_resolver": "http://localhost:8080/def/",
  640.     "default_crs": "http://localhost:8080/def/OGC/0/Index2D",
  641.     "mock": false,
  642.     "automated": true,
  643.     "subset_correction" : false
  644.   },
  645.   "input": {
  646.     "coverage_id": "{coverage}"
  647.   },
  648.   "recipe": {
  649.     "name": "wcs_extract",
  650.     "options": {
  651.       "coverage_id" : "{coverage}",
  652.       "wcs_endpoint" : "http://ows.rasdaman.org/rasdaman/ows"
  653.     }
  654.   }
  655. }
  656. """
  657.         tmp = self.installation_path + "/ingest/"
  658.         make_directory(tmp)
  659.         coverages = ["NIR", "NN3_1", "lena"]
  660.         for coverage in coverages:
  661.             ingest_tmp = tmp + coverage + ".json"
  662.             write_to_file(ingest_tmp, ingredients_template.replace("{coverage}", coverage))
  663.  
  664.     def delete_not_needed_files(self):
  665.         remove(self.installation_path + "/lib")
  666.         remove(self.installation_path + "/include")
  667.         strip_files = get_all_filepaths(self.installation_path + "/bin/")
  668.         for sfile in strip_files:
  669.             executor.execute(["strip", sfile], throw_on_error_code=False)
  670.  
  671.     def make_tomcat_auto_deploy(self):
  672.         replace_in_file("/var/lib/tomcat8/conf/server.xml", {
  673.             'unpackWARs="false"': 'unpackWARs="true"',
  674.             'autoDeploy="false"': 'autoDeploy="true"'
  675.         })
  676.         tomcat_service.restart()
  677.  
  678.     def remove_dev_libs(self):
  679.         executor.executeSudo(
  680.             ['apt-get', '--yes', 'remove', 'libtool', 'bison', 'comerr-dev', 'doxygen', 'doxygen-latex', 'flex',
  681.              'krb5-multidev', 'libecpg-dev', 'libjpeg-dev', 'libedit-dev', 'libkrb5-dev', 'libncurses5-dev',
  682.              'libnetpbm10-dev', 'libpng12-dev', 'libpq-dev', 'libreadline-dev', 'libreadline6-dev', 'libtiff4-dev',
  683.              'luatex', 'libgssrpc4', 'libkdb5-7', 'libgdal-dev', 'libsigsegv-dev'], throw_on_error_code=False)
  684.  
  685.     def add_profile_to_bashrc(self):
  686.         bashrc = UserInfo(ConfigManager.default_user).user_home_dir + "/.bashrc"
  687.         with open(bashrc, "a") as bfile:
  688.             bfile.write("source /etc/profile.d/rasdaman.sh\n")
  689.  
  690.     def make_root_owner_of_rasdaman(self):
  691.         sudo_chown(self.installation_path, "root", "users")
  692.  
  693.     def finalize(self):
  694.         FinalizerDecorator.finalize(self)
  695.         log.info("Customizing rasdaman for OSGeo Live...")
  696.         log.info("Creating starting scripts...")
  697.         self.create_bin_starters()
  698.         self.create_demo_scripts()
  699.         log.info("Starting scripts successfully created.")
  700.         log.info("Creating desktop icons...")
  701.         self.create_desktop_applications()
  702.         log.info("Desktop icons created successfully.")
  703.         log.info("Striping binaries and removing unneeded files for OSGeo Live...")
  704.         self.delete_not_needed_files()
  705.         log.info("Binaries stripped successfully.")
  706.         log.info("Deploying local earthlook...")
  707.         self.deploy_earthlook()
  708.         log.info("Local earthlook deployed successfully.")
  709.         log.info("Ingesting demo data...")
  710.         self.ingest_data()
  711.         log.info("Demo data ingested successfully.")
  712.         log.info("Add rasdaman profile to the user's bashrc...")
  713.         self.add_profile_to_bashrc()
  714.         log.info("Profile added successfully.")
  715.         log.info("Cleaning dev packages...")
  716.         self.remove_dev_libs()
  717.         log.info("Dev packages cleaned successfully.")
  718.         log.info("Making root owner of rasdaman installation.")
  719.         self.make_root_owner_of_rasdaman()
  720.         log.info("Root is now owner of rasdaman")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top