Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue where dpkg would get locked and not allow deployment t… #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ fabric.properties

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

.DS_Store
# -- END
Binary file removed marketplace/images/logos/hero.png
Binary file not shown.
Binary file removed marketplace/images/logos/large.png
Binary file not shown.
Binary file removed marketplace/images/logos/medium.png
Binary file not shown.
Binary file removed marketplace/images/logos/small.png
Binary file not shown.
Binary file removed marketplace/images/logos/wide.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions marketplace/mainTemplate-byol_2019.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serverNodeCount": {
Expand Down Expand Up @@ -69,7 +69,7 @@
}
},
{
"apiVersion": "2016-06-01",
"apiVersion": "2019-11-01",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "networksecuritygroups",
"location": "[parameters('location')]",
Expand Down
4 changes: 2 additions & 2 deletions marketplace/mainTemplate-hourly_pricing_mar19.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serverNodeCount": {
Expand Down Expand Up @@ -69,7 +69,7 @@
}
},
{
"apiVersion": "2016-06-01",
"apiVersion": "2019-11-01",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "networksecuritygroups",
"location": "[parameters('location')]",
Expand Down
8 changes: 8 additions & 0 deletions marketplace/test/ResourceGroupCleanup.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": { },
"variables": { },
"resources": [ ],
"outputs": { }
}
43 changes: 43 additions & 0 deletions marketplace/test/backout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

###############################################################################
# Dependencies: #
# azure cli #
# JQ #
###############################################################################

###############################################################################
# Parameters #
# -g : Resource Group #
# usage: -g ja-test-1 #
# purpose: Specifies the name of the resource group to use. Will create #
# if not exists #
# -s : Save Resource Group #
# usage: -s #
# purposes: Specifies whether resource group should be maintained #
###############################################################################

###############################################################################
# WARNING; THIS WILL DELETE ALL RESOURCES WITHIN A RESOURCE GROUP #
###############################################################################

while getopts g:s flag
do
case "${flag}" in
g) RESOURCE_GROUP=${OPTARG};;
s) SAVE=1;;
*) exit 1;;
esac
done

echo "Resource Group: ${RESOURCE_GROUP}"
echo "Save Resource Group: ${SAVE}"


if [ "$SAVE" -eq "1" ]; then
echo "Save was passed, deleting resources but leaving group."
az deployment group create --verbose --template-file ResourceGroupCleanup.template.json --resource-group $RESOURCE_GROUP --mode Complete
exit 0
fi

az group delete --name $RESOURCE_GROUP --yes
69 changes: 69 additions & 0 deletions marketplace/test/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh

###############################################################################
# Dependencies: #
# azure cli #
# JQ #
###############################################################################

###############################################################################
# Parameters #
# -l : Location #
# usage: -l useast1 #
# purpose: Location based on az account list-locations #
# -p : Parameters #
# usage: -p mainTemplateParameterss.json #
# purpose: Pass in a parameters file for the mainTemplate #
# -g : Resource Group #
# usage: -g ja-test-1 #
# purpose: Specifies the name of the resource group to use. Will create #
# if not exists #
# -n : Deployment Name #
# usage: -n test_deployment_one #
# purposes: names the deployment in azure #
# -b : BYOL Template #
# purpose: specify the BYOL template #
# -h : Hourly Template #
# purpose: Specify the Hourly Template #
###############################################################################

TEMPLATE="../mainTemplate-byol_2019.json"

while getopts l:p:g:n:h:b flag
do
case "${flag}" in
l) LOCATION=${OPTARG};;
p) PARAMETERS=${OPTARG};;
g) RESOURCE_GROUP=${OPTARG};;
n) NAME=${OPTARG};;
h) TEMPLATE="../mainTemplate-hourly_pricing_mar19.json";;
b) TEMPLATE="../mainTemplate-byol_2019.json";;
*) exit 1;;
esac
done

echo "Location: ${LOCATION}"
echo "Parameters: ${PARAMETERS}"
echo "Resource Group: ${RESOURCE_GROUP}"
echo "Deployment Name: ${NAME}"

