Created
March 29, 2018 08:39
-
-
Save paraita/5dd6e49e9d076d2049e022bbffa9274c to your computer and use it in GitHub Desktop.
FOR VALIDATION WITH MICHAEL
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
#!/bin/bash | |
set -x | |
SSH_USERNAME="michael" | |
SSH_PORT=22224 | |
function debug { | |
DEBUGCONTENT=`echo $1 | base64 -w 0` | |
DEBUGMESSAGE="<QueueMessage><MessageText>$DEBUGCONTENT</MessageText></QueueMessage>" | |
curl -X POST -d "$DEBUGMESSAGE" "https://$STORAGEACCOUNT.queue.core.windows.net/debug/messages?$SASKEY" | |
} | |
# Downloads and install ProActive Node as a Systemd service | |
mkdir -p /opt/proactive | |
cd /opt/proactive | |
if apt-get --help; then | |
apt-get update | |
if ! apt-get install -y wget curl jq; then | |
sleep 10 | |
apt-get update | |
if ! apt-get install -y wget curl jq; then | |
>&2 echo "Fatal error: Unable to run apt-get" | |
halt | |
fi | |
fi | |
else | |
yum install epel-release -y | |
if ! yum -y install wget curl jq; then | |
sleep 10 | |
if ! yum -y install wget curl jq; then | |
>&2 echo "Fatal error: Unable to run yum" | |
halt | |
fi | |
fi | |
fi | |
wget --no-clobber https://s3.amazonaws.com/ci-materials/Latest_jre/jre-8u131-linux-x64.tar.gz | |
tar zxf jre-8u131-linux-x64.tar.gz | |
ln -s /opt/proactive/jre1.8.0_131 /opt/proactive/java | |
JSONCONFIG=`base64 -d /var/lib/waagent/CustomData` | |
echo $JSONCONFIG | |
export HOST=`echo $JSONCONFIG | jq '.rmurl' -r | sed 's/http[s]\?:\?\/\{2\}//g'` | |
export RMURL=`echo $JSONCONFIG | jq '.rmurl' -r | sed 's/http[s]\?:\?\/\{2\}//g'` | |
export CREDVALUE=`echo $JSONCONFIG | jq '.credentials' -r` | |
export NODESOURCENAME=`echo $JSONCONFIG | jq '.nodesourcename' -r` | |
export STORAGEACCOUNT=`echo $JSONCONFIG | jq '.storageaccount' -r` | |
export SASKEY=`echo $JSONCONFIG | jq '.saskey' -r` | |
export USERCUSTOMSCRIPTURL=`echo $JSONCONFIG | jq '.usercustomscripturl' -r` | |
export EXT_STORACC_RAW=`echo $JSONCONFIG | jq '.exernalstorageaccount' -r` | |
export EXT_STOR_ACC=`echo $EXT_STORACC_RAW | sed 's/\:.*$//'` | |
export EXT_STOR_ACC_SAS=`echo $EXT_STORACC_RAW | sed 's/^.*\:?//'` | |
debug "$HOSTNAME INFO: CustomData read properly (as I can write this message)" | |
if [ ! -z "$USERCUSTOMSCRIPTURL" ]; then | |
curl -X GET "$USERCUSTOMSCRIPTURL" > user_custom_script.sh | |
chmod +x user_custom_script.sh | |
./user_custom_script.sh | |
if [ $? -ne 0 ]; then | |
debug "$HOSTNAME FATAL: User custom script exited with error: $?" | |
halt #sleep 9999 #exit -1 | |
fi | |
fi | |
# PNP | |
PNP_PROPERTIES="-Dproactive.net.nolocal=true -Dproactive.communication.protocol=pnp" | |
#PAMR | |
PAMRHOST=`echo $HOST | cut -d: -f1` | |
PAMR_PROPERTIES="-Dproactive.net.nolocal=false -Dproactive.communication.protocol=pamr \ | |
-Dproactive.pamr.router.address=$RMURL \ | |
-Dproactive.pamrssh.address=localhost \ | |
-Dproactive.pamr.socketfactory=ssh -Dproactive.pamrssh.port=$SSH_PORT \ | |
-Dproactive.pamrssh.username=$SSH_USERNAME \ | |
-Dproactive.pamrssh.key_directory=/opt/proactive/.ssh \ | |
-Dpa.rm.node.source.ping.frequency=75000" | |
PROPERTIES=$PAMR_PROPERTIES | |
debug "$HOSTNAME INFO: $PROPERTIES" | |
# Getting node.jar | |
# if the node.jar is uploaded by the infrastructure | |
#curl -X GET "https://$STORAGEACCOUNT.blob.core.windows.net/nodefiles/node.jar?$SASKEY" > /opt/proactive/node.jar | |
# if we assume the node.jar file is already in the external storage account | |
curl -X GET "https://$EXT_STOR_ACC.blob.core.windows.net/nodefiles/node.jar?$EXT_STOR_ACC_SAS" > /opt/proactive/node.jar | |
# Getting the key | |
mkdir -p /opt/proactive/.ssh | |
curl -X GET "https://$EXT_STOR_ACC.blob.core.windows.net/nodefiles/azure_rsa?$EXT_STOR_ACC_SAS" > /opt/proactive/.ssh/id_rsa | |
curl -X GET "https://$EXT_STOR_ACC.blob.core.windows.net/nodefiles/azure_rsa.pub?$EXT_STOR_ACC_SAS" > /opt/proactive/.ssh/id_rsa.pub | |
chown -R activeeon /opt/proactive | |
chmod 600 /opt/proactive/.ssh/id_rsa | |
chmod 600 /opt/proactive/.ssh/id_rsa.pub | |
# Read Azure Queue to get node name Deletion is performed on NS Side when nodes are properly registered | |
msg=$(curl "https://$STORAGEACCOUNT.queue.core.windows.net/nodeconfig/messages?visibilitytimeout=300&$SASKEY") | |
JSONMSG=`echo $msg | grep -oP '<MessageText>\K[^<]+' | base64 -d` | |
msgId=`echo $msg | grep -oP '<MessageId>\K[^<]+'` | |
popReceipt=`echo $msg | grep -oP '<PopReceipt>\K[^<]+'` | |
NODEBASENAME=`echo $JSONMSG | jq '.nodebasename' -r` | |
NODEINSTANCES=`echo $JSONMSG | jq '.nodeinstances' -r` | |
if [ -z "$NODEBASENAME" ]; then | |
debug "$HOSTNAME FATAL: Unable to retrieve node configuration from 'nodeconfig' queue" | |
halt #sleep 9999 #exit -1 | |
fi | |
# Immediately delete the message from queue. | |
# If the script fails then the node will be considered lost, | |
# this must be the default behaviour until Azure scaleSet provide | |
# automatic redeployment in case of failure. | |
curl -X DELETE "https://${STORAGEACCOUNT}.queue.core.windows.net/nodeconfig/messages/${msgId}?popreceipt=${popReceipt}&${SASKEY}" | |
# Retrieve instance metadata | |
INSTANCE_NAME=$(curl -H Metadata:true "http://169.254.169.254/metadata/instance/compute?api-version=2017-12-01" | jq .name | sed 's/"//g') | |
INSTANCE_ID=$(echo -n "$INSTANCE_NAME" | rev | cut -d'_' -f1 | rev) | |
# update Azure Table | |
ENTITY="{'PartitionKey':'$HOSTNAME','RowKey':'$NODEBASENAME', 'NodesCount':'$NODEINSTANCES', 'InstanceId': '$INSTANCE_ID'}" | |
curl -H "Content-Type: application/json" -d "$ENTITY" -X POST "https://$STORAGEACCOUNT.table.core.windows.net/nodesperhost?$SASKEY" | |
if [ $? -ne 0 ]; then | |
debug "$HOSTNAME FATAL: Unable to register the host into 'nodesperhost' table" | |
halt #sleep 9999 #exit -1 | |
fi | |
NOW=`date` | |
debug "$HOSTNAME INFO: Terminated to fill the Table on $NOW" | |
# Generate proactive-node service description | |
cat > /etc/systemd/system/proactive-node.service <<EOL | |
[Unit] | |
After=sshd.service | |
[Service] | |
ExecStart=/opt/proactive/java/bin/java -jar /opt/proactive/node.jar ${PROPERTIES} -v ${CREDVALUE} -w ${NODEINSTANCES} -r pamr://0/ -n ${NODEBASENAME} -s ${NODESOURCENAME} | |
User=activeeon | |
[Install] | |
WantedBy=default.target | |
EOL | |
chmod 664 /etc/systemd/system/proactive-node.service | |
# Install ProActive Node Service | |
systemctl daemon-reload | |
systemctl enable proactive-node.service | |
sysctl fs.inotify.max_user_watches=524288 # Support for large numnber of nodes | |
# Debug message posted on debug queue | |
IP=`hostname -i` | |
debug "$HOSTNAME INFO: Service is ready to start: $IP , $NODEBASENAME , $NODEINSTANCES" | |
# Let's start the service | |
systemctl start proactive-node.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment