My setup uses systemd Socket Activation which you can read more about on Lennart Poettering's website.
The following link has been used as a basis for that setup: systemd: on-demand start of services like postgresql and mysql that do not yet support socket-based activation.
I took Amazon Linux distribution for this demo with the following kernel: 4.14.123-111.109.amzn2.x86_64, however, the setup steps should be the same for any other Red Hat based distributions.
The Oracle Database version is 19.3.
In a nutshell, we need to create several systemd units:
1. /etc/systemd/system/proxy-to-oracle.socket:
1 2 3 4 5 6 7 8 9 | [Unit] Description= "Socket for Oracle Socket Proxy" [Socket] ListenStream=0.0.0.0:1522 [Install] WantedBy=sockets.target |
2. /etc/systemd/system/proxy-to-oracle.service:
1 2 3 4 5 6 7 8 9 10 11 12 | [Unit] Description= "Oracle Socket Proxy" Requires=dbora.service After =dbora.service [Service] User =nobody Group =nobody ExecStart=/lib/systemd/systemd-socket-proxyd ip-172-17-31-208.ec2.internal:1521 Restart= on -failure PrivateTmp= true |
There are After and Requires dependencies on dbora.service, which manages the database and the listener.
3. /etc/systemd/system/dbora.service:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [Unit] Description= "The Oracle Database Service" After =syslog.target network.target [Service] LimitMEMLOCK=infinity LimitNOFILE=65535 RemainAfterExit=yes User =oracle Group =dba ExecStart=/home/oracle/scripts/start_oracle.sh ExecStop=/u01/app/oracle/product/19/dbhome_1/bin/dbshut /u01/app/oracle/product/19/dbhome_1 [Install] WantedBy=multi- user .target |
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/sh export ORACLE_SID=orcl ORAENV_ASK= NO . /usr/ local /bin/oraenv -s sqlplus / as sysdba <<_EOF startup _EOF lsnrctl start sqlplus / as sysdba <<_EOF alter system register; _EOF |
1 2 3 4 5 6 7 8 9 10 11 | pdb = (DESCRIPTION= (RETRY_COUNT=10) (RETRY_DELAY=10) (ADDRESS= (PROTOCOL=TCP)(HOST=ip-172-17-31-208.ec2.internal)(PORT=1522) ) (CONNECT_DATA= (SERVICE_NAME=pdb) ) ) |
1 | DISABLE_OOB= ON |
1 2 3 4 5 6 7 8 9 10 11 12 | -- test_db_conn.sh #!/bin/sh export TNS_ADMIN= "${HOME}/tns_admin" echo "Started at: " $( date + "%F %T" ) sqlplus -L tc/tc@pdb <<_EOF select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss' ) current_date from dual; _EOF echo "" echo "Finished at: " $( date + "%F %T" ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # systemctl status proxy- to -oracle.socket proxy- to -oracle.service dbora.service ● proxy- to -oracle.socket - "Socket for Oracle Socket Proxy" Loaded: loaded (/etc/systemd/system/proxy- to -oracle.socket; enabled; vendor preset: disabled) Active: active (listening) since Thu 2019-08-08 13:31:19 UTC; 20h ago Listen: 0.0.0.0:1522 (Stream) ● proxy- to -oracle.service - "Oracle Socket Proxy" Loaded: loaded (/etc/systemd/system/proxy- to -oracle.service; static ; vendor preset: disabled) Active: inactive (dead) since Fri 2019-08-09 10:25:21 UTC; 3min 15s ago Process: 16042 ExecStart=/lib/systemd/systemd-socket-proxyd ip-172-17-31-208.ec2.internal:1521 (code=killed, signal=TERM) Main PID: 16042 (code=killed, signal=TERM) ● dbora.service - "The Oracle Database Service" Loaded: loaded (/etc/systemd/system/dbora.service; enabled; vendor preset: disabled) Active: inactive (dead) since Fri 2019-08-09 10:25:46 UTC; 2min 50s ago Process: 22234 ExecStop=/u01/app/oracle/product/19/dbhome_1/bin/dbshut /u01/app/oracle/product/19/dbhome_1 (code=exited, status=0/SUCCESS) Process: 16032 ExecStart=/home/oracle/scripts/start_oracle.sh (code=exited, status=0/SUCCESS) Main PID: 16032 (code=exited, status=0/SUCCESS) |
1 2 | [oracle@ip-172-17-31-208 ~]$ pgrep -af 'pmon|tnslsnr' [oracle@ip-172-17-31-208 ~]$ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | [oracle@ip-172-17-31-208 scripts]$ ./test_db_conn.sh Started at : 2019-08-09 10:32:53 SQL*Plus: Release 19.0.0.0.0 - Production on Fri Aug 9 10:32:53 2019 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. Last Successful login time : Fri Aug 09 2019 09:27:45 +00:00 Connected to : Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 SQL> 2 CURRENT_DATE ------------------- 2019-08-09 10:33:13 SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 Finished at : 2019-08-09 10:33:14 |
Комментариев нет:
Отправить комментарий
Примечание. Отправлять комментарии могут только участники этого блога.