Skip to content

Commit

Permalink
Add TNS Names Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-buchan committed Jan 20, 2025
1 parent 58243c7 commit 6a68668
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docker/oracle-observer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ RUN rm -rf /opt/aws

USER oracle:oinstall

COPY configure_tnsnames.sh /home/oracle/configure_tnsnames.sh
RUN chmod u+x /home/oracle/configure_tnsnames.sh
COPY dummyfile.txt /opt/response.txt

EXPOSE 8080

# Dummy command to keep container running during development
CMD ["/bin/bash","-c","while true; do cat /opt/response.txt | nc -l -p 8080; done"]
CMD ["/bin/bash","-c","/home/oracle/configure_tnsnames.sh; while true; do cat /opt/response.txt | nc -l -p 8080; done"]
62 changes: 62 additions & 0 deletions docker/oracle-observer/configure_tnsnames.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

. ~/.bash_profile

# Check if required environment variables are set
if [ -z "$PRIMARYDB_HOSTNAME" ]; then
echo "Error: PRIMARYDB_HOSTNAME is not set."
exit 1
fi

if [ -z "$DATABASE_PORT" ]; then
echo "Error: DATABASE_PORT is not set."
exit 1
fi

if [ -z "$DATABASE_NAME" ]; then
echo "Error: DATABASE_NAME is not set."
exit 1
fi

# Treat standby database environment variables as "none" if not set
STANDBYDB1_HOSTNAME=${STANDBYDB1_HOSTNAME:-none}
STANDBYDB2_HOSTNAME=${STANDBYDB2_HOSTNAME:-none}

# Path to tnsnames.ora file
tnsnames_file="${ORACLE_HOME}/network/admin/tnsnames.ora"

# Create the tnsnames.ora file
cat <<EOL > "$tnsnames_file"
$DATABASE_NAME =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = $PRIMARYDB_HOSTNAME)(PORT = $DATABASE_PORT))
(CONNECT_DATA =
(SERVICE_NAME = $DATABASE_NAME)
)
)
EOL

# Add standby databases if they exist
if [ "$STANDBYDB1_HOSTNAME" != "none" ]; then
cat <<EOL >> "$tnsnames_file"
${DATABASE_NAME}S1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = $STANDBYDB1_HOSTNAME)(PORT = $DATABASE_PORT))
(CONNECT_DATA =
(SERVICE_NAME = ${DATABASE_NAME}S1)
)
)
EOL
fi

if [ "$STANDBYDB2_HOSTNAME" != "none" ]; then
cat <<EOL >> "$tnsnames_file"
${DATABASE_NAME}S2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = $STANDBYDB2_HOSTNAME)(PORT = $DATABASE_PORT))
(CONNECT_DATA =
(SERVICE_NAME = ${DATABASE_NAME}S2)
)
)
EOL
fi

0 comments on commit 6a68668

Please sign in to comment.