Skip to content

Commit

Permalink
Bugfix for missing Listener autostart in systemd
Browse files Browse the repository at this point in the history
The old dotprofile environment scripts were remove in 2022.
They were replaced by ocenv but still nbeeded by manage_oracle_rdbms_procs.s
for a mapping of listener to ORACLE_HOME.

The dotprofiles are back again with ocenv as environment switcher.
  • Loading branch information
Rendanic committed Jul 18, 2023
1 parent 452a594 commit 4d5c90a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelogs/fragments/manage_oracle_rdbms_procs.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
bugfixes:
- "oraswdb_install: shellchecker for manage_oracle_rdbms_procs.sh (oravirt#358)"
- "Bugfix for missing Listener autostart in systemd (oravirt#358)"
2 changes: 1 addition & 1 deletion roles/oradb_manage_db/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
loop_var: dbh
label: " oracle_db_name={{ dbh.oracle_db_name | default('') }}"
when: oracle_databases is defined
tags: create_db,dbca,customdbcatemplate,dotprofile_db
tags: create_db,dbca,customdbcatemplate,dotprofile_db,listener2

- name: manage_db | Check if database is running
ansible.builtin.shell: ps -ef |grep pmon |grep -v grep
Expand Down
23 changes: 23 additions & 0 deletions roles/oradb_manage_db/tasks/manage-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,35 @@
{%- else -%}\
{{ oracle_base }}/{{ db_homes_config[dbh.home]['version'] }}/{{ db_homes_config[dbh.home]['home'] }}\
{%- endif -%}"
tags: always

- ansible.builtin.include_tasks: ocenv.yml # noqa name[missing]
when: deploy_ocenv
tags:
- always

# The systemd service needs an information for
# starting the listener from right home
# Mapping from listener to ORACLE_HOME is done with oracle_databases
# => use the old .profile_<DB_SID> for this
# => use the loop over oracle_databases
- name: listener | Deploy dotprofile for listener autostart
ansible.builtin.template:
src: dotprofile-db.j2
dest: >-
{{ oracle_user_home }}/.profile_{{ dbh.oracle_db_instance_name
| default(dbh.oracle_db_unique_name)
| default(dbh.oracle_db_name)}}
owner: "{{ oracle_user }}"
group: "{{ oracle_group }}"
mode: 0644
when: dbh.state | lower == 'present'
loop_control:
label: >-
db_name: {{ dbh.oracle_db_name | default('') }}
listener: {{ dbh.listener_name | default('') }}
tags: listener2

- ansible.builtin.debug:
msg: "Maintaining DB - {{ dbh.oracle_db_name }}, ORACLE_HOME - {{ oracle_home_db }}" # noqa name[missing]
run_once: "{{ configure_cluster }}"
Expand Down
26 changes: 26 additions & 0 deletions roles/oradb_manage_db/templates/dotprofile-db.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#jinja2: trim_blocks:True
# {{ ansible_managed }}
#
. {{ oracle_user_home }}/dbenv/ocenv 2>&1 > /dev/null
myoraenv {{ dbh.oracle_db_instance_name
| default(dbh.oracle_db_unique_name)
| default(dbh.oracle_db_name) }} 2>&1 > /dev/null

{# Remove possible old LSNRNAME from environmet
Maybe we cannot set it because it is not defined for this database...
#}
unset LSNRNAME
{% if dbh.listener_name is defined %}
LSNRNAME={{ dbh.listener_name }}
export LSNRNAME
{% endif %}

{# create environemt variables when rman is configured in oracle_databases #}
{% if dbh.rman_jobs is defined %}
# setup some variables for oradb-rman
export RMANTNS_ADMIN={{ rman_tns_admin | default(dbh.rman_tns_admin | default(oracle_base + '/rman/network/admin')) }}
export RMANLOGDIR={{ rman_log_dir | default(dbh.rman_log_dir | default(oracle_base + '/rman/log/')) }}
export RMANSCRIPTDIR={{ rman_script_dir | default(dbh.rman_script_dir | default(oracle_base + '/rman/script')) }}
{% endif %}

export PATH=${ORACLE_BASE}/bin:${PATH}
20 changes: 17 additions & 3 deletions roles/oraswdb_install/files/manage_oracle_rdbms_procs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,22 @@ function start_database() {
echo "ORACLE_HOME: ${ORACLE_HOME}"
echo "ORACLE_SID : ${ORACLE_SID}"

# set PFILEDIR as default
# => will be replaced when readonly home ist used
PFILEDIR="${ORACLE_HOME}/dbs"

# Do we have a potential readonly Home?
if test -f "${ORACLE_HOME}/install/orabasetab" ; then
# we could check for a readonly home
# shellcheck disable=SC2046
if [ ! $("${ORACLE_HOME}/bin/orabasehome") = "${ORACLE_HOME}" ] ; then
# readonly Home
PFILEDIR=$("$ORACLE_HOME/bin/orabaseconfig")/dbs
fi
fi

# Check for SPFile/PFile
test -f "${ORACLE_HOME}/dbs/spfile${ORACLE_SID}.ora" || test -f "${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora"
test -f "${PFILEDIR}/spfile${ORACLE_SID}.ora" || test -f "${PFILEDIR}/init${ORACLE_SID}.ora"
# shellcheck disable=2181
if [ "${?}" -ne 0 ] ; then
echo "no parameter file found."
Expand All @@ -123,7 +137,7 @@ function start_database() {

fi

if [ "${STARTDB:-'N'}" = "Y" ] ; then
if [ "${STARTDB:-N}" = "Y" ] ; then

# Using RMAN for startup
# => easy to switch from mount to open for running instance during execution
Expand Down Expand Up @@ -227,7 +241,7 @@ function do_sidline() {
if test -f "${PROFILE_FILE}" ; then
# shellcheck source=/dev/null
. "${PROFILE_FILE}" > /dev/null
stop_database "${ORA_HOME}" "${ORA_SID}" "${global_dbmode:-'immediate'}"
stop_database "${ORA_HOME}" "${ORA_SID}" "${global_dbmode:-immediate}"
fi

if test -f "${PROFILE_FILE}" ; then
Expand Down

0 comments on commit 4d5c90a

Please sign in to comment.