Skip to content

Commit

Permalink
Added more configuration for nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
iuliana committed Sep 12, 2021
1 parent 793d377 commit ef5cfe6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 6 deletions.
67 changes: 61 additions & 6 deletions catalog/common-types/nginx.bom
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ brooklyn.catalog:
To have the orchestration server download it, or to use a classpath URL with a bundled resource,
use files.customize writing from that URL to creation-script.sql instead of this.
type: string
default: 8080
default: 80
- name: nginx.sticky
description: Whether to use sticky sessions (no sure where this is used)
type: boolean
default: true

- name: server.list
type: string
description: Comma separated list of server ips to manage.
brooklyn.config:
dontRequireTtyForSudo: true
start.timeout: 20m
Expand All @@ -54,21 +56,74 @@ brooklyn.catalog:

shell.env:
APP_PORT: $brooklyn:config("app.port")
ADDR_LIST: $brooklyn:config("server.list")

install.command: |
sudo apt -y update
sudo apt -y install nginx

customize.command: |
echo customize
sudo systemctl status nginx | grep 'running' > /dev/null 2>&1
if [ $? == 0 ]; then
echo "NginX is up. All is well with the world..."
else
echo "NginX is down. Starting it..."
sudo systemctl start nginx
fi

echo "NginX - configuring ..."

cat >/tmp/load-balancer.conf <<ENDOFTEXT
upstream backend {
IPXX
}

server {
listen 80;

location / {
proxy_pass http://backend;
}
}
ENDOFTEXT

IFS=',' ADDR=(${ADDR_LIST}); unset IFS;

# TODO got to figure out how to configure NginX correctly
SERVERS=''
for i in "${ADDR[@]}"; do
i="${i%\"}"
i="${i#\"}"
SERVERS="${SERVERS} server ${i};\n"
done

sed -i -e "s/IPXX/${SERVERS}/g" /tmp/load-balancer.conf

# configure servers to balance
sudo mv /tmp/load-balancer.conf /etc/nginx/conf.d/
# remove the default symbolic link from the sites-enabled folder.
sudo rm /etc/nginx/sites-enabled/default

#sudo systemctl enable postgresql.service
echo "NginX - restarting ..."
sudo systemctl restart nginx

launch.command: |
sudo systemctl start nginx
sudo systemctl status nginx | grep 'running' > /dev/null 2>&1
if [ $? == 0 ]; then
echo "NginX is up. All is well with the world."
else
echo "NginX is down. Starting it..."
sudo systemctl start nginx
fi

stop.command: |
sudo systemctl stop nginx
sudo systemctl status nginx | grep 'running' > /dev/null 2>&1
if [ $? == 0 ]; then
echo "NginX is up. Shutting it down..."
sudo systemctl stop nginx
else
echo "NginX is already down."
fi

checkRunning.command:
sudo systemctl status nginx | grep -i -e 'active' -e 'online'
Expand Down
12 changes: 12 additions & 0 deletions catalog/three-tier-webapp/three-tier-webapp.bom
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ brooklyn.catalog:
enricher.targetSensor: $brooklyn:sensor("webapp.reqs.perSec.perNode")
enricher.aggregating.fromMembers: true
transformation: average
- type: org.apache.brooklyn.enricher.stock.Aggregator
brooklyn.config:
enricher.sourceSensor: $brooklyn:sensor("host.public.address") # not sure about this one
enricher.targetSensor: $brooklyn:sensor("addr.list")
enricher.aggregating.fromMembers: true
- type: org.apache.brooklyn.enricher.stock.Joiner
brooklyn.config:
enricher.joiner.minimum: $brooklyn:config("cluster.initial.size")
enricher.sourceSensor: $brooklyn:sensor("addr.list")
enricher.targetSensor: $brooklyn:sensor("addr.list.string")
enricher.joiner.separator: ","
brooklyn.policies:
- type: org.apache.brooklyn.policy.ha.ServiceReplacer
- type: org.apache.brooklyn.policy.autoscaling.AutoScalerPolicy
Expand All @@ -86,6 +97,7 @@ brooklyn.catalog:
brooklyn.config:
app.port: 8080
#loadbalancer.serverpool: $brooklyn:entity("cluster")
server.list: $brooklyn:entity("cluster").attributeWhenReady("addr.list.string")
nginx.sticky: false
#ssl: $brooklyn:config("ssl")
- type: org.apache.brooklyn.entity.database.mysql5
Expand Down

0 comments on commit ef5cfe6

Please sign in to comment.