184 lines
5.0 KiB
Plaintext
Executable File
184 lines
5.0 KiB
Plaintext
Executable File
#/bin/bash
|
|
echo "Start container ODOO_18: $UUID""
|
|
|
|
export PATH=/4SERVER/sbin:$PATH
|
|
SERVER_IP=$( ip -4 addr show eth0 | awk '/inet/ {print $2}' | cut -d/ -f1 )
|
|
echo "SERVER_IP $SERVER_IP"
|
|
|
|
if [ -z "$1" ]; then
|
|
exit 0
|
|
else
|
|
BASEURL="/4SERVER/data/$1/"
|
|
fi
|
|
|
|
|
|
DOMAIN="$UUID.odoo4projects.com $DOMAIN"
|
|
CLIENT_DOMAIN=$(cat ${BASEURL}etc/domain)
|
|
echo "CLIENT_DOMAIN: $CLIENT_DOMAIN"
|
|
echo ""
|
|
if [[ -n "$CLIENT_DOMAIN" ]]; then
|
|
DOMAIN+=" www.$CLIENT_DOMAIN $CLIENT_DOMAIN"
|
|
fi
|
|
echo "Domains: $DOMAIN"
|
|
|
|
|
|
NEW=0
|
|
if [ ! -d "$BASEURL" ]; then
|
|
echo "NEW CLIENT !!!"
|
|
echo "Wait for DNS to update"
|
|
|
|
WAIT=true
|
|
START_TIME=$(date +%s)
|
|
while $WAIT; do
|
|
nslookup "$1.odoo4projects.com" > /dev/null 2>&1
|
|
if [ $? -eq 0 ]; then
|
|
echo "Domain $DOMAIN resolved successfully."
|
|
WAIT=false
|
|
fi
|
|
|
|
CURRENT_TIME=$(date +%s)
|
|
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
|
|
if [ $ELAPSED_TIME -ge 120 ]; then
|
|
echo "Timeout reached. Domain $DOMAIN could not be resolved."
|
|
WAIT=false
|
|
fi
|
|
sleep 5
|
|
done
|
|
NEW=1
|
|
fi
|
|
|
|
echo "Get valid DNS entries:"
|
|
filtered_domains=""
|
|
|
|
for domain in $DOMAIN; do
|
|
nslookup_output=$(nslookup "$domain" 2>/dev/null)
|
|
status=$?
|
|
|
|
echo "DOMAIN: $domain $status"
|
|
if [[ $status -eq 0 ]]; then
|
|
#ns_ip=$(echo "$nslookup_output" | grep 'Address:' | tail -n1 | awk '{print $2}')
|
|
ns_ip=$(echo "$nslookup_output" | grep -Eo 'Address: ([0-9]{1,3}\.){3}[0-9]{1,3}' | awk '{print $2}' | tail -n1)
|
|
|
|
echo "NS IP $ns_ip"
|
|
if [[ "$ns_ip" == "$SERVER_IP" ]]; then
|
|
filtered_domains+=" $domain"
|
|
echo "Domain added $filtered_domains"
|
|
fi
|
|
else
|
|
echo "Failed to nslookup $domain -- $ns_ip"
|
|
fi
|
|
done
|
|
|
|
filtered_domains=$(echo "$filtered_domains" | xargs)
|
|
echo "Filtered domains: $filtered_domains"
|
|
|
|
|
|
DOMAIN_LABEL=""
|
|
|
|
for domain in $filtered_domains; do
|
|
if [ -z "$DOMAIN_LABEL" ]; then
|
|
DOMAIN_LABEL="traefik.http.routers.$1.rule=Host(\`$domain\`)"
|
|
else
|
|
DOMAIN_LABEL+=" || Host(\`$domain\`)"
|
|
fi
|
|
done
|
|
|
|
|
|
|
|
echo $DOMAIN_LABEL
|
|
|
|
echo "end domains"
|
|
|
|
exit 0
|
|
|
|
echo "BASEURL: $BASEURL"
|
|
PORT=$((CONTRACT_ID + 2200))
|
|
echo "CREATING PORT $PORT"
|
|
UUID="${1:-default}"
|
|
DATA_DIR="${BASEURL}odoo/"
|
|
CUSTOM_DIR="${BASEURL}git/$UUID/custom/"
|
|
ENTERPRISE_DIR="${BASEURL}git/$UUID/enterprise/"
|
|
LOGS_DIR="${BASEURL}logs/"
|
|
CONFIG_DIR="${BASEURL}config/"
|
|
CC_DIR="${BASEURL}cc/"
|
|
BACKUP_DIR="/BACKUP/$1"
|
|
GIT_DIR="${BASEURL}git-server/"
|
|
ETC_DIR="${BASEURL}etc/"
|
|
INSTALL_DIR="${BASEURL}install/"
|
|
SSH_DIR="${BASEURL}.ssh/"
|
|
HUGO_DIR="${BASEURL}git-server/local/hugo"
|
|
|
|
log restoreODOO "DOMAIN_LABEL $DOMAIN_LABEL"
|
|
|
|
log restoreODOO "CREATING CONTAINER $UUID"
|
|
|
|
echo "Stopping and Deleting Contianer"
|
|
d stop $UUID
|
|
d container rm $UUID
|
|
echo "Done Stopping & Deleting containers Errors above are OK"
|
|
|
|
|
|
EXTRA_DOCKER_PARAMETER=""
|
|
if [ -d "$HUGO_DIR" ]; then
|
|
EXTRA_DOCKER_PARAMETER="-v $HUGO_DIR:/mnt/hugo"
|
|
fi
|
|
echo "******************"
|
|
echo $EXTRA_DOCKER_PARAMETER
|
|
echo $HUGO_DIR
|
|
echo ***********************""
|
|
# start container - check done in checkContractsBee
|
|
sudo docker run -d --name "$UUID" \
|
|
--network docker-compose_4projects \
|
|
--restart=always \
|
|
$EXTRA_DOCKER_PARAMETER \
|
|
-v "$DATA_DIR/odoo-web-data:/var/lib/odoo" \
|
|
-v "$CUSTOM_DIR:/mnt/addons/custom" \
|
|
-v "$ENTERPRISE_DIR:/mnt/addons/enterprise" \
|
|
-v "$LOGS_DIR:/mnt/logs" \
|
|
-v "$CC_DIR:/mnt/cc" \
|
|
-v "$BACKUP_DIR:/mnt/backup" \
|
|
-v "$CONFIG_DIR:/etc/odoo" \
|
|
-v "$GIT_DIR:/git-server" \
|
|
-v "$ETC_DIR:/mnt/etc" \
|
|
-v "$INSTALL_DIR:/mnt/install" \
|
|
-v "$SSH_DIR:/etc/sshkey" \
|
|
-p "$PORT:22" \
|
|
-e HOST=beedb \
|
|
-e USER=$UUID \
|
|
-e PASSWORD=$UUID \
|
|
-e STAGING=$STAGING \
|
|
--label "$DOMAIN_LABEL" \
|
|
--label "traefik.http.services.$1.loadbalancer.server.port=8069" \
|
|
--label "traefic.http.routers.$1.entrypoints=web, websecure" \
|
|
--label "traefik.http.routers.$1.tls.certresolver=production" \
|
|
--label "traefik.http.routers.$1.tls=true" \
|
|
--label "traefik.http.routers.$1.service=$1" \
|
|
--label "traefik.http.routers.$1_S.entrypoints=web,websecure" \
|
|
--label "traefik.http.routers.$1_S.rule=Host(\`s.$1.odoo4projects.com\`)" \
|
|
--label "traefik.http.routers.$1_S.tls.certresolver=production" \
|
|
--label "traefik.http.routers.$1_S.tls=true" \
|
|
--label "traefik.http.services.$1_S.loadbalancer.server.port=8070" \
|
|
--label "traefik.http.routers.$1_S.service=$1_S" \
|
|
docker.odoo4projects.com/4projects/odoo_18:$BRANCH
|
|
sudo chmod 777 $DATA_DIR/odoo-web-data
|
|
sudo mkdir $ETC_DIR
|
|
sudo chmod 777 $ETC_DIR
|
|
sudo chmod 777 $INSTALL_DIR
|
|
sudo cp /4PROJECTS/config/odoo_18/odoo.conf $CONFIG_DIR
|
|
sudo cp /4PROJECTS/config/odoo_18/staging.conf $CONFIG_DIR
|
|
echo "git clone ssh://git@$1.odoo4projects.com:$PORT/git-server/repos/odoo.git" > $ETC_DIR/gitpath
|
|
echo "$1" > $ETC_DIR/uuid
|
|
d exec -it $1 chown -R odoo /mnt
|
|
d exec -it $1 chgrp -R odoo /mnt/
|
|
d exec -it $1 chown -R git /git-server
|
|
d exec -it $1 chgrp -R git /git-server
|
|
d exec -it $1 chmod -R g+rw /git-server
|
|
if [ "$NEW" -eq 1 ]; then
|
|
restoreODOO $1 default.zip
|
|
echo "here"
|
|
restoreODOO ${1}_ default.zip
|
|
echo "there"
|
|
fi
|
|
|
|
|