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
Ensure most of the following lines are present in the .bash_profile of your oracle user (oracle user is the user you’ve used to install oracle server). Of course adapt the values to your oracle server.
export ORACLE_HOSTNAME=$HOSTNAME
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 # => The directory where your tablespace files are
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
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
export ORAENV_ASK=NO
oraenv
export ORAENV_ASK=YES
dbshut $ORACLE_HOME
Edit /etc/oratab
As explained by our Oracle god Burleson (http://www.dba-oracle.com/t_linux_dbstart_dbshut.htm) :
Oracle provides you with the scripts dbstart and dbshut to start and stop multiple databases on the system. As mentioned in earlier chapters, these scripts rely on the /etc/oratab file to determine what databases should be started.
Entries where the third field is Y are started when dbstart is run; entries with an N in this field are ignored by dbstart.
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 at 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