-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from hardyoyo/add-healthcheck-to-our-backend-i…
…mage Add healthcheck to our backend image
- Loading branch information
Showing
13 changed files
with
6,736 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python3 | ||
"""Script to modify a Tomcat server.xml file using Docker and plain text processing. | ||
This script fetches the server.xml file from a Docker container, adds a new | ||
HealthCheckValve element to the last Host in the XML, and saves the modified | ||
file locally. | ||
Make sure you have Docker installed and the necessary permissions to run it. | ||
Usage: | ||
1. Adjust CONTAINER_TOMCAT_CONFIG_PATH, LOCAL_TOMCAT_CONFIG_PATH, and | ||
BACKEND_IMAGE_TAG as needed. | ||
2. Run the script. | ||
""" | ||
|
||
import subprocess | ||
import sys | ||
import os | ||
|
||
CONTAINER_TOMCAT_CONFIG_PATH = '/usr/local/tomcat/conf' | ||
LOCAL_TOMCAT_CONFIG_PATH = 'config/tomcat' | ||
BACKEND_IMAGE_TAG = os.getenv('BACKEND_IMAGE_TAG', 'dspace/dspace:dspace-7_x') | ||
|
||
CONTAINER_SERVER_XML = CONTAINER_TOMCAT_CONFIG_PATH + '/server.xml' | ||
LOCAL_SERVER_XML = LOCAL_TOMCAT_CONFIG_PATH + '/server.xml' | ||
|
||
# Indicate that we are fetching the server.xml file | ||
print("Fetching the server.xml file from the Docker container...") | ||
|
||
docker_command = [ | ||
'docker', | ||
'run', | ||
'--rm', | ||
BACKEND_IMAGE_TAG, | ||
'cat', | ||
CONTAINER_SERVER_XML, | ||
] | ||
|
||
# Run the Docker command to fetch the server.xml file | ||
with subprocess.Popen(docker_command, cwd=LOCAL_TOMCAT_CONFIG_PATH, stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE) as process: | ||
output, error = process.communicate() | ||
if process.returncode != 0: | ||
print("Error fetching the server.xml file:") | ||
print("stdout:", output.decode('utf-8')) | ||
print("stderr:", error.decode('utf-8')) | ||
sys.exit(1) | ||
|
||
# Write the fetched content to the local server.xml file | ||
with open(LOCAL_SERVER_XML, 'wb') as local_file: | ||
local_file.write(output) | ||
|
||
# Indicate that we are processing the server.xml file | ||
print("Processing the server.xml file...") | ||
|
||
# Identify the line number where we want to insert the new HealthCheckValve | ||
INSERT_LINE_NUMBER = None | ||
with open(LOCAL_SERVER_XML, 'r', encoding='utf-8') as xml_file: | ||
lines = xml_file.readlines() | ||
for i, line in enumerate(reversed(lines)): | ||
if '</Host>' in line: | ||
INSERT_LINE_NUMBER = len(lines) - i | ||
break | ||
|
||
# Insert the new HealthCheckValve into the identified line | ||
if INSERT_LINE_NUMBER is not None: | ||
lines.insert(INSERT_LINE_NUMBER, | ||
' <Valve className="org.apache.catalina.valves.HealthCheckValve"/>\n') | ||
|
||
# Write the modified content back to the local server.xml file | ||
with open(LOCAL_SERVER_XML, 'w', encoding='utf-8') as xml_file: | ||
xml_file.writelines(lines) | ||
|
||
# Indicate success | ||
print("Modification complete. The modified server.xml file is saved locally.") | ||
|
||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> | ||
|
||
<bean id="uploadConfigurationDefault" class="org.dspace.submit.model.UploadConfiguration"> | ||
<property name="name" value="upload"/> | ||
<property name="metadata" value="bitstream-metadata" /> | ||
<property name="options"> | ||
<list> | ||
<ref bean="openAccess"/> | ||
<ref bean="lease"/> | ||
<ref bean="embargoed" /> | ||
<ref bean="administrator"/> | ||
<!-- <ref bean="networkAdministration"/> --> | ||
</list> | ||
</property> | ||
</bean> | ||
|
||
<bean id="openAccess" class="org.dspace.submit.model.AccessConditionOption"> | ||
<property name="groupName" value="Anonymous"/> | ||
<property name="name" value="openaccess"/> | ||
<property name="hasStartDate" value="false"/> | ||
<property name="hasEndDate" value="false"/> | ||
</bean> | ||
<bean id="lease" class="org.dspace.submit.model.AccessConditionOption"> | ||
<property name="groupName" value="Anonymous"/> | ||
<property name="name" value="lease"/> | ||
<property name="hasStartDate" value="false"/> | ||
<property name="hasEndDate" value="true"/> | ||
<property name="endDateLimit" value="+6MONTHS"/> | ||
</bean> | ||
<bean id="embargoed" class="org.dspace.submit.model.AccessConditionOption"> | ||
<property name="groupName" value="Anonymous"/> | ||
<property name="name" value="embargo"/> | ||
<property name="hasStartDate" value="true"/> | ||
<property name="startDateLimit" value="+36MONTHS"/> | ||
<property name="hasEndDate" value="false"/> | ||
</bean> | ||
<bean id="administrator" class="org.dspace.submit.model.AccessConditionOption"> | ||
<property name="groupName" value="Administrator"/> | ||
<property name="name" value="administrator"/> | ||
<property name="hasStartDate" value="false"/> | ||
<property name="hasEndDate" value="false"/> | ||
</bean> | ||
<!-- <bean id="networkAdministration" class="org.dspace.submit.model.AccessConditionOption"> | ||
<property name="groupName" value="INSTITUTIONAL_NETWORK"/> | ||
<property name="name" value="networkAdministration"/> | ||
<property name="hasStartDate" value="false"/> | ||
<property name="hasEndDate" value="false"/> | ||
</bean> --> | ||
|
||
<bean id="uploadConfigurationService" class="org.dspace.submit.model.UploadConfigurationService"> | ||
<property name="map"> | ||
<map> | ||
<entry key="upload" value-ref="uploadConfigurationDefault" /> | ||
</map> | ||
</property> | ||
</bean> | ||
|
||
<bean id="accessConditionConfigurationService" class="org.dspace.submit.model.AccessConditionConfigurationService" /> | ||
|
||
<bean id="accessConditionConfigurationDefault" class="org.dspace.submit.model.AccessConditionConfiguration"> | ||
<!-- This name must match the id of the step as defined in the item-submission.xml --> | ||
<property name="name" value="itemAccessConditions"></property> | ||
<property name="canChangeDiscoverable" value="true"></property> | ||
<property name="options"> | ||
<list> | ||
<ref bean="openAccess"/> | ||
<ref bean="lease"/> | ||
<ref bean="embargoed" /> | ||
<ref bean="administrator"/> | ||
</list> | ||
</property> | ||
</bean> | ||
|
||
<bean id="defaultBulkAccessConditionConfiguration" | ||
class="org.dspace.app.bulkaccesscontrol.model.BulkAccessConditionConfiguration"> | ||
<property name="name" value="default"/> | ||
<property name="itemAccessConditionOptions"> | ||
<list> | ||
<ref bean="openAccess"/> | ||
<ref bean="administrator"/> | ||
<ref bean="embargoed" /> | ||
<ref bean="lease"/> | ||
</list> | ||
</property> | ||
<property name="bitstreamAccessConditionOptions"> | ||
<list> | ||
<ref bean="openAccess"/> | ||
<ref bean="administrator"/> | ||
<ref bean="embargoed" /> | ||
<ref bean="lease"/> | ||
</list> | ||
</property> | ||
</bean> | ||
|
||
<bean id="bulkAccessConditionConfigurationService" | ||
class="org.dspace.app.bulkaccesscontrol.service.BulkAccessConditionConfigurationService"> | ||
<property name="bulkAccessConditionConfigurations"> | ||
<list> | ||
<ref bean="defaultBulkAccessConditionConfiguration"/> | ||
</list> | ||
</property> | ||
</bean> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:util="http://www.springframework.org/schema/util" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd | ||
http://www.springframework.org/schema/context | ||
http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd" | ||
default-autowire-candidates="*Service,*DAO,javax.sql.DataSource"> | ||
|
||
<context:annotation-config/> | ||
<!-- allows us to use spring annotations in beans --> | ||
|
||
<util:map id="bibtexMetadataFieldMap" key-type="org.dspace.importer.external.metadatamapping.MetadataFieldConfig" | ||
value-type="org.dspace.importer.external.metadatamapping.contributor.MetadataContributor"> | ||
<description>Defines which metadatum is mapped on which metadatum. Note that while the key must be unique it | ||
only matters here for postprocessing of the value. The mapped MetadatumContributor has full control over | ||
what metadatafield is generated. | ||
</description> | ||
<entry key-ref="dcType" value-ref="bibtexTypeContrib" /> | ||
<entry key-ref="dcTitle" value-ref="bibtexTitleContrib" /> | ||
<entry key-ref="dcAuthors" value-ref="bibtexAuthorsContrib" /> | ||
<entry key-ref="dcJournal" value-ref="bibtexJournalContrib" /> | ||
<entry key-ref="dcIssued" value-ref="bibtexIssuedContrib" /> | ||
<entry key-ref="dcJissn" value-ref="bibtexJissnContrib" /> | ||
</util:map> | ||
|
||
<bean id="bibtexJissnContrib" class="org.dspace.importer.external.metadatamapping.contributor.SimpleMetadataContributor"> | ||
<property name="field" ref="dcJissn"/> | ||
<property name="key" value="ISSN" /> | ||
</bean> | ||
|
||
<bean id="bibtexIssuedContrib" class="org.dspace.importer.external.metadatamapping.contributor.SimpleMetadataContributor"> | ||
<property name="field" ref="dcIssued"/> | ||
<property name="key" value="year" /> | ||
</bean> | ||
|
||
<bean id="bibtexJournalContrib" class="org.dspace.importer.external.metadatamapping.contributor.SimpleMetadataContributor"> | ||
<property name="field" ref="dcJournal"/> | ||
<property name="key" value="journal" /> | ||
</bean> | ||
|
||
<bean id="bibtexAuthorsContrib" class="org.dspace.importer.external.metadatamapping.contributor.SplitMetadataContributor"> | ||
<constructor-arg name="innerContributor"> | ||
<bean class="org.dspace.importer.external.metadatamapping.contributor.SimpleMetadataContributor"> | ||
<property name="field" ref="dcAuthors"/> | ||
<property name="key" value="author" /> | ||
</bean> | ||
</constructor-arg> | ||
<constructor-arg name="regex" value="\sand\s"/> | ||
</bean> | ||
|
||
<bean id="bibtexTitleContrib" class="org.dspace.importer.external.metadatamapping.contributor.SimpleMetadataContributor"> | ||
<property name="field" ref="dcTitle"/> | ||
<property name="key" value="title" /> | ||
</bean> | ||
|
||
<bean id="bibtexTypeContrib" class="org.dspace.importer.external.metadatamapping.contributor.SimpleMetadataContributor"> | ||
<property name="field" ref="dcType"/> | ||
<property name="key" value="type" /> | ||
</bean> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-lazy-init="true"> | ||
|
||
<bean name="org.dspace.storage.bitstore.BitstreamStorageService" class="org.dspace.storage.bitstore.BitstreamStorageServiceImpl"> | ||
<property name="incoming" value="${assetstore.index.primary}"/> | ||
<property name="stores"> | ||
<map> | ||
<entry key="0" value-ref="localStore"/> | ||
<entry key="1" value-ref="s3Store"/> | ||
</map> | ||
</property> | ||
</bean> | ||
|
||
<bean name="localStore" class="org.dspace.storage.bitstore.DSBitStoreService" scope="singleton"> | ||
<property name="baseDir" value="${assetstore.dir}"/> | ||
</bean> | ||
|
||
<bean name="s3Store" class="org.dspace.storage.bitstore.S3BitStoreService" scope="singleton" lazy-init="true"> | ||
<property name="enabled" value="${assetstore.s3.enabled}"/> | ||
<!-- AWS Security credentials, with policies for specified bucket --> | ||
<property name="awsAccessKey" value="${assetstore.s3.awsAccessKey}"/> | ||
<property name="awsSecretKey" value="${assetstore.s3.awsSecretKey}"/> | ||
<property name="useRelativePath" value="${assetstore.s3.useRelativePath}"/> | ||
|
||
<!-- S3 bucket name to store assets in. example: longsight-dspace-auk --> | ||
<property name="bucketName" value="${assetstore.s3.bucketName}"/> | ||
|
||
<!-- AWS S3 Region to use: {us-east-1, us-west-1, eu-west-1, eu-central-1, ap-southeast-1, ... } --> | ||
<!-- Optional, sdk default is us-east-1 --> | ||
<property name="awsRegionName" value="${assetstore.s3.awsRegionName}"/> | ||
|
||
<!-- Subfolder to organize assets within the bucket, in case this bucket is shared --> | ||
<!-- Optional, default is root level of bucket --> | ||
<property name="subfolder" value="${assetstore.s3.subfolder}"/> | ||
</bean> | ||
|
||
<!-- <bean name="localStore2 ... --> | ||
<!-- <bean name="s3Store2 ... --> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:cache="http://www.springframework.org/schema/cache" | ||
xmlns:p="http://www.springframework.org/schema/p" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/cache | ||
http://www.springframework.org/schema/cache/spring-cache.xsd"> | ||
|
||
<cache:annotation-driven /> | ||
<bean id="cacheManager" class="org.springframework.cache.jcache.JCacheCacheManager"> | ||
<property name="cacheManager"> | ||
<bean class="org.springframework.cache.jcache.JCacheManagerFactoryBean"> | ||
<property name="cacheManagerUri" value="file:${dspace.dir}/config/ehcache.xml"/> | ||
</bean> | ||
</property> | ||
</bean> | ||
|
||
</beans> |
Oops, something went wrong.