Example User-Data LSF
Sample User Data Scripts
Example
Simple user_data.sh
CODE
#!/bin/bash
set -x
#typical aws-style hostname
NEW_HOSTNAME=ip-$( hostname -I |sed 's/\./-/g' |sed 's/ //g' )
hostname ${NEW_HOSTNAME}
##temporarily change the root password
#echo root:AAAAAA |chpasswd
##delete line 3 of /etc/hosts
#sed -i.orig '3d' /etc/hosts
#add an /etc/hosts self-identifying entry
echo >> /etc/hosts
echo -e "$( hostname -I )\t\t\t${NEW_HOSTNAME}" >> /etc/hosts
##aws-resource-connector based AMI has a local /opt/lsf/conf asset
## and needs configuration file updated to faciliate startup under
## the XIO Provider in Resource Connector:
## change resource designation
sed -i 's/awshost/exohost/g' /opt/lsf/conf/lsf.conf
. /opt/lsf/conf/profile.lsf
lsadmin limstartup
lsadmin resstartup
badmin hstartup
Less Simple user_data.sh
BASH
#!/bin/bash
#set -ex
#set -e
cp ${0} /tmp/$( basename ${0} ).$$
export LOGGER="/tmp/user-data-$$.log"
# by dropping everything in to a subshell
(
echo STARTing $( date )
set -x
#export boolEXO=exohost boolIO=iohost boolWO=wohost
%EXPORT_USER_DATA%
IP=$( hostname -I |awk '{print $1}' )
NEW_HOSTNAME=ip-$( echo ${IP} |sed 's/\./-/g' )
hostnamectl set-hostname ${NEW_HOSTNAME} --static
echo >> /etc/hosts
echo -e "172.16.153.140\t\thead" >> /etc/hosts
echo -e "${IP}\t\t${NEW_HOSTNAME}" >> /etc/hosts
sed -i 's/#head/head/g' /etc/fstab
systemctl daemon-reload
mount -a
sleep 2
LSF_CONF_FILE=/localopt/lsf/conf/lsf.conf
for _resource in boolEXO boolWO boolIO ;do
if [[ -v ${_resource} ]]; then
LSF_LOCAL_RESOURCES="${LSF_LOCAL_RESOURCES} [resource ${!_resource}]"
fi
done
for _resourcemap in mem clusterName providerName ;do
if [[ -v ${_resourcemap} ]]; then
LSF_LOCAL_RESOURCES="${LSF_LOCAL_RESOURCES} [resourcemap ${!_resourcemap}*${_resourcemap}]"
fi
done
sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1 ${LSF_LOCAL_RESOURCES}\"/" ${LSF_CONF_FILE}
## if [[ -n ${boolEXO} ]]; then
## LSF_LOCAL_RESOURCES="${LSF_LOCAL_RESOURCES} [resource ${boolEXO}]"
## fi
##
## if [[ -n ${boolWO} ]]; then
## LSF_LOCAL_RESOURCES="${LSF_LOCAL_RESOURCES} [resource ${boolWO}]"
## fi
##
## if [[ -n ${boolIO} ]]; then
## LSF_LOCAL_RESOURCES="${LSF_LOCAL_RESOURCES} [resource ${boolIO}]"
## fi
##
## if [[ -n ${mem} ]]; then
## LSF_LOCAL_RESOURCES="${LSF_LOCAL_RESOURCES} [resourcemap ${mem}*mem]]"
## fi
##
## if [[ -n ${clusterName} ]]; then
## LSF_LOCAL_RESOURCES="${LSF_LOCAL_RESOURCES} [resourcemap ${clusterName}*clusterName]]"
## fi
##
## if [[ -n ${providerName} ]]; then
## LSF_LOCAL_RESOURCES="${LSF_LOCAL_RESOURCES} [resourcemap ${providerName}*providerName]]"
## fi
##
## sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1 ${LSF_LOCAL_RESOURCES}\"/" ${LSF_CONF_FILE}
### if [[ -n ${boolEXO} ]]; then
### sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1 [resource ${boolEXO}]\"/" ${LSF_CONF_FILE}
### fi
###
### if [[ -n ${boolWO} ]]; then
### sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1 [resource ${boolWO}]\"/" ${LSF_CONF_FILE}
### fi
###
### if [[ -n ${boolIO} ]]; then
### sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1 [resource ${boolIO}]\"/" ${LSF_CONF_FILE}
### fi
###
### if [[ -n ${mem} ]]; then
### sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1 [resourcemap ${mem}*mem]\"/" ${LSF_CONF_FILE}
### fi
###
### if [[ -n ${clusterName} ]]; then
### sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1 [resourcemap ${clusterName}*clusterName]\"/" ${LSF_CONF_FILE}
### fi
###
### if [[ -n ${providerName} ]]; then
### sed -i "s/\(LSF_LOCAL_RESOURCES=.*\)\"/\1 [resourcemap ${providerName}*providerName]\"/" ${LSF_CONF_FILE}
### fi
. /localopt/lsf/conf/profile.lsf
lsreghost -s ${LSF_ENVDIR}/hostregsetup
#if /localopt/lsf has the binaries, can use /localopt/lsf location
#lsf_daemons start
#if /localopt/lsf doesn't have all the binaries, can use the remoteFS location
/opt/lsf/10.1/linux3.10-glibc2.17-x86_64/etc/lsf_daemons start
echo ENDing $( date )
) |& tee -a ${LOGGER}