forked from VeriorPies/MineCloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting up a DNS name for the minecloud server
Implements VeriorPies#68 A DNS name is setup automatically when the parameter DOMAIN_NAME is set to a name pointing to an existing Hosted Zone. Setting up a hosted zone on AWS involves purchasing a domain and paying a for it on a yearly basis. This makes it hard to automate and is therefore left out of the automation. Instead an existing hosted zone is referenced by the value of the parameter DOMAIN_NAME in the MineCloud-Service-Info.ts file. When this parameter is set, an additional branch of the CDK script gets executed, which assigns some additional policies to the EC2 role to allow the VM to lookup the hosted zone id to update the IP address of the ARecord, which has been created by CDK. The DNS name is derived by appending the value of DOMAIN_NAME to the hostname "minecloud". The DOMAIN_NAME is attached as a tag to the EC2 instance to make it accessible to the start_service.sh script which updates the ARecord with the assigned IP address. The bot pushes the domain name to the Discord channel only when the DOMAIN_NAME parameter has been set. The changeset also includes a change to avoid the file MineCloud-Service-Info.ts with all the private data being committed to Git accidentally. Therefore the file is renamed to MineCloud-Service-Info.ts.sample and the README is updated to make a copy to the actual name MineCloud-Service-Info.ts before setting all the parameters. The MineCloud-Service-Info.ts is set to the .gitignore list so that the actual file is ignored upon git commits.
mirumpf
committed
Oct 3, 2023
1 parent
dc4b7bf
commit 01c07ef
Showing
5 changed files
with
104 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
cd /opt/minecloud | ||
echo "Server started: $(date)" | ||
public_ip=$(dig +short myip.opendns.com @resolver1.opendns.com) | ||
echo "new ip: $public_ip" | ||
./send_discord_message_to_webhook.sh "The server instance is ready >w< ! Here's the IP address:\n$public_ip" | ||
echo "Discord public IP sent" | ||
|
||
MY_IP=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4/) | ||
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id/) | ||
AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/) | ||
|
||
DOMAIN_NAME=$(aws ec2 describe-tags --region ${AZ::-1} --filters "Name=resource-id,Values=${INSTANCE_ID}" --query 'Tags[?Key==`DOMAIN_NAME`].Value' --output text) | ||
if [ ! -z "$DOMAIN_NAME" ] | ||
then | ||
DNS_NAME="minecloud.$DOMAIN_NAME" | ||
|
||
ZONE=$(aws route53 list-hosted-zones-by-name --dns-name $DOMAIN_NAME --query "HostedZones[].Id" --output text) | ||
ZONE_ID=${ZONE##*/} | ||
|
||
aws route53 change-resource-record-sets --hosted-zone-id $ZONE_ID --change-batch '{"Changes":[{"Action":"UPSERT","ResourceRecordSet":{"Name":"'$DNS_NAME'","Type":"A","TTL":60,"ResourceRecords":[{"Value":"'$MY_IP'"}]}}]}' | ||
echo "hostname (ip): $DNAME_NAME ($MY_IP)" | ||
./send_discord_message_to_webhook.sh "The server instance is ready >w< ! Here's the hostname/IP address:\n$DNS_NAME ($MY_IP)" | ||
echo "Discord hostname & public IP sent" | ||
else | ||
echo "ip: $MY_IP" | ||
./send_discord_message_to_webhook.sh "The server instance is ready >w< ! Here's the IP address:\n$MY_IP" | ||
echo "Discord public IP sent" | ||
fi | ||
|
||
#start the Minecloud server | ||
echo "starting server" | ||
cd server | ||
./start_server.sh | ||
echo "server stop" | ||
echo "server stop" |