def deploy_app_fn(resource_id, server_host, server_port, app_path, app_war_file, user, password, update=False, tag=None): params = {"path":app_path} params["war"] = "file:" + \ os.path.abspath(os.path.expanduser(app_war_file)) if update: params["update"] = "true" if tag: params["tag"] = tag uri = "http://%s:%d/manager/deploy?%s" % \ (server_host, server_port, urllib.urlencode(params)) with open(app_war_file, "rb") as f: result = \ httputils.make_request_with_basic_authentication( uri, MANAGER_REALM, user, password, logger=logger) # This version tried to send the file directly using PUT. # Unfortunately, the python code seems to be expecting unicode # data and errors out. Not sure what kind of encoding the # tomcat side is expecting. ## httputils.make_request_with_basic_authentication( ## uri, MANAGER_REALM, user, password, ## data=f.read(), ## content_type="application/java-archive", ## request_method="PUT", ## logger=logger) if result[0:2]!="OK": raise UserError(errors[ERR_TOMCAT_DEPLOY], msg_args={"id":resource_id, "path":app_path, "response": result}, developer_msg="uri=%s" % uri)
def install(self, package): extracted_dir = package.extract(self.config.home_dir_parent) if extracted_dir != self.config.home_dir: # make the final name of the tomcat dir equivalent to the # one specified in the resource instance shutil.move(os.path.join(self.config.home_dir_parent, extracted_dir), self.config.home_path) # initialize the database call_mysql(self.config, _mysql_cmds.format(self.config.createdb_sql_path, self.config.config_port.database_user, self.config.config_port.database_password)) # setup the runtime properties file setup_runtime_properties(self.config) # copy the war file #shutil.copyfile(self.config.warfile_source_path, # self.config.warfile_target_path) uri = _deploy_req_uri % (self.config.input_ports.tomcat.hostname, self.config.input_ports.tomcat.manager_port, self.config.home_path) logger.debug("Attempting to deploy openmrs:\nuri=%s" % uri) result = iuhttp.make_request_with_basic_authentication(uri, _tomcat_mgr_realm, self.config.input_ports.tomcat.admin_user, self.config.input_ports.tomcat.admin_password) if result.find(_deploy_rsp)==-1: raise OpenmrsError(ERR_DEPLOY_RSP, "Install", self.config, developer_msg="Response was: '%s'" % result) # check that everything is now in place self.validate_post_install()
def stop(self): uri = _stop_req_uri % (self.config.input_ports.tomcat.hostname, self.config.input_ports.tomcat.manager_port) try: result = iuhttp.make_request_with_basic_authentication( uri, _tomcat_mgr_realm, self.config.input_ports.tomcat.admin_user, self.config.input_ports.tomcat.admin_password, ) if result.find(_stop_rsp) == -1: raise AgilefantError( ERR_TOMCAT_STOPRSP, "Stop", self.config, developer_msg="Response was '%s'" % result ) except urllib2.URLError, msg: raise AgilefantError(ERR_TOMCAT_STOPREQ, "Stop", self.config, developer_msg="URL error was: '%s'" % msg)
def start(self): uri = _start_req_uri % (self.config.input_ports.tomcat.hostname, self.config.input_ports.tomcat.manager_port) tomcat_password = install_context.password_repository.get_value(self.config.input_ports.tomcat.admin_password) try: result = iuhttp.make_request_with_basic_authentication( uri, _tomcat_mgr_realm, self.config.input_ports.tomcat.admin_user, tomcat_password ) if result.find(_start_rsp) == -1: raise AgilefantError( ERR_TOMCAT_STARTRSP, "Startup", self.config, developer_msg="Response was '%s'" % result ) except urllib2.URLError, msg: raise AgilefantError( ERR_TOMCAT_STARTUP, "Startup", self.config, developer_msg="Tomcat error was '%s'" % msg )
def install(self, package): extracted_dir = package.extract(self.config.home_dir_parent, desired_common_dirname=self.config.home_dir) # initialize the database root_password = install_context.password_repository.get_value(self.config.input_ports.mysql_admin.root_password) db_password = install_context.password_repository.get_value(self.config.config_port.database_password) call_mysql( self.config, "root", root_password, _mysql_cmds.format(self.config.config_port.database_user, db_password) ) call_mysql( self.config, self.config.config_port.database_user, db_password, _mysql_createdb.format(self.config.home_path), ) # deploy the war file uri = _deploy_req_uri % ( self.config.input_ports.tomcat.hostname, self.config.input_ports.tomcat.manager_port, self.config.home_path, ) logger.debug("Attempting to deploy agilefant:\nuri=%s" % uri) tomcat_password = install_context.password_repository.get_value(self.config.input_ports.tomcat.admin_password) result = iuhttp.make_request_with_basic_authentication( uri, _tomcat_mgr_realm, self.config.input_ports.tomcat.admin_user, tomcat_password ) if result.find(_deploy_rsp) == -1: raise AgilefantError(ERR_DEPLOY_RSP, "Install", self.config, developer_msg="Response was: '%s'" % result) # write out the init.d startup script # we just stick it in the install directory for now and leave it to # the user to manually copy it to /etc/init.d and enable it. agilefant_initd_file = iufile.get_data_file_contents(__file__, "agilefant.sh") startup_script = agilefant_initd_file % { "mysql_install_dir": self.config.input_ports.mysql_admin.install_dir, "tomcat_install_dir": self.config.input_ports.tomcat.home, "os_user": self.config.input_ports.tomcat.os_user_name, } start_script_filepath = os.path.join(self.config.home_path, "agilefant.sh") start_script_file = open(start_script_filepath, "wb") start_script_file.write(startup_script) start_script_file.close() os.chmod(start_script_filepath, 0755) # check that everything is now in place self.validate_post_install()
def _make_request(uri, user, password): return httputils.make_request_with_basic_authentication(uri, MANAGER_REALM, user, password, logger=logger)