forked from RetailMeNot/SeleniumGridScaler
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add support to configure the number of browser processes per instance. #12
Open
adam-hampton-sp
wants to merge
2
commits into
mhardin:master
Choose a base branch
from
adam-hampton-sp:ahampton-updates
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
# ###################################################################################### | ||
# Shell script to configure a Selenium Grid worker node and add it to the grid. | ||
# This is executed by this command in the crontab, as seen with "cronatab -l": | ||
# @reboot /home/ubuntu/grid/grid_start_node.sh >> /home/ubuntu/grid/process.log 2>&1 | ||
# | ||
# ###################################################################################### | ||
PATH=/sbin:/usr/sbin:/bin:/usr/bin | ||
cd /home/ubuntu/grid/ | ||
|
||
# Call into AWS and figure out what our EC2 instance ID is. | ||
# Sometimes cron kicks off this script before the AWS/EC2 networking stack is awake. | ||
# We need to wait, polling for when the instance ID details beome available. | ||
echo "Grid Automation process started, looking up our EC2 Instance at `date`" | ||
export EC2_INSTANCE_ID= | ||
while [ -z "${EC2_INSTANCE_ID}" ] ; do | ||
# Wait 1 seconds to let the network settle down on boot up and let AWS get all of | ||
# the user-data zip file artifiacts in place. | ||
sleep 1 | ||
export EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`" | ||
done | ||
|
||
echo "Retreived our EC2 Instance ID: $EC2_INSTANCE_ID at `date`" | ||
|
||
# Pull down the user data, which will be a zip file containing necessary information | ||
# This is placed in the user-data fild for the instance by the getUserData() and launchNodes() methods. | ||
export NODE_TEMPLATE="/home/ubuntu/grid/nodeConfigTemplate.json" | ||
curl http://169.254.169.254/latest/user-data -o /home/ubuntu/grid/data.zip | ||
|
||
# Now, unzip the data downloaded from the userdata | ||
unzip -o /home/ubuntu/grid/data.zip -d /home/ubuntu/grid/ | ||
|
||
# Replace the instance ID in the node config file | ||
sed "s/<INSTANCE_ID>/$EC2_INSTANCE_ID/g" $NODE_TEMPLATE > /home/ubuntu/grid/nodeConfig.json | ||
|
||
# Finally, run the java process in a window so browsers can run | ||
xvfb-run --auto-servernum --server-args='-screen 0, 1600x1200x24' \ | ||
java -jar /home/ubuntu/grid/selenium-server-node.jar -role node \ | ||
-nodeConfig /home/ubuntu/grid/nodeConfig.json \ | ||
-Dwebdriver.chrome.driver="/home/ubuntu/grid/chromedriver" \ | ||
-log /home/ubuntu/grid/grid.log & | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
# ########################################################################### | ||
# A shell script to patch the /etc/hosts file for new grid node hosts. | ||
# Stock hosts files on EC2 usually only contain the loopback addresses and | ||
# are missing the actual host name and the DHCP address binding. This can | ||
# delay certain network operations. | ||
# This script patches the /etc/hosts file to contain the hostname on both the | ||
# loopback and DHCP based VPC IP address. | ||
# ########################################################################### | ||
PATH=/sbin:/usr/sbin:/bin:/usr/bin | ||
|
||
# Make certain we can find our host's EC2 instance ID. This ensures that the | ||
# network stack is online and that it can get out to the rest of the netowrk. | ||
export EC2_INSTANCE_ID= | ||
while [ -z "${EC2_INSTANCE_ID}" ] ; do | ||
# Wait 1 seconds to let the network settle down on boot up and let AWS get all of | ||
# the user-data zip file artifiacts in place. | ||
sleep 1 | ||
export EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`" | ||
done | ||
|
||
# Now we are certain the network stack is online, what is the host's IP? | ||
LOCALIP=`ifconfig | grep "inet addr" | grep -v "127.0.0" | cut -d':' -f2 | cut -d' ' -f1` | ||
HOSTNAME=`hostname` | ||
|
||
# Count the number of instacnces of the local ip in /etc/hosts. If this comes | ||
# back as zero then we know the local IP address needs to be added to the | ||
# /etc/hosts file. | ||
HASLOCALIP=`grep -c $LOCALIP /etc/hosts` | ||
|
||
# Count the number of instances of the host name in /etc/hosts. If this comes | ||
# back as zero then we know the localhost line needs to be patched to include | ||
# the local host name. | ||
HASHOSTNAME=`grep -c $HOSTNAME /etc/hosts` | ||
|
||
# Add the local hostname to /etc/hosts. | ||
if [ "0" -eq "$HASHOSTNAME" ] ; then | ||
sudo sed -i -e "s/localhost/localhost $HOSTNAME/" /etc/hosts | ||
fi | ||
|
||
# Add the local IP to /etc/hosts. | ||
if [ "0" -eq "$HASLOCALIP" ] ; then | ||
sudo bash -c "echo '# hostname added to support SeleniumGridScaler. ' >> /etc/hosts" | ||
sudo bash -c "echo \"$LOCALIP $HOSTNAME\" >> /etc/hosts" | ||
fi | ||
|
||
# Add an /etc/hosts entry for the Hub IP address. | ||
HASHUBNODEADDR=`grep -c hubHost /home/ubuntu/grid/nodeConfig.json` | ||
while [ "0" -eq "$HASHUBNODEADDR" ] ; do | ||
# Wait for the node setup script to pull down the hub's IP address. | ||
sleep 1 | ||
export HASHUBNODEADDR=`grep -c hubHost /home/ubuntu/grid/nodeConfig.json` | ||
done | ||
|
||
# Lookup the IP address of the hubNode in the nodeConfig.json file. | ||
HUBNODEADDR=`grep hubHost /home/ubuntu/grid/nodeConfig.json | cut -d'"' -f4` | ||
|
||
# Only add the entry if it is actually necessary to do so. | ||
ETCHOSTSHUBCOUNT=`grep -c $HUBNODEADDR /etc/hosts` | ||
if [ "0" -eq "$ETCHOSTSHUBCOUNT" ] ; then | ||
sudo bash -c "echo $HUBNODEADDR hubnode gridhead >> /etc/hosts" | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better check is !StringUtils.isEmpty(maxChromeThreads)