A systemd service define an application than can be managed by systemd, thus it enables you to start your database on linux boot and also to shut it down on linux shutdown.
Furthermore it allows other systemd services to wait for your database is started on linux boot.
The helper files
Create a directory scripts inside /home/oracle
Create a file setEnv.sh
# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=$HOSTNAME
export ORACLE_UNQNAME=cdb1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.3.0/dbhome_1
export ORA_INVENTORY=/u01/app/oraInventory
export ORACLE_SID=YOUR_ORACLE_SID
export PDB_NAME=mypdb1
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
Modify these to respect your oracle installation (modify ORACLE_BASE, ORA_INVENTORY, …).
Then create a file start_all.sh
#!/bin/bash
. /home/oracle/.bash_profile
/home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
oraenv
export ORAENV_ASK=YES
dbstart $ORACLE_HOME
Now create a file stop_all.sh
!/bin/bash
. /home/oracle/.bash_profile
/home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
oraenv
export ORAENV_ASK=YES
dbshut $ORACLE_HOME
The systemd service
Create a file dbora.service inside /etc/systemd/system/
[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
$> systemctl enable dbora
Don’t try systemctl start dbora
Because it won’t fully work, if you dig inside the oracle script dbstart that is called by start_all.sh you’ll read that this script should only be called a linux boot.
Consequently, to try your service reboot your linux OS.
Start another systemd service after my oracle database is started
In your service description, specify dbora.service inside the “After” field present in the unit part as described here:
[Unit]
Description=Your service description
After=syslog.target network.target dbora.service
[Service]
...
[Install]
...
Leave a Reply