Last active
December 14, 2023 18:25
-
-
Save ratulbasak/7e9bc46008a744651680876ff8c70d2b to your computer and use it in GitHub Desktop.
Autoscale Ejabberd Cluster in AWS
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 | |
REGION="ap-southeast-1" | |
get_ip=$(curl -s curl http://169.254.169.254/latest/meta-data/local-ipv4) | |
echo "Node IP : $get_ip" | |
sudo sed -i "s/INET_DIST_INTERFACE=.*/INET_DIST_INTERFACE={$get_ip}/g" /opt/ejabberd/conf/ejabberdctl.cfg | |
sudo sed -i "s/ERLANG_NODE=ejabberd@.*/ERLANG_NODE=ejabberd@$get_ip/g" /opt/ejabberd/conf/ejabberdctl.cfg | |
sudo rm -rf /opt/ejabberd/database/* | |
export HOME=/root | |
echo $HOME | |
sudo systemctl start ejabberd.service | |
sleep 10 | |
echo "...............Restarted.........................." | |
asg_ip=($(aws autoscaling describe-auto-scaling-instances --region $REGION --output text \ | |
--query "AutoScalingInstances[?AutoScalingGroupName=='Prod-Ejabberd-ASG'].InstanceId" \ | |
| xargs -n1 aws ec2 describe-instances --instance-ids $ID --region $REGION \ | |
--query "Reservations[].Instances[].PrivateIpAddress" --output text)) | |
echo "All Nodes are: ${asg_ip[@]}" | |
if [ ${#asg_ip[@]} -eq 1 ]; then | |
echo "|INFO|: Single Node found in ASG >> ${#asg_ip[@]}" | |
else | |
echo "Node IP :$get_ip is found in All Nodes..." | |
delete=($get_ip) | |
for target in "${delete[@]}"; do | |
for i in "${!asg_ip[@]}"; do | |
if [[ ${asg_ip[i]} = $target ]]; then | |
unset 'asg_ip[i]' | |
echo "|INFO|: Joining to >> ejabberd@${asg_ip[0]}" | |
sudo /opt/ejabberd-19.05/bin/ejabberdctl join_cluster ejabberd@${asg_ip[0]} | |
echo "......................Joined..........................." | |
fi | |
done | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment