Advertisement
Guest User

Untitled

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