if [ -f "$PARAMETERS" ]; then
echo "${PARAMETERS} exists"
else
echo "Parameters file does not exist."
exit 1
fi
location_exists=$(az account list-locations -o json | jq ".[] | .name" | grep ${LOCATION} -c)

if [ "$location_exists" = 0 ]; then
echo "Invalid location."
exit 1
fi

if [ "$(az group exists --name ${RESOURCE_GROUP})" = "true" ]; then
echo "Group Exists, skipping creation"
else
az group create --name $RESOURCE_GROUP --location $LOCATION --output table
fi

az deployment group create --verbose --template-file $TEMPLATE --parameters $PARAMETERS --resource-group $RESOURCE_GROUP --name $NAME --output table
38 changes: 38 additions & 0 deletions marketplace/test/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"serverNodeCount": {
"value": 3
},
"serverDiskSize": {
"value": 30
},
"serverVersion": {
"value": "6.6.1"
},
"syncGatewayNodeCount": {
"value": 1
},
"syncGatewayVersion": {
"value": "2.7.3"
},
"vmSize": {
"value": "Standard_DS3_v2"
},
"adminUsername": {
"value": "couchbase"
},
"adminPassword": {
"value": "Foo123!"
},
"location": {
"value": "eastus"
},
"license": {
"value": "byol_2019"
},
"_artifactsLocation": {
"value": "https://raw.githubusercontent.com/malscent/azure-resource-manager-couchbase/master/scripts/"
},
"_artifactsLocationSasToken": {
"value": ""
}
}
38 changes: 38 additions & 0 deletions marketplace/test/test_parameters/NoSyncGateway.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"serverNodeCount": {
"value": "32"
},
"serverDiskSize": {
"value": "30"
},
"serverVersion": {
"value": "6.6.1"
},
"syncGatewayNodeCount": {
"value": "0"
},
"syncGatewayVersion": {
"value": "2.7.3"
},
"vmSize": {
"value": "Standard_DS3_v2"
},
"adminUsername": {
"value": "couchbase"
},
"adminPassword": {
"value": "Foo123!"
},
"location": {
"value": "useast1"
},
"license": {
"value": "byol_2019"
},
"_artifactsLocation": {
"value": "string"
},
"_artifactsLocationSasToken": {
"value": ""
}
}
49 changes: 36 additions & 13 deletions scripts/server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ echo adminPassword \'$adminPassword\'
echo uniqueString \'$uniqueString\'
echo location \'$location\'

FILE="/var/lib/dpkg/lock-frontend"
DB="/var/lib/dpkg/lock"
if [[ -f "$FILE" ]]; then
PID=$(lsof -t $FILE)
echo "lock-frontend locked by $PID"
echo "Killing $PID"
kill -9 "${PID##p}"
echo "$PID Killed"
rm $FILE
PID=$(lsof -t $DB)
echo "DB locked by $PID"
kill -9 "${PID##p}"
if ps -p "${PID##p}" > /dev/null
then
__log_error "${PID} was not successfully killed, Installation cannot continue"
exit 1
fi
rm $DB
dpkg --configure -a
fi
malscent marked this conversation as resolved.
Show resolved Hide resolved


echo "Installing prerequisites..."
apt-get update
apt-get -y install python-httplib2
Expand Down Expand Up @@ -43,15 +65,16 @@ echo "Configuring Couchbase Server..."
nodeIndex="null"
while [[ $nodeIndex == "null" ]]
do
nodeIndex=`curl -H Metadata:true "http://169.254.169.254/metadata/instance/compute?api-version=2017-04-02" \
nodeIndex=$(curl -H Metadata:true "http://169.254.169.254/metadata/instance/compute?api-version=2017-04-02" \
| jq ".name" \
| sed 's/.*_//' \
| sed 's/"//'`
| sed 's/"//')
done

nodeDNS='vm'$nodeIndex'.server-'$uniqueString'.'$location'.cloudapp.azure.com'
rallyDNS='vm0.server-'$uniqueString'.'$location'.cloudapp.azure.com'

echo "Node DNS: ${nodeDNS}"
echo "Rally DNS: ${rallyDNS}"
echo "Adding an entry to /etc/hosts to simulate split brain DNS..."
echo "
# Simulate split brain DNS for Couchbase
Expand Down Expand Up @@ -86,8 +109,8 @@ echo "Running couchbase-cli node-init"
--node-init-data-path=/datadisk/data \
--node-init-index-path=/datadisk/index \
--node-init-analytics-path=/datadisk/analytics \
-u=$adminUsername \
-p=$adminPassword
--user=$adminUsername \
--pass=$adminPassword

if [[ $nodeIndex == "0" ]]
then
Expand All @@ -109,16 +132,16 @@ then
else
echo "Running couchbase-cli server-add"
output=""
while [[ ! "$output" =~ "SUCCESS" ]]
while [[ $output != "Server $nodeDNS:8091 added" && ! $output == *"Node is already part of cluster."* ]]
do
output=`./couchbase-cli server-add \
output=$(./couchbase-cli server-add \
--cluster=$rallyDNS \
-u=$adminUsername \
-p=$adminPassword \
--username=$adminUsername \
--password=$adminPassword \
--server-add=$nodeDNS \
--server-add-username=$adminUsername \
--server-add-password=$adminPassword \
--services=$services`
--services=$services)
echo server-add output \'$output\'
sleep 10
done
Expand All @@ -127,10 +150,10 @@ else
output=""
while [[ ! $output =~ "SUCCESS" ]]
do
output=`./couchbase-cli rebalance \
output=$(./couchbase-cli rebalance \
--cluster=$rallyDNS \
-u=$adminUsername \
-p=$adminPassword`
--username=$adminUsername \
--password=$adminPassword)
echo rebalance output \'$output\'
sleep 10
done
Expand Down
42 changes: 38 additions & 4 deletions scripts/syncGateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,54 @@ echo "Running syncGateway.sh"
version=$1

echo "Sleeping to prevent dpkg lock"
sleep 20s #workaround for dpkg lock issue
sleep 60s #workaround for dpkg lock issue

echo "Using the settings:"
echo version \'$version\'

echo "Setting up sync gateway user"
useradd sync_gateway
echo "Creating sync_gateway home directory"
mkdir -p /home/sync_gateway/
chown sync_gateway:sync_gateway /home/sync_gateway

echo "Installing Couchbase Sync Gateway..."
wget https://packages.couchbase.com/releases/couchbase-sync-gateway/${version}/couchbase-sync-gateway-enterprise_${version}_x86_64.deb
dpkg -i couchbase-sync-gateway-enterprise_${version}_x86_64.deb
wget https://packages.couchbase.com/releases/couchbase-sync-gateway/${version}/couchbase-sync-gateway-enterprise_${version}_x86_64.deb --quiet
echo "Download Complete. Installing..."

FILE="/var/lib/dpkg/lock-frontend"
DB="/var/lib/dpkg/lock"
if [[ -f "$FILE" ]]; then
PID=$(lsof -t $FILE)
echo "lock-frontend locked by $PID"
echo "Killing $PID"
kill -9 "${PID##p}"
echo "$PID Killed"
rm $FILE
PID=$(lsof -t $DB)
echo "DB locked by $PID"
kill -9 "${PID##p}"
rm $DB
dpkg --configure -a
fi

RESULT=$(dpkg -i couchbase-sync-gateway-enterprise_${version}_x86_64.deb 2>&1)
COUNT=0

while [[ $RESULT == *"dpkg frontend is locked by another process"* && $COUNT -le 50 ]]
do
printf "%s: %s\n" "$COUNT" "$RESULT"
RESULT=$(dpkg -i couchbase-sync-gateway-enterprise_${version}_x86_64.deb 2>&1)
COUNT=$((COUNT + 1))
sleep 3s
done
echo "Installation of Sync Gateway Complete"
echo "Calling util.sh..."
source util.sh
adjustTCPKeepalive

echo "Configuring Couchbase Sync Gateway..."
echo "Configuring Couchbase Sync Gateway..."\

file="/home/sync_gateway/sync_gateway.json"
echo '
{
Expand Down