Bash

  1. Create a scripts directory.

›_ Console

# mkdir /home/oracle/scripts


  1. Create an environment file called setEnv.sh. The "$" characters are avoided by using "\". If you don't create the file with the cat command, you will need to remove the escape characters. Make sure to change the hostname accordingly.

›_ Console

# Oracle Settings cat > /home/oracle/scripts/setEnv.sh <<EOF

# Oracle Settings export TMP=/tmp export TMPDIR=\$TMP


export ORACLE_HOSTNAME=oraclelinux.localdomain export ORACLE_UNQNAME=orcl export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=\$ORACLE_BASE/product/19.0.0/dbhome_1 export ORA_INVENTORY=/u01/app/oraInventory export ORACLE_SID=orcl export PDB_NAME=pdb1 export DATA_DIR=/u02/oradata


export PATH=/usr/sbin:/usr/local/bin:\$PATH export PATH=\$ORACLE_HOME/bin:\$PATH


export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib export CLASSPATH=\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib

EOF


  1. Add the following lines at the end of the /home/oracle/.bash_profile file.

›_ Console

# Oracle set environment

. /home/oracle/scripts/setEnv.sh


  1. Create a start_all.sh and stop_all.sh script that can be called from a startup or shutdown service. Make sure the ownership and permissions are correct.

›_ Console

# chown -R oracle:oinstall /home/oracle/scripts

# chmod u+x /home/oracle/scripts/*.sh


cat > /home/oracle/scripts/start_all.sh <<EOF

#!/bin/bash

. /home/oracle/scripts/setEnv.sh


export ORAENV_ASK=NO

. oraenv

export ORAENV_ASK=YES


dbstart \$ORACLE_HOME

EOF


cat > /home/oracle/scripts/stop_all.sh <<EOF

#!/bin/bash

. /home/oracle/scripts/setEnv.sh


export ORAENV_ASK=NO

. oraenv

export ORAENV_ASK=YES


dbshut \$ORACLE_HOME

EOF



  1. Create a Linux service to automatically start or stop the database. Create the service file called dbora.service.

›_ Console

#nano /lib/systemd/system/dbora.service


  1. Add the following lines:

›_ Console

[Unit]

Description=The Oracle Database Service

After=syslog.target network.target


[Service]

# systemd ignores PAM limits, so set any necessary limits in the service.

# Not really a bug, but a feature.

# https://bugzilla.redhat.com/show_bug.cgi?id=754285

LimitMEMLOCK=infinity

LimitNOFILE=65535


#Type=simple

# idle: similar to simple, the actual execution of the service binary is delayed

#until all jobs are finished, which avoids mixing the status output with shell output of services.

RemainAfterExit=yes

User=oracle

Group=oinstall

Restart=no

ExecStart=/bin/bash -c '/home/oracle/scripts/start_all.sh'

ExecStop=/bin/bash -c '/home/oracle/scripts/stop_all.sh'


[Install]

WantedBy=multi-user.target



  1. Reload the system so it can see the new service.

›_ Console

# systemctl daemon-reload


  1. Start the service and enable it for an automatic restart on reboot.

›_ Console

# systemctl start dbora.service

# systemctl enable dbora.service

# systemctl status dbora.service


  1. Reboot the machine.