-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_entrypoint.sh
executable file
·129 lines (102 loc) · 4.27 KB
/
docker_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
#!/usr/bin/env bash
#set -x
ODOO_CONFIG_FILE="/opt/odoo/conf/odoo.conf"
ODOO_PORT=${ODOO_PORT:-8069}
ODOO_LONGPOOLING_PORT=${ODOO_LONGPOOLING_PORT:-8072}
PG_VERSION="${POSTGRES_VERSION:-12}"
PG_USER="${POSTGRES_USER:-postgres}"
PG_PASS="${POSTGRES_PASSWORD:-postgres}"
PG_PORT="${POSTGRES_PORT:-5432}"
if [ "${ODOO_DATABASE_HOSTNAME}" != "" ]; then
export PG_HOST="${ODOO_DATABASE_HOSTNAME}"
else
export PG_HOST="${ODOO_DB_HOST:-127.0.0.1}"
fi
ODOO_DATABASE_NAME="${ODOO_DATABASE_NAME:-odoo}"
ODOO_DATABASE_USERNAME="${ODOO_DATABASE_USERNAME:-odoo}"
ODOO_DATABASE_PASSWORD="${ODOO_DATABASE_PASSWORD:-odoo}"
# if it's the first time (initializing the container) ...
if [ ! -f /opt/odoo/conf/.initialized ]; then
export ODOO_EXTRA_ARGS="-i base"
echo -e "* Creating server config file ..."
touch $ODOO_CONFIG_FILE
echo "[options]" > $ODOO_CONFIG_FILE
echo "addons_path = /opt/odoo/odoo-server/addons,/opt/odoo/extra-addons" >> $ODOO_CONFIG_FILE
echo "data_dir = /opt/odoo/data" >> $ODOO_CONFIG_FILE
echo "db_host = $PG_HOST" >> $ODOO_CONFIG_FILE
echo "db_port = $PG_PORT" >> $ODOO_CONFIG_FILE
echo "db_user = $ODOO_DATABASE_USERNAME" >> $ODOO_CONFIG_FILE
echo "db_password = $ODOO_DATABASE_PASSWORD" >> $ODOO_CONFIG_FILE
echo "http_port = $ODOO_PORT"
echo "xmlrpc_port = ${ODOO_PORT}" >> $ODOO_CONFIG_FILE
echo "longpolling_port = $ODOO_LONGPOOLING_PORT" >> $ODOO_CONFIG_FILE
chmod 640 $ODOO_CONFIG_FILE
chown -fR odoo:odoo /opt/odoo/conf
chown -fR odoo:odoo /opt/odoo/extra-addons
chown -fR odoo:odoo /opt/odoo/logs
chown -fR odoo:odoo /opt/odoo/data
# initialize the database if running locally and with root user
if [ "${PG_HOST}" == "127.0.0.1" ] || [ "${PG_HOST}" == "localhost" ] ; then
if [ "$(id -u)" == "0" ]; then
pg_ctlcluster $PG_VERSION main start
touch /tmp/.pg_started
su - postgres -c "psql <<-EOF
CREATE USER $ODOO_DATABASE_USERNAME with superuser;
ALTER USER $ODOO_DATABASE_USERNAME with password '$ODOO_DATABASE_PASSWORD';
EOF
"
fi
fi
# initialize the database if it's empty
PGPASSWORD=$ODOO_DATABASE_PASSWORD psql -U $ODOO_DATABASE_USERNAME -d $ODOO_DATABASE_NAME -c "SELECT 1 from res_users where id = 1" > /dev/null 2>&1
if [ "$?" != "0" ]; then
if [ "$(id -u)" == "0" ]; then
su - odoo -c "source /opt/odoo/.profile ; python3 /opt/odoo/odoo-server/odoo-bin --config=/opt/odoo/conf/odoo.conf -i base -d $ODOO_DATABASE_NAME --stop-after-init"
else
python3 /opt/odoo/odoo-server/odoo-bin --config=/opt/odoo/conf/odoo.conf -i base -d $ODOO_DATABASE_NAME --stop-after-init
fi
fi
echo "--------------------------- Odoo database initialized! ----------------------------------"
touch /opt/odoo/conf/.initialized
else
if [ "${PG_HOST}" == "127.0.0.1" ] || [ "${PG_HOST}" == "localhost" ] ; then
if [ "$(id -u)" == "0" ]; then
pg_ctlcluster "$PG_VERSION" main start
fi
fi
fi
# check if is necessary to install any additional library
install_requirements=0
if [ -f /opt/odoo/extra-addons/requirements.txt ]; then
if [ ! -f /opt/odoo/extra-addons-requirements.txt.sha ]; then
export install_requirements=1
else
last_sha_sum=$(cat /opt/odoo/extra-addons-requirements.txt.sha)
curr_sha_sum=$(shasum /opt/odoo/extra-addons/requirements.txt | awk '{ printf("%s", $1); }')
if [ "${last_sha_sum}" == "" ] || [ "${last_sha_sum}" != "${curr_sha_sum}" ] ; then
export install_requirements=1
fi
fi
fi
if [ "${install_requirements}" != "0" ]; then
if [ "$(id -u)" == "0" ]; then
su - odoo -c 'pip3 install --user /opt/odoo/libs/wise_commons'
su - odoo -c 'pip3 install --user -r /opt/odoo/extra-addons/requirements.txt'
else
pip3 install --user -r /opt/odoo/extra-addons/requirements
pip3 install --user /opt/odoo/libs/wise_commons
fi
# if pip install succedded ..
if [ "$?" == "0" ]; then
echo $curr_sha_sum > /opt/odoo/extra-addons-requirements.txt.sha
if [ "$(id -u)" == "0" ]; then
chown odoo:odoo /opt/odoo/extra-addons-requirements.txt.sha
fi
fi
fi
if [ "$(id -u)" == "0" ]; then
exec gosu odoo /bin/bash -c "source /opt/odoo/.profile ; python3 /opt/odoo/odoo-server/odoo-bin --config=/opt/odoo/conf/odoo.conf --proxy-mode $@"
else
python3 /opt/odoo/odoo-server/odoo-bin --config=/opt/odoo/conf/odoo.conf --proxy-mode $@
fi
exit 0