Ubuntu and Oracle

# see also https://wiki.centos.org/HowTos/Oracle12onCentos7
# see also https://adrhc.go.ro/wordpress/centos-and-oracle/

# Follow this (works with Ubuntu 16.04 too):
# http://www.techienote.com/install-oracle-12c-on-ubuntu/

# systemd oracle.service (working when only one db is automatically started with /etc/oratab)
[Unit]
Description=Oracle 12c
After=local-fs.target
Wants=local-fs.target

[Service]
Type=forking

User=oracle
Group=oinstall

RuntimeDirectory=oracle
PIDFile=/run/oracle/oracle.pid

Restart=on-failure
RestartSec=3

TimeoutSec=0

ExecStart=/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart /u01/app/oracle/product/12.1.0/dbhome_1
ExecStop=/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbshut /u01/app/oracle/product/12.1.0/dbhome_1

[Install]
WantedBy=multi-user.target

# modify dbstart and dbshut in order to create /run/oracle/oracle.pid needed by oracle.service
# /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart
startinst() {
...
      if [ $? -eq 0 ] ; then
        echo "" 
		OS_PID=$(sqlplus -S / AS SYSDBA <<EOF
select SPID from v\$process where PNAME = 'PMON';
EOF
)
		OS_PID=$(echo "$OS_PID" | /bin/grep -P "\d+")
        echo "$0: ${INST} \"${ORACLE_SID}\" warm started (PID $OS_PID)." 
		if [ -d /run/oracle ]; then
			echo "$OS_PID" > /run/oracle/oracle.pid
			echo "created /run/oracle/oracle.pid"
		fi
      else
        $LOGMSG "" 
        $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOT started." 
      fi
# /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbshut
  if test $? -eq 0 ; then
	if [ -f /run/oracle/oracle.pid ]; then
		# see /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart
		rm -fv /run/oracle/oracle.pid
	fi
    echo "${INST} \"${ORACLE_SID}\" shut down."
  else
    echo "${INST} \"${ORACLE_SID}\" not shut down."
  fi

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.