Tuesday, June 21, 2022

Automatic start observer during instance startup/reboot

Observer plays critical role during automatic failover, but sometimes routine maintenance would restart the Linux instance running observer and causes observer in stopped after instance reboot. Here are scripts to start observer automatically during Linux OS startup.

Running observer in background requires Oracle wallet setup, refer to below 2 links for more details:

/home/oracle/start_observer.sh

#!/bin/bash

export PATH

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/client
export LD_LIBRARY_PATH=/u01/lib
export PATH=/u01/sqlcl/bin:$ORACLE_HOME/bin:$PATH

ObserverRunning=`ps -ef|grep dgmgrl|grep -v grep|wc -l`
# echo $ObserverRunning
if [[ $ObserverRunning -eq 1 ]]
then
         echo "Observer is already running"
else
dgmgrl  <<EOD
start observer in background logfile is '/tmp/observer.log' connect identifier is rds_custom_orcl_a;
EOD
fi

/etc/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

su - oracle -c "nohup /home/oracle/start_observer.sh &" 

Make sure change these scripts to be *executable".

chmod +x /home/oracle/start_observer.sh
chmod +x /etc/rc.local 

No comments:

Post a Comment