Created
July 11, 2018 07:42
-
-
Save paraita/752e782851cbad43d94a8c074e7f19d3 to your computer and use it in GitHub Desktop.
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 | |
# This script is used as internalCustomStartupScript to setup the VM of the Azure Scale Set. | |
# This setup is for Centos 7.2 VM only, and involves: | |
# - setting up Docker and Docker-Compose | |
# - setting up ProActive Node service with PNP | |
# - starting the ProActive Node service | |
set -x | |
############################### | |
# Bash function used by the VM to send debug messages to the dedicated Azure Queue | |
############################### | |
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" | |
} | |
# Prerequisites: Install Docker and Docker Compose, add 'activeeon' user to docker group | |
#apt-get update | |
#apt-get install -y \ | |
# apt-transport-https \ | |
# ca-certificates \ | |
# curl \ | |
# gnupg2 \ | |
# software-properties-common | |
#curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | apt-key add - | |
#add-apt-repository \ | |
# "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \ | |
# $(lsb_release -cs) \ | |
# stable" | |
#apt-get update | |
#apt-get install -y docker-ce | |
#groupadd docker | |
#usermod -aG docker activeeon | |
#curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose | |
#chmod +x /usr/local/bin/docker-compose | |
############################### | |
# Downloads and install ProActive Node as a Systemd service | |
############################### | |
# Install dependencies | |
yum install epel-release -y | |
if ! yum -y install git wget curl jq vim; then | |
sleep 10 | |
if ! yum -y install git wget curl jq vim; then | |
>&2 echo "Fatal error: Unable to run yum" | |
halt | |
fi | |
fi | |
# Retrieve NS config | |
JSONCONFIG=`base64 -d /var/lib/waagent/CustomData` | |
echo $JSONCONFIG | |
export RMURL=`echo $JSONCONFIG | jq '.rmurl' -r` | |
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 EXTERNALSTORAGEACCOUNT=`echo $JSONCONFIG | jq '.externalstorageaccount' -r` | |
# debug | |
debug "$HOSTNAME INFO: CustomData read properly (as I can write this message)" | |
# Overidded custom script if specified | |
#if [ ! -z "$USERCUSTOMSCRIPTURL" ]; then | |
# curl -X GET "$USERCUSTOMSCRIPTURL" > 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 | |
# PNPS or PAMR can be infered from RM URL | |
#wget https://gist.githubusercontent.com/bamedro/c6c348af7741a4e09b4239077f5b2d67/raw/node.properties | |
#PROPERTIES="-Dproactive.net.nolocal=true -Dproactive.communication.protocol=pnps -Dproactive.pnps.heartbeat_factor=10 -Dlog4j.configuration=file:/opt/proactive/node.properties" | |
PROPERTIES="-Dproactive.net.nolocal=true -Dproactive.communication.protocol=pnp -Dproactive.pnps.heartbeat_factor=10" | |
# Retrieve node.jar | |
#mkdir -p /opt/proactive | |
#curl -X GET "https://$STORAGEACCOUNT.blob.core.windows.net/nodefiles/node.jar?$SASKEY" > /opt/proactive/node.jar | |
#chown -R tibcodev /opt/proactive | |
# Install Java 8 | |
#cd /opt/proactive | |
#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 | |
##/opt/proactive/java/bin/java | |
# 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}" | |
# debug | |
NOW=`date` | |
debug "$HOSTNAME INFO: Start filling the Table on $NOW" | |
# 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 systemd service unit file | |
cat > /etc/systemd/system/proactive-node.service <<EOL | |
[Unit] | |
After=sshd.service | |
[Service] | |
ExecStart=/tibco/proactive/bin/proactive-node ${PROPERTIES} -v ${CREDVALUE} -w ${NODEINSTANCES} -r ${RMURL} -n ${NODEBASENAME} -s ${NODESOURCENAME} | |
User=tibcodev | |
[Install] | |
WantedBy=default.target | |
EOL | |
chmod 664 /etc/systemd/system/proactive-node.service | |
# Generate proactive-node-jar systemd service unit file | |
cat > /etc/systemd/system/proactive-node-jar.service <<EOL | |
[Unit] | |
After=sshd.service | |
[Service] | |
ExecStart=/usr/bin/java -jar /opt/proactive/node.jar ${PROPERTIES} -v ${CREDVALUE} -w ${NODEINSTANCES} -r ${RMURL} -n ${NODEBASENAME} -s lngmem | |
User=tibcodev | |
[Install] | |
WantedBy=default.target | |
EOL | |
chmod 664 /etc/systemd/system/proactive-node-jar.service | |
# Install ProActive Node Service | |
systemctl daemon-reload | |
systemctl enable proactive-node.service | |
#systemctl enable proactive-node-jar.service | |
sysctl fs.inotify.max_user_watches=524288 # Support for large number of nodes | |
# TODO: this must be called ONLY if the node.jar execution succeed | |
# Until here, if script fails, another host could reuse this nodeconfig message. | |
# Once the service is started, if something goes wrong, this node configuration will not be reusable from another host | |
#curl -X DELETE "https://${STORAGEACCOUNT}.queue.core.windows.net/nodeconfig/messages/${msgId}?popreceipt=${popReceipt}&${SASKEY}" | |
#if [ $? -ne 0 ]; then | |
# debug "$HOSTNAME FATAL: Unable to delete nodeconfig from the queue." | |
# halt #sleep 9999 #exit -1 | |
#fi | |
# Debug message posted on debug queue | |
IP=`hostname -i` | |
debug "$HOSTNAME INFO: Service is ready to start: $IP , $NODEBASENAME , $NODEINSTANCES" | |
############################### | |
############################### | |
# Prepare script engines | |
############################### | |
# Python | |
#curl -O https://bootstrap.pypa.io/get-pip.py | |
#python2 get-pip.py | |
#python3 get-pip.py | |
#python2 /usr/local/bin/pip install py4j | |
#python2 /usr/local/bin/pip install numpy | |
#python3 /usr/local/bin/pip install py4j | |
#python3 /usr/local/bin/pip install numpy | |
# R | |
#apt-get install -y libssl-dev libcurl4-openssl-dev | |
#echo "deb http://cran.univ-paris1.fr/bin/linux/debian jessie-cran34/" >> /etc/apt/sources.list | |
#apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF' | |
#apt-get install -y r-base r-cran-rjava | |
#Rscript --slave --no-save --no-restore-history -e "install.packages(c('gtools','stringr','devtools'), repos=c('http://www.freestatistics.org/cran/'))" | |
#update-alternatives --install /usr/bin/java java /opt/proactive/java/bin/java 1 | |
#update-alternatives --set java /opt/proactive/java/bin/java | |
# Scilab | |
#apt-get install -y scilab | |
# OpenMPI | |
#apt-get install -y mpi-default-bin | |
# LnG specific configuration | |
sed -i -e '/lnh/d' /etc/fstab | |
if ! grep -q 'tibco' /etc/fstab; then | |
echo '10.0.3.4:/tibco /tibco nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0' >> /etc/fstab | |
fi | |
if ! grep -q 'algodata' /etc/fstab; then | |
echo '10.0.3.4:/algodata /algodata nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0' >> /etc/fstab | |
fi | |
mount -a | |
sed -i -e 's/PasswordAuthentication no/ PasswordAuthentication yes/g' /etc/ssh/sshd_config | |
systemctl reload sshd | |
sed -i -e '/ALGO_TOP/d' /etc/environment | |
echo 'ALGO_TOP=/algodata/algo_top/algos2dev1/AlgoOne5/algo/TOP' >> /etc/environment | |
echo 'PATH=/usr/bin:$PATH' >> /etc/environment | |
echo 'echo \"$@\"' > /bin/algoservices | |
chmod +x /bin/algoservices | |
sleep 10 | |
# Setup Java | |
unlink /usr/bin/java | |
ln -s /tibco/proactive/jre/bin/java /usr/bin/java | |
PATH=$PATH:/usr/bin | |
############################### | |
# Let's start the ProActive node service | |
############################### | |
systemctl start proactive-node.service | |
#systemctl start proactive-node-jar.service | |
############################### | |
# Add additional jar required for script engines | |
############################### | |
# prepare one-jar lib dir | |
#sleep 120 | |
#cd /tmp | |
#git clone https://github.com/gheon/proactive-node-additional-jar.git | |
#mv proactive-node-additional-jar/jri*.jar proactive-node-additional-jar/pa-*.jar proactive-node-additional-jar/rengine-*.jar /tmp/node/lib/ | |
#mv proactive-node-additional-jar/scheduler-examples*.jar /tmp/node/lib/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment