Closed Synkevych closed 6 months ago
sudo add-apt-repository 'deb http://security.ubuntu.com/ubuntu xenial-security main'
sudo apt-get update
sudo apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com
sudo apt-get install -y libjasper1 libjasper-dev
sudo apt-get install parallel
# After an instance is running, a new folder should be mounted
# sudo mkdir -p /data && sudo mkdir -p /series
calculation_id=1
sudo mount 10.0.1.17:/home/ubuntu/calculations/$calculation_id /data
sudo mount 10.0.1.17:/home/ubuntu/series /series
cat start_calculation.sh
#!/bin/bash
# su -l ubuntu
export LD_LIBRARY_PATH=/home/ubuntu/flexpart_lib/lib:$LD_LIBRARY_PATH
echo "For calculations FLEXPART uses $(nproc) cores." >> /data/calculations_server.log
DIR_NAME=example
NFS_SERVER=IP_ADDRESS
# mount DIR_NAME folder to /data
sudo mount $NFS_SERVER:/home/ubuntu/calculations/$DIR_NAME /data
sudo mount $NFS_SERVER:/home/ubuntu/series /series
cd /home/ubuntu/calculation
su -c "python3.6 parser.py" ubuntu
su -c "export LD_LIBRARY_PATH=/home/ubuntu/flexpart_lib/lib:$LD_LIBRARY_PATH && simflex" ubuntu
exit 0
cat launch_instance.sh
#!/bin/bash
HASH=`date --utc +%Y%m%d%H%M`; FLAVOR="Name"; VMNAME="flexpart_${FLAVOR/./_}_${HASH}";
TIME=$(date "+%d.%m.%Y-%H:%M:%S"); TIMER=20; KEY_PATH=.ssh/"${VMNAME}.key"
openstack keypair create $VMNAME >> $KEY_PATH; chmod 600 .ssh/"${VMNAME}.key"
nova boot --flavor $FLAVOR\
--image Image-Id\
--key-name $VMNAME\
--security-groups group-id\
--user-data start_calculation.sh\
$VMNAME
echo -e "$TIME start creating VM $VMNAME, status - $STATUS\n" >> vm_launching.log
for i in `seq 1 3`; do
echo -ne "$i attempt to start VM \033[0K\r"
sleep $TIMER & wait
STATUS=`openstack server list | grep $VMNAME | awk '{ print $6 }'`
IP=`openstack server list | grep $VMNAME | awk '{ split($8, v, "="); print v[2]}'`
SYSTEM=`openstack server list | grep $VMNAME | awk '{ print $10 $11 }'`
if [ "x$STATUS" = "xACTIVE" ]; then
printf "VM $VMNAME is $STATUS, IP address $IP, system $SYSTEM\n"
echo "$TIME VM $VMNAME is $STATUS, IP address $IP, system $SYSTEM" >> vm_launching.log
printf "To connect use: ssh -i $KEY_PATH ubuntu@$IP\n"
echo -e "To connect use: ssh -i $KEY_PATH ubuntu@$IP\n" >> vm_launching.log
exit 0
fi
done
if test -z "$STATUS"; then
echo "Launching $VMNAME failed"
echo -e "$TIME Launching VM $VMNAME failed\n" >> vm_launching.log
else
printf "Launching $VMNAME failed with status: $STATUS"
echo -e "$TIME Launching VM $VMNAME failed\n" >> vm_launching.log
fi
private_key=".ssh/${VMNAME}.key"
if [ -f $private_key ]; then
rm $private_key
echo "Private key file '$private_key' has been removed."
else
echo "Private key file '$private_key' not found."
fi
# remove keypair if it exists
if openstack keypair show $VMNAME > /dev/null 2>&1; then
openstack keypair delete $VMNAME
echo "Keypair ${VMNAME} has been deleted."
else
echo "Keypair ${VMNAME} does not exist"
fi
# check if it the instance exists
if openstack server show $VMNAME > /dev/null 2>&1; then
openstack server stop $VMNAME && openstack server delete $VMNAME
echo "Instance ${VMNAME} has been deleted."
else
echo "Instance ${VMNAME} does not exist."
fi
the same in Openstack v1
Using ubuntu:18.04 as a system without virtualization.