LLI Wiki — My Digital Knowledge Base

Start Oracle 12c automatically at boot with systemd on CentOS

Create systemd units so that the Oracle listener and database start at boot on CentOS, with their environment in a sysconfig file.

On CentOS, systemd can start the Oracle listener and the database at boot. Two unit files do this: one for lsnrctl, one for dbstart/dbshut. Their environment comes from a sysconfig file. The examples use the SID ORCL and an Oracle 12c home under /u1/app/oracle; adapt the paths to your installation.

1. Become root

sudo -i

2. Create the environment file

touch /etc/sysconfig/ORCL.oracledb
vi /etc/sysconfig/ORCL.oracledb
ORACLE_BASE=/u1/app/oracle
ORACLE_HOME=/u1/app/oracle/product/12.1.0/dbhome_1
ORACLE_SID=ORCL

3. Create the listener unit

touch /usr/lib/systemd/system/oracle-lsnrctl.service
vi /usr/lib/systemd/system/oracle-lsnrctl.service
[Unit]
Description=Oracle Net Listener
After=network.target

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/ORCL.oracledb
ExecStart=/u1/app/oracle/product/12.1.0/dbhome_1/bin/lsnrctl start
ExecStop=/u1/app/oracle/product/12.1.0/dbhome_1/bin/lsnrctl stop
User=oracle

[Install]
WantedBy=multi-user.target

4. Create the database unit

touch /usr/lib/systemd/system/oracle-db.service
vi /usr/lib/systemd/system/oracle-db.service
[Unit]
Description=Oracle Database service
After=network.target oracle-lsnrctl.service

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/ORCL.oracledb
ExecStart=/u1/app/oracle/product/12.1.0/dbhome_1/bin/dbstart $ORACLE_HOME
ExecStop=/u1/app/oracle/product/12.1.0/dbhome_1/bin/dbshut $ORACLE_HOME
User=oracle

[Install]
WantedBy=multi-user.target

5. Enable the units

systemctl daemon-reload
systemctl enable oracle-lsnrctl oracle-db
exit

6. Test and monitor

sudo reboot

sudo systemctl start oracle-lsnrctl oracle-db
sudo systemctl status oracle-lsnrctl oracle-db
sudo journalctl -u oracle-db
sudo journalctl -f
Mastodon LLIMastodon SocialFosstodon