forked from webdizz/docker-oracle-xe-11g-sa
-
Notifications
You must be signed in to change notification settings - Fork 8
/
entrypoint.sh
94 lines (80 loc) · 3.93 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
#!/bin/bash
# Prevent owner issues on mounted folders
chown -R oracle:dba /u01/app/oracle
rm -f /u01/app/oracle/product
ln -s /u01/app/oracle-product /u01/app/oracle/product
# Update hostname
sed -i -E "s/HOST = [^)]+/HOST = $HOSTNAME/g" /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
sed -i -E "s/PORT = [^)]+/PORT = 1521/g" /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe" > /etc/profile.d/oracle-xe.sh
echo "export PATH=\$ORACLE_HOME/bin:\$PATH" >> /etc/profile.d/oracle-xe.sh
echo "export ORACLE_SID=XE" >> /etc/profile.d/oracle-xe.sh
. /etc/profile
case "$1" in
'')
#Check for mounted database files
if [ "$(ls -A /u01/app/oracle/oradata)" ]; 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
chown 664 /etc/oratab
printf "ORACLE_DBENABLED=false\nLISTENER_PORT=1521\nHTTP_PORT=8080\nCONFIGURE_RUN=true\n" > /etc/default/oracle-xe
rm -rf /u01/app/oracle-product/11.2.0/xe/dbs
ln -s /u01/app/oracle/dbs /u01/app/oracle-product/11.2.0/xe/dbs
else
echo "Database not initialized. Initializing database."
printf "Setting up:\nprocesses=$processes\nsessions=$sessions\ntransactions=$transactions\n"
echo "If you want to use different parameters set processes, sessions, transactions env variables and consider this formula:"
printf "processes=x\nsessions=x*1.1+5\ntransactions=sessions*1.1\n"
mv /u01/app/oracle-product/11.2.0/xe/dbs /u01/app/oracle/dbs
ln -s /u01/app/oracle/dbs /u01/app/oracle-product/11.2.0/xe/dbs
#Setting up processes, sessions, transactions.
sed -i -E "s/processes=[^)]+/processes=$processes/g" /u01/app/oracle/product/11.2.0/xe/config/scripts/init.ora
sed -i -E "s/processes=[^)]+/processes=$processes/g" /u01/app/oracle/product/11.2.0/xe/config/scripts/initXETemp.ora
sed -i -E "s/sessions=[^)]+/sessions=$sessions/g" /u01/app/oracle/product/11.2.0/xe/config/scripts/init.ora
sed -i -E "s/sessions=[^)]+/sessions=$sessions/g" /u01/app/oracle/product/11.2.0/xe/config/scripts/initXETemp.ora
sed -i -E "s/transactions=[^)]+/transactions=$transactions/g" /u01/app/oracle/product/11.2.0/xe/config/scripts/init.ora
sed -i -E "s/transactions=[^)]+/transactions=$transactions/g" /u01/app/oracle/product/11.2.0/xe/config/scripts/initXETemp.ora
printf 8080\\n1521\\noracle\\noracle\\ny\\n | /etc/init.d/oracle-xe configure
echo "Database initialized. Please visit http://#containeer:8080/apex to proceed with configuration"
fi
/etc/init.d/oracle-xe start
echo "Database ready to use. Enjoy! ;)"
if [ "$SCHEMAS" == "" ]; then
echo "If you want to create DBs automatically specify SCHEMAS environment variable";
else
for db in ${SCHEMAS} ; do
if [ -f "/db.${db}" ];
then
echo "User ${db} already exists"
else
echo "Is about to create schema: $db"
cp /u01/scripts/template.schema.sql /u01/scripts/$db.schema.sql
sed -i -E "s/TEMPLATE_USER/$db/g" /u01/scripts/$db.schema.sql
sqlplus -S system/oracle@localhost @/u01/scripts/$db.schema.sql
touch "/db.${db}"
fi
done
fi
## Execute all sql scripts in batch folder with parameters
if [ "$BATCH_PARAMS" == "" ]; then
echo "Executing scripts in batch folder with no parameters... ";
else
echo "Executing scripts in batch folder with parameters: [" $BATCH_PARAMS "] ...";
fi
ls -1 -Q /u01/scripts/batch/*.sql |sed 's/\(.\)/@@&/' > /u01/scripts/batch.sql
echo "exit;" >> /u01/scripts/batch.sql && echo "" >> /u01/scripts/batch.sql
sqlplus -S system/oracle@localhost @/u01/scripts/batch.sql $BATCH_PARAMS
##
## Workaround for graceful shutdown. ....ing oracle... ‿( ́ ̵ _-`)‿
##
while [ "$END" == '' ]; do
sleep 1
trap "/etc/init.d/oracle-xe stop && END=1" INT TERM
done
;;
*)
echo "Database is not configured. Please run /etc/init.d/oracle-xe configure if needed."
$1
;;
esac