Last active
February 13, 2021 17:50
-
-
Save ilmarkerm/30fa6f8935329bcf01d720379eafcb6d to your computer and use it in GitHub Desktop.
Managing Oracle database single instance listener from SystemD (properly)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This scripts parses the output from "lsnrctl show pid" and prints it either to screen to file | |
# Intended for "small" deployments where listener is started from RDBMS_HOME via systemd (not GI!) | |
# In unit file refferred as /home/oracle/bin/get_listener_pid.sh | |
# 2020 Ilmar Kerm | |
if [ -z "$ORACLE_HOME" ]; then | |
echo "ORACLE_HOME environment variable is missing" | |
exit 1 | |
fi | |
if [ -z "$TNS_ADMIN" ]; then | |
echo "TNS_ADMIN environment variable is missing" | |
exit 1 | |
fi | |
$ORACLE_HOME/bin/lsnrctl show pid > /tmp/lsnrctl_show_pid.out | |
# If lsnrctl returned an error | |
# Remove pidfile and display an error | |
if [ $? -ne 0 ]; then | |
[[ -n "$1" && -f "$1" ]] && rm "$1" | |
echo "*** lsnrctl show pid returned an error" | |
cat /tmp/lsnrctl_show_pid.out | |
exit 1 | |
fi | |
# Get the actual pid from output | |
listenerpid=$(grep PID= /tmp/lsnrctl_show_pid.out | awk -F"[()]" '{print $2}') | |
# Write pid to file or standard output | |
if [ -n "$1" ]; then | |
echo "$listenerpid" > "$1" | |
else | |
echo "$listenerpid" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place under /etc/systemd/system/oracle-listener.service | |
[Unit] | |
Description=The Oracle Database Listener | |
After=syslog.target network.target | |
[Service] | |
LimitNPROC=131072 | |
LimitNOFILE=131072 | |
LimitMEMLOCK=5525094 | |
Type=forking | |
User=oracle | |
Group=oinstall | |
Restart=on-abnormal | |
RestartSec=5 | |
Environment=ORACLE_HOME=/u01/app/oracle/product/19-clean-19081 | |
Environment=LD_LIBRARY_PATH=/u01/app/oracle/product/19-clean-19081/lib | |
Environment=ORACLE_BASE=/u01/app/oracle | |
Environment=TNS_ADMIN=/u01/app/oracle/network | |
WorkingDirectory=/tmp | |
ExecStart=/bin/bash -c '/u01/app/oracle/product/19-clean-19081/bin/lsnrctl start && /home/oracle/bin/get_listener_pid.sh /u01/app/oracle/network/listener.pid' | |
ExecStop=/bin/bash -c '/u01/app/oracle/product/19-clean-19081/bin/lsnrctl stop && rm /u01/app/oracle/network/listener.pid' | |
PIDFile=/u01/app/oracle/network/listener.pid | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment