Skip to content

Instantly share code, notes, and snippets.

@adriasir123
Created October 26, 2022 15:45
Show Gist options
  • Save adriasir123/5a0d4930806ce3e7192395483b33b132 to your computer and use it in GitHub Desktop.
Save adriasir123/5a0d4930806ce3e7192395483b33b132 to your computer and use it in GitHub Desktop.
Config file modified needed to compile Oracle 19c on Debian 11
#!/bin/bash
#
# chkconfig: 2345 80 05
# Description: This script is responsible for taking care of configuring the Oracle Database and its associated services.
#
# processname: oracledb_ORCLCDB-19c
# Red Hat or SuSE config: /etc/sysconfig/oracledb_ORCLCDB-19c
#
# Set path if path not set
case $PATH in
"") PATH=/bin:/usr/bin:/sbin:/etc
export PATH ;;
esac
# Check if the root user is running this script
if [ $(id -u) != "0" ]
then
echo "You must be root user to run the configurations script. Login as root user and try again."
exit 1
fi
# Setting the required environment variables
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export ORACLE_VERSION=19c
export ORACLE_SID=ORCLCDB
export TEMPLATE_NAME=General_Purpose.dbc
export CHARSET=AL32UTF8
export PDB_NAME=ORCLPDB1
export LISTENER_NAME=LISTENER
export NUMBER_OF_PDBS=1
export CREATE_AS_CDB=true
# General exports and vars
export PATH=$ORACLE_HOME/bin:$PATH
LSNR=$ORACLE_HOME/bin/lsnrctl
SQLPLUS=$ORACLE_HOME/bin/sqlplus
DBCA=$ORACLE_HOME/bin/dbca
NETCA=$ORACLE_HOME/bin/netca
ORACLE_OWNER=oracle
RETVAL=0
CONFIG_NAME="oracledb_$ORACLE_SID-$ORACLE_VERSION.conf"
CONFIGURATION="/etc/sysconfig/$CONFIG_NAME"
# Commands
if [ -z "$SU" ];then SU=/bin/su; fi
if [ -z "$GREP" ]; then GREP=/usr/bin/grep; fi
if [ ! -f "$GREP" ]; then GREP=/bin/grep; fi
# To start the DB
start()
{
check_for_configuration
RETVAL=$?
if [ $RETVAL -eq 1 ]
then
echo "The Oracle Database is not configured. You must run '/etc/init.d/oracledb_$ORACLE_SID-$ORACLE_VERSION configure' as the root user to configure the database."
exit
fi
# Check if the DB is already started
pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | $GREP -v grep`
if [ "$pmon" = "" ];
then
# Unset the proxy env vars before calling sqlplus
unset_proxy_vars
echo "Starting Oracle Net Listener."
$SU -s /bin/bash $ORACLE_OWNER -c "$LSNR start $LISTENER_NAME" > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
echo "Oracle Net Listener started."
fi
echo "Starting Oracle Database instance $ORACLE_SID."
$SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog << EOF
connect / as sysdba
startup
alter pluggable database all open
exit;
EOF" > /dev/null 2>&1
RETVAL1=$?
if [ $RETVAL1 -eq 0 ]
then
echo "Oracle Database instance $ORACLE_SID started."
fi
else
echo "The Oracle Database instance $ORACLE_SID is already started."
exit 0
fi
echo
if [ $RETVAL -eq 0 ] && [ $RETVAL1 -eq 0 ]
then
return 0
else
echo "Failed to start Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr and Oracle Database using $ORACLE_HOME/bin/sqlplus."
exit 1
fi
}
# To stop the DB
stop()
{
check_for_configuration
RETVAL=$?
if [ $RETVAL -eq 1 ]
then
echo "The Oracle Database is not configured. You must run '/etc/init.d/oracledb_$ORACLE_SID-$ORACLE_VERSION configure' as the root user to configure the database."
exit 1
fi
# Check if the DB is already stopped
pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | $GREP -v grep`
if [ "$pmon" = "" ]
then
echo "Oracle Database instance $ORACLE_SID is already stopped."
exit 1
else
# Unset the proxy env vars before calling sqlplus
unset_proxy_vars
echo "Shutting down Oracle Database instance $ORACLE_SID."
$SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog << EOF
connect / as sysdba
shutdown immediate
exit;
EOF" > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
echo "Oracle Database instance $ORACLE_SID shut down."
fi
echo "Stopping Oracle Net Listener."
$SU -s /bin/bash $ORACLE_OWNER -c "$LSNR stop $LISTENER_NAME" > /dev/null 2>&1
RETVAL1=$?
if [ $RETVAL1 -eq 0 ]
then
echo "Oracle Net Listener stopped."
fi
fi
echo
if [ $RETVAL -eq 0 ] && [ $RETVAL1 -eq 0 ]
then
return 0
else
echo "Failed to stop Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr and Oracle Database using $ORACLE_HOME/bin/sqlplus."
exit 1
fi
}
# To call DBCA to configure the DB
configure_perform()
{
# Unset the proxy env vars before calling dbca
unset_proxy_vars
echo "Configuring Oracle Database $ORACLE_SID."
$SU -s /bin/bash $ORACLE_OWNER -c "$DBCA -silent -createDatabase -gdbName $ORACLE_SID -templateName $TEMPLATE_NAME -characterSet $CHARSET -createAsContainerDatabase $CREATE_AS_CDB -numberOfPDBs $NUMBER_OF_PDBS -pdbName $PDB_NAME -createListener $LISTENER_NAME:$LISTENER_PORT -datafileDestination $ORACLE_DATA_LOCATION -sid $ORACLE_SID -autoGeneratePasswords -emConfiguration DBEXPRESS -emExpressPort $EM_EXPRESS_PORT -J-Doracle.assistants.dbca.validate.ConfigurationParams=false"
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]
then
echo "Database configuration completed successfully. The passwords were auto generated, you must change them by connecting to the database using 'sqlplus / as sysdba' as the oracle user."
return 0
else
echo "Database configuration failed."
exit 1
fi
}
# Enh 27965939 - Unsets the proxy env variables
unset_proxy_vars()
{
if [ "$http_proxy" != "" ]
then
unset http_proxy
fi
if [ "$HTTP_PROXY" != "" ]
then
unset HTTP_PROXY
fi
if [ "$https_proxy" != "" ]
then
unset https_proxy
fi
if [ "$HTTPS_PROXY" != "" ]
then
unset HTTPS_PROXY
fi
}
# Check if the DB is already configured
check_for_configuration()
{
configfile=`$GREP --no-messages $ORACLE_SID:$ORACLE_HOME /etc/oratab` > /dev/null 2>&1
if [ "$configfile" = "" ]
then
return 1
fi
return 0
}
read_config_file()
{
if [ -f "$CONFIGURATION" ]
then
. "$CONFIGURATION"
else
echo "The Oracle Database is not configured. Unable to read the configuration file '$CONFIGURATION'"
exit 1;
fi
}
# Entry point to configure the DB
configure()
{
check_for_configuration
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
echo "Oracle Database instance $ORACLE_SID is already configured."
exit 1
fi
read_config_file
check_port_availability
check_em_express_port_availability
configure_perform
}
check_port_availability()
{
port=`netstat -n --tcp --listen | $GREP :$LISTENER_PORT`
if [ "$port" != "" ]
then
echo "Port $LISTENER_PORT appears to be in use by another application. Specify a different port in the configuration file '$CONFIGURATION'"
exit 1;
fi
}
# Validation method to check for port availability for Oracle EM Express
check_em_express_port_availability()
{
port=`netstat -n --tcp --listen | $GREP :$EM_EXPRESS_PORT`
if [ "$port" != "" ]
then
echo "Port $EM_EXPRESS_PORT appears to be in use by another application. Specify a different Oracle EM Express port in the configuration file '$CONFIGURATION'"
exit 1;
fi
}
restart()
{
# Check if the DB is already stopped
pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | $GREP -v grep`
if [ "$pmon" = "" ]
then
start
else
stop
start
fi
}
configure_delete()
{
# Unset the proxy env vars before calling dbca and netca
unset_proxy_vars
ORABASE=`$ORACLE_HOME/bin/orabase`
NETCA_LOG_DIR="$ORABASE/cfgtoollogs/netca"
LSNR_CONFIG_FILE="$ORACLE_HOME/network/admin/listener.ora"
if [ ! -d "$NETCA_LOG_DIR" ]
then
$SU -s /bin/bash $ORACLE_OWNER -c "$MKDIR_CMD -p $NETCA_LOG_DIR"
fi
NETCA_LOG="$NETCA_LOG_DIR/netca_deinst_out.log"
echo "Detecting existing Listeners..."
if [ -f "$LSNR_CONFIG_FILE" ]
then
NUMBER_OF_LISTENERS=`grep -w "DESCRIPTION_LIST" $LSNR_CONFIG_FILE | wc -l`
if [ "$NUMBER_OF_LISTENERS" == "1" ]
then
echo "Deleting Oracle Listener...."
$SU -s /bin/bash $ORACLE_OWNER -c "$LSNR stop $LISTENER_NAME" > /dev/null 2>&1
$SU -s /bin/bash $ORACLE_OWNER -c "$NETCA /deinst >>$NETCA_LOG"
else
if [ "$NUMBER_OF_LISTENERS" != "0" ]
then
echo "There were more Listeners detected. Verify and remove them manually so the service can be safely deleted"
exit
else
echo "No Listeners were detected. Proceeding with Database removal"
fi
fi
else
echo "No Listener configuration file found. Proceeding with Database removal"
fi
#Then proceed to remove the database
echo "Detecting existing Oracle Databases..."
check_for_configuration
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
echo "Deleting Oracle Database $ORACLE_SID."
$SU -s /bin/bash $ORACLE_OWNER -c "$DBCA -silent -deleteDatabase -sourceDB $ORACLE_SID -skipSYSDBAPasswordPrompt true"
else
echo "The Oracle Database is not configured. You must run '/etc/init.d/oracledb_$ORACLE_SID-@<DBNRMAJVSNLETTER_STR>@ configure' as the root user to configure the database"
exit
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
configure)
configure
;;
delete)
configure_delete
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart|configure|delete}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment