forked from MaksymBilenko/docker-oracle-12c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·161 lines (138 loc) · 5.94 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
set -e
# Prevent owner issues on mounted folders, if desired
if [ "$ENABLE_OWNERSHIP_FIX" = true ] ; then
chown -R oracle:dba /u01/app/oracle
chown -R oracle:dba /docker-entrypoint-initdb.d/
fi
rm -f /u01/app/oracle/product
ln -s /u01/app/oracle-product /u01/app/oracle/product
#Run Oracle root scripts
/u01/app/oraInventory/orainstRoot.sh > /dev/null 2>&1
echo | /u01/app/oracle/product/12.1.0/xe/root.sh > /dev/null 2>&1 || true
if [ -z "$CHARACTER_SET" ]; then
if [ "${USE_UTF8_IF_CHARSET_EMPTY}" == "true" ]; then
export CHARACTER_SET="AL32UTF8"
fi
fi
if [ -n "$CHARACTER_SET" ]; then
export CHARSET_MOD="NLS_LANG=.$CHARACTER_SET"
export CHARSET_INIT="-characterSet $CHARACTER_SET"
fi
impdp () {
set +e
DUMP_FILE=$(basename "$1")
DUMP_NAME=${DUMP_FILE%.dmp}
cat > /tmp/impdp.sql << EOL
-- Impdp User
CREATE USER IMPDP IDENTIFIED BY IMPDP;
ALTER USER IMPDP ACCOUNT UNLOCK;
GRANT dba TO IMPDP WITH ADMIN OPTION;
-- New Scheme User
create or replace directory IMPDP as '/docker-entrypoint-initdb.d';
create tablespace $DUMP_NAME datafile '/u01/app/oracle/oradata/$DUMP_NAME.dbf' size 1000M autoextend on next 100M maxsize unlimited;
create user $DUMP_NAME identified by $DUMP_NAME default tablespace $DUMP_NAME;
alter user $DUMP_NAME quota unlimited on $DUMP_NAME;
alter user $DUMP_NAME default role all;
grant connect, resource to $DUMP_NAME;
exit;
EOL
su oracle -c "$CHARSET_MOD $ORACLE_HOME/bin/sqlplus -S / as sysdba @/tmp/impdp.sql"
su oracle -c "$CHARSET_MOD $ORACLE_HOME/bin/impdp IMPDP/IMPDP directory=IMPDP dumpfile=$DUMP_FILE $IMPDP_OPTIONS"
#Disable IMPDP user
echo -e 'ALTER USER IMPDP ACCOUNT LOCK;\nexit;' | su oracle -c "$CHARSET_MOD $ORACLE_HOME/bin/sqlplus -S / as sysdba"
set -e
}
case "$1" in
'')
#Check for mounted database files
if [ "$(ls -A /u01/app/oracle/oradata 2>/dev/null)" ]; then
echo "Found files in /u01/app/oracle/oradata Using them instead of initial database"
echo "XE:$ORACLE_HOME:N" >> /etc/oratab
chown oracle:dba /etc/oratab
chmod 664 /etc/oratab
rm -rf /u01/app/oracle-product/12.1.0/xe/dbs
ln -s /u01/app/oracle/dbs /u01/app/oracle-product/12.1.0/xe/dbs
#Startup Database
su oracle -c "/u01/app/oracle/product/12.1.0/xe/bin/tnslsnr &"
su oracle -c 'echo startup\; | $ORACLE_HOME/bin/sqlplus -S / as sysdba'
else
echo "Database not initialized. Initializing database."
export IMPORT_FROM_VOLUME=true
#printf "Setting up:\nprocesses=$processes\nsessions=$sessions\ntransactions=$transactions\n"
set +e
mv /u01/app/oracle-product/12.1.0/xe/dbs /u01/app/oracle/dbs
set -e
ln -s /u01/app/oracle/dbs /u01/app/oracle-product/12.1.0/xe/dbs
echo "Starting tnslsnr"
su oracle -c "/u01/app/oracle/product/12.1.0/xe/bin/tnslsnr &"
#create DB for SID: xe
su oracle -c "$ORACLE_HOME/bin/dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname xe -sid xe -responseFile NO_VALUE $CHARSET_INIT -totalMemory $DBCA_TOTAL_MEMORY -emConfiguration LOCAL -pdbAdminPassword oracle -sysPassword oracle -systemPassword oracle"
echo "Configuring Apex console"
cd $ORACLE_HOME/apex
su oracle -c 'echo -e "0Racle$\n8080" | $ORACLE_HOME/bin/sqlplus -S / as sysdba @apxconf > /dev/null'
su oracle -c 'echo -e "${ORACLE_HOME}\n\n" | $ORACLE_HOME/bin/sqlplus -S / as sysdba @apex_epg_config_core.sql > /dev/null'
su oracle -c 'echo -e "ALTER USER ANONYMOUS ACCOUNT UNLOCK;" | $ORACLE_HOME/bin/sqlplus -S / as sysdba > /dev/null'
echo "Database initialized. Please visit http://#containeer:8080/em http://#containeer:8080/apex for extra configuration if needed"
if [ "$INSTALL_UTPLSQL" == true ]; then
cd /tmp
echo "[utPLSQL] Download..."
curl -LOk $(curl --silent https://api.github.com/repos/utPLSQL/utPLSQL/releases/latest | awk '/browser_download_url/ { print $2 }' | grep ".zip" | sed 's/"//g')
echo "[utPLSQL] Uncompress file..."
unzip -q utPLSQL.zip
echo "[utPLSQL] Set permission..."
chown oracle:dba utPLSQL -R
echo "[utPLSQL] Starting Installation..."
cd utPLSQL/source/
su oracle -c "$ORACLE_HOME/bin/sqlplus -S / as sysdba @install_headless.sql"
if [ "$CREATE_UT_USER" == true ]; then
su oracle -c "$ORACLE_HOME/bin/sqlplus -S / as sysdba @create_utplsql_owner.sql ut_user ut_user users"
else
echo "[CREATE_UT_USER] If you want create UT_USER - add 'CREATE_UT_USER=true' variable"
echo
fi
else
echo "[utPLSQL] If you want to install utPLSQL framework - add 'INSTALL_UTPLSQL=true' variable"
echo
fi
fi
if [ "$WEB_CONSOLE" == "true" ]; then
echo 'Starting web management console'
su oracle -c 'echo EXEC DBMS_XDB.sethttpport\(8080\)\; | $ORACLE_HOME/bin/sqlplus -S / as sysdba'
else
echo 'Disabling web management console'
su oracle -c 'echo EXEC DBMS_XDB.sethttpport\(0\)\; | $ORACLE_HOME/bin/sqlplus -S / as sysdba'
fi
if [ "$IMPORT_FROM_VOLUME" == true ]; then
echo "Starting import from '/docker-entrypoint-initdb.d':"
for f in $(ls /docker-entrypoint-initdb.d/*); do
echo "found file $f"
case "$f" in
*.sh) echo "[IMPORT] $0: running $f"; . "$f" ;;
*.sql) echo "[IMPORT] $0: running $f"; echo "exit" | su oracle -c "$CHARSET_MOD $ORACLE_HOME/bin/sqlplus -S / as sysdba @$f"; echo ;;
*.dmp) echo "[IMPORT] $0: running $f"; impdp $f ;;
*) echo "[IMPORT] $0: ignoring $f" ;;
esac
echo
done
echo "Import finished"
echo
else
echo "[IMPORT] Not a first start, SKIPPING Import from Volume '/docker-entrypoint-initdb.d'"
echo "[IMPORT] If you want to enable import at any state - add 'IMPORT_FROM_VOLUME=true' variable"
echo
fi
echo "Database ready to use. Enjoy! ;)"
##
## Workaround for graceful shutdown.
##
while [ "$END" == '' ]; do
sleep 1
trap "su oracle -c 'echo shutdown immediate\; | $ORACLE_HOME/bin/sqlplus -S / as sysdba'" INT TERM
done
;;
*)
echo "Database is not configured. Please run '/entrypoint.sh' if needed."
exec "$@"
;;
esac