This commit is contained in:
Alex Pickering 2024-04-24 17:04:01 -05:00
parent ece2007c14
commit acce6b2873
16 changed files with 251 additions and 60 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
secrets.lua
terraform.tfstate

View File

@ -13,9 +13,10 @@ data_templated=$(wildcard src/data/*.etlua)
data_built=$(data_templated:src/data/%.etlua=build/data/%)
data_copied=$(data_files:src/data/%=build/data/%)
data_immediate=$(filter-out $(data_built),$(data_copied))
data_zipped=$(data_immediate) $(data_built)
built=$(srcs:src/%.etlua=build/%) # other files after preprocessing
ready=$(built) $(startup_built) $(data_built)
ready=$(built) $(startup_built) $(data_built) build/data.zip
all: $(ready)
echo "Ready: $(startup_built)"
@ -33,6 +34,9 @@ $(data_immediate) : build/data/% : src/data/% config.lua
$(data_built) : build/data/% : src/data/%.etlua config.lua
cat $< | $(pp) > $@
build/data.zip : $(data_zipped)
zip -r build/data build/data
build/init.tf : config.lua
clean:

View File

@ -19,16 +19,19 @@ local config = {
}
-- Each machine gets a startup script, located in src/startup that configures
-- it when the vps starts up for the first time.
-- it when the vps starts up for the first time. Reprovisioning the machine also
-- reprovisions attached elastic block storage, make sure your data is backed up
-- to the s3 bucket!
config.machines = {
main = {
ebs = 500,
size = "t3.medium",
size = "r7a.medium",
},
sidecar = {
size = "t3.nano",
}
}
-- Minecraft mods!
config.mods = {
shared = {
@ -53,15 +56,20 @@ config.mods = {
-- Handcrafted - more decoration
"https://cdn.modrinth.com/data/pJmCFF0p/versions/K4jSQsxb/handcrafted-fabric-1.20.4-3.2.1.jar",
"https://cdn.modrinth.com/data/G1hIVOrD/versions/TiIWVg2u/resourcefullib-fabric-1.20.4-2.4.10.jar",
--Basic weapons
"https://cdn.modrinth.com/data/sc2Pektv/versions/zSdnkMN9/basicweapons-fabric-mc1.20.4%2B1.2.0.jar",
-- Travelers backpack
"https://cdn.modrinth.com/data/rlloIFEV/versions/AdxNPxLV/travelersbackpack-fabric-1.20.4-9.4.3.jar",
"https://cdn.modrinth.com/data/K01OU20C/versions/DObEjZD4/cardinal-components-api-5.4.0.jar",
-- Just enough items, needed on server for "+"
"https://cdn.modrinth.com/data/u6dRKJwZ/versions/HPR5ThoH/jei-1.20.4-fabric-17.3.0.49.jar",
},
server = {
--Aditional Structures
-- Aditional Structures
"https://cdn.modrinth.com/data/TWsbC6jW/versions/4aO595R4/AdditionalStructures-1.20.x-%28v.4.2.1%29.jar",
"https://cdn.modrinth.com/data/9s6osm5g/versions/eBZiZ9NS/cloth-config-13.0.121-fabric.jar",
--Yung's *
-- Yung's *
"https://cdn.modrinth.com/data/Ua7DFN59/versions/RXxBbRs7/YungsApi-1.20.4-Fabric-4.4.2.jar",
"https://cdn.modrinth.com/data/HjmxVlSr/versions/St6cNi1U/YungsBetterMineshafts-1.20.4-Fabric-4.4.1.jar",
"https://cdn.modrinth.com/data/kidLKymU/versions/lT8OssHA/YungsBetterStrongholds-1.20.4-Fabric-4.4.1.jar",
@ -71,19 +79,24 @@ config.mods = {
"https://cdn.modrinth.com/data/3dT9sgt4/versions/M9acJ70z/YungsBetterOceanMonuments-1.20.4-Fabric-3.4.1.jar",
"https://cdn.modrinth.com/data/Z2mXHnxP/versions/W7R83Bhr/YungsBetterNetherFortresses-1.20.4-Fabric-2.4.2.jar",
"https://cdn.modrinth.com/data/t5FRdP87/versions/hXyLPxPz/YungsBetterWitchHuts-1.20.4-Fabric-3.4.1.jar",
--Terralith
"https://cdn.modrinth.com/data/z9Ve58Ih/versions/csNNUblm/YungsBetterJungleTemples-1.20.4-Fabric-2.4.1.jar",
"https://cdn.modrinth.com/data/2BwBOmBQ/versions/sPWRtsih/YungsBetterEndIsland-1.20.4-Fabric-2.4.1.jar",
"https://cdn.modrinth.com/data/ZYgyPyfq/versions/F1adMKW8/YungsExtras-1.20.4-Fabric-4.4.0.jar",
-- Terralith
"https://cdn.modrinth.com/data/cl223EMc/versions/3aypqSNl/cristellib-1.2.4-fabric.jar",
"https://cdn.modrinth.com/data/DjLobEOy/versions/bwfVhUnU/t_and_t-1.12.1.1.jar",
"https://cdn.modrinth.com/data/8oi3bsk5/versions/zA1qYB0L/Terralith_1.20.4_v2.4.11_FABRIC.jar",
--Dungeons and Taverns
-- Dungeons and Taverns
"https://cdn.modrinth.com/data/tpehi7ww/versions/xwTzTss5/dungeons-and-taverns-3.1.1.jar",
--Vein miner
-- Overhauled village
"https://cdn.modrinth.com/data/fgmhI8kH/versions/KXEQACvr/ctov-fabric-3.4.3.jar",
-- Vein miner
"https://cdn.modrinth.com/data/OhduvhIc/versions/DCSFfJF9/Veinminer-2.0.3.jar",
"https://cdn.modrinth.com/data/aTaCgKLW/versions/qm0TSoQL/silk-all-1.10.3.jar",
"https://cdn.modrinth.com/data/Ha28R6CL/versions/ZMokinzs/fabric-language-kotlin-1.10.19%2Bkotlin.1.9.23.jar",
--Profundis
-- Profundis
"https://cdn.modrinth.com/data/aucz7XCt/versions/qX0iNakQ/profundis-1.6.2.jar",
--Sleep
-- Sleep
"https://cdn.modrinth.com/data/Cw8IlnGM/versions/2LFCQnd1/serversleep-datapack.jar",
-- More structures
"https://cdn.modrinth.com/data/rYlnn25U/versions/qu1FkIzJ/adorabuild-structures-2.6.0-fabric-1.20.4.jar",
@ -91,6 +104,28 @@ config.mods = {
"https://cdn.modrinth.com/data/HSfsxuTo/versions/DFkIejTe/explorify-v1.3.0-mc1.20.jar",
-- Inventory sorting
"https://cdn.modrinth.com/data/5ibSyLAz/versions/MO3Q3zs2/InventorySorter-1.9.0-1.20.4.jar",
-- Optimizations
"https://cdn.modrinth.com/data/gvQqBUqZ/versions/nMhjKWVE/lithium-fabric-mc1.20.4-0.12.1.jar",
-- Keep items
"https://cdn.modrinth.com/data/lL35xmSR/versions/XG0TklFV/youritemsaresafe-1.20.4-4.2.jar",
-- Tree cutting
"https://cdn.modrinth.com/data/Fb4jn8m6/versions/mb15RrXi/FallingTree-1.20.4-1.20.4.3.jar",
-- Incendium, nether additions
"https://cdn.modrinth.com/data/ZVzW5oNS/versions/BxVLGy3y/Incendium_1.20.4_v5.3.4.jar",
-- Don't display terralith message
"https://cdn.modrinth.com/data/sk4iFZGy/versions/2jAppOW4/remove-terralith-intro-message-1.0.jar",
-- Backups!
"https://cdn.modrinth.com/data/Jrmoreqs/versions/3SI3svDb/AdvancedBackups-fabric-1.20.4-3.5.1.jar",
-- Camps castles and carriages
"https://cdn.modrinth.com/data/h9XxzZxe/versions/uI06GjwK/camps_castles_carriages-2.3.jar",
-- Moog's nether structures
"https://cdn.modrinth.com/data/nGUXvjTa/versions/PTf5Y56P/mns-1.0.1-1.20-fabric.jar",
-- Moog's voyager structures
"https://cdn.modrinth.com/data/OQAgZMH1/versions/tbOvFJdA/mvs-4.1.2-1.20-fabric.jar",
-- Moog's end structures
"https://cdn.modrinth.com/data/r4PuRGfV/versions/s3M8KkSa/mes-1.3.1-1.20-fabric.jar",
-- When Dungeon Arise
"https://cdn.modrinth.com/data/ZsrrjDbP/versions/AxIOkvEv/DungeonsAriseSevenSeas-1.19.2-1.0.2-forge.jar",
},
client = {
@ -111,13 +146,16 @@ config.mods = {
-- Hunger bar tweaks
"https://cdn.modrinth.com/data/EsAfCjCV/versions/pmFyu3Sz/appleskin-fabric-mc1.20.3-2.5.1.jar",
-- Just enough items
"https://cdn.modrinth.com/data/u6dRKJwZ/versions/HPR5ThoH/jei-1.20.4-fabric-17.3.0.49.jar",
"https://cdn.modrinth.com/data/uEfK2CXF/versions/FjwDwtUL/JustEnoughResources-Fabric-1.20.4-1.5.0.4.jar",
"https://cdn.modrinth.com/data/9Pk89J3g/versions/rWDKPxQZ/justenoughbreeding-fabric-1.20.4-1.2.1.jar",
-- Lightmatica - blueprints
"https://cdn.modrinth.com/data/GcWjdA9I/versions/kZJWQDi6/malilib-fabric-1.20.4-0.18.1.jar",
"https://masa.dy.fi/mcmods/litematica/litematica-fabric-1.20.4-0.17.3-pre.1.jar",
"https://cdn.modrinth.com/data/3llatzyE/versions/xeDghx1o/litematica-printer-1.20.4-3.2.1.jar",
-- CIT, allows datapacks to have textures
"https://cdn.modrinth.com/data/otVJckYQ/versions/MU5nRGAS/citresewn-1.1.5%2B1.20.4.jar",
"https://cdn.modrinth.com/data/BVzZfTc1/versions/qMoPCh9Z/entity_texture_features_fabric_1.20.4-5.2.3.jar",
"https://cdn.modrinth.com/data/4I1XuqiY/versions/bwjbN1G7/entity_model_features_fabric_1.20.4-1.3.jar",
},
}
@ -125,10 +163,17 @@ config.mods = {
-- Resource packs to download
config.resource_packs = {
shared = {},
server = {},
server = {
},
client = {
-- Redstone tweaks
"https://cdn.modrinth.com/data/RvfAlf4Z/versions/6x5Vyy2c/Redstone%20Tweaks%202.4.3.zip",
-- Incedium textures
"https://cdn.modrinth.com/data/HfNmMQ9E/versions/DoalfjbG/Sparkles_1.20.4_v1.0.5.zip",
-- Textures for enchanted books
"https://cdn.modrinth.com/data/6udpuGCH/versions/Hk6zJ311/EBE_1.20.x_v1.1.zip",
-- Textures for potions
"https://cdn.modrinth.com/data/yFn9hTiq/versions/cCOinnlk/xali%27s%20Potions%20v1.0.0.zip",
},
}
-- Shaders, only makes sense client side
@ -146,7 +191,18 @@ config.shaders = {
-- Patches to apply to the instance
config.config = {
shared = {},
server = {},
server = {
["ops.json"] = immediate([[
[
{
"uuid": ""a7568061-843d-4aa6-bc45-96880c5a8747",
"name": "PartiallyPlatapus",
"level": 4,
"bypassPlayerLimit": true
}
]
]]),
},
client = {
[".minecraft/config/iris.properties"] = immediate([[
#This file stores configuration options for Iris, such as the currently active shaderpack
@ -234,8 +290,8 @@ glintStrength:0.75
damageTiltStrength:1.0
highContrast:false
narratorHotkey:true
gamma:0.5
renderDistance:12
gamma:1.0
renderDistance:16
simulationDistance:12
entityDistanceScaling:1.0
guiScale:2
@ -246,8 +302,8 @@ ao:true
prioritizeChunkUpdates:0
biomeBlendRadius:2
renderClouds:"true"
resourcePacks:["vanilla","fabric","file/Redstone%20Tweaks%202.4.3.zip"]
incompatibleResourcePacks:["appleskin","balm-fabric","controlling","jade","jei","jeresources","rechiseled","searchables","supermartijn642corelib","waystones"]
resourcePacks:["vanilla","fabric","file/Redstone%20Tweaks%202.4.3.zip","file/EBE_1.20.x_v1.1.zip","file/xali%27s%20Potions%20v1.0.0.zip","file/Sparkles_1.20.4_v1.0.5.zip"]
incompatibleResourcePacks:["appleskin","balm-fabric","controlling","jade","jei","jeresources","justenoughbreeding","rechiseled","searchables","supermartijn642corelib","waystones","file/EBE_1.20.x_v1.1.zip","file/xali%27s%20Potions%20v1.0.0.zip"]
lastServer:
lang:en_us
soundDevice:""
@ -276,7 +332,7 @@ tutorialStep:movement
mouseWheelSensitivity:1.0
rawMouseInput:true
glDebugVerbosity:1
skipMultiplayerWarning:false
skipMultiplayerWarning:true
skipRealms32bitWarning:false
hideMatchedNames:true
joinedFirstServer:false
@ -322,7 +378,42 @@ key_key.hotbar.6:key.keyboard.6
key_key.hotbar.7:key.keyboard.7
key_key.hotbar.8:key.keyboard.8
key_key.hotbar.9:key.keyboard.9
]])
key_key.extraalchemy.magnetism_toggle:key.keyboard.n
key_key.extraalchemy.potion_bag_mode:key.keyboard.k
key_key.jade.config:key.keyboard.keypad.0
key_key.jade.show_overlay:key.keyboard.keypad.1
key_key.jade.toggle_liquid:key.keyboard.keypad.2
key_key.jade.show_recipes:key.keyboard.keypad.3
key_key.jade.show_uses:key.keyboard.keypad.4
key_key.jade.narrate:key.keyboard.keypad.5
key_key.jade.show_details_alternative:key.keyboard.unknown
key_key.lighty.enable:key.keyboard.f7
key_key.lighty.toggle:key.keyboard.f8
key_key.modmenu.open_menu:key.keyboard.unknown
key_key.travelersbackpack.inventory:key.keyboard.b
key_key.travelersbackpack.toggle_tank:key.keyboard.n
key_key.travelersbackpack.cycle_tool:key.keyboard.z
key_iris.keybind.reload:key.keyboard.r
key_iris.keybind.toggleShaders:key.keyboard.k
key_iris.keybind.shaderPackSelection:key.keyboard.o
soundCategory_master:1.0
soundCategory_music:1.0
soundCategory_record:1.0
soundCategory_weather:1.0
soundCategory_block:1.0
soundCategory_hostile:1.0
soundCategory_neutral:1.0
soundCategory_player:1.0
soundCategory_ambient:1.0
soundCategory_voice:1.0
modelPart_cape:true
modelPart_jacket:true
modelPart_left_sleeve:true
modelPart_right_sleeve:true
modelPart_left_pants_leg:true
modelPart_right_pants_leg:true
modelPart_hat:true
]]),
},
}

View File

@ -1,11 +1,9 @@
# Readme
This is a little pile of scripts to configure stuff on the AWS cloud.
In general, create a setup script under `src/startup/your_service_name.sh.etlua`,
Then add `your_service_name` to `config.lua` under the `services`, and `machines`.
`your_service_name.sh.etlua` will be preprocessed with [etlua](), then run in a
chroot on the machine configured in `machines`. Everything else is configured
in `src/main.tf.etlua` and should generally not be touched.
This is a little pile of scripts to configure a Minecraft server on AWS and Namecheap.
In general, the `config.lua` file holds your config, and `secrets.lua` holds api keys.
Each of the vms in `config.lua`.`machines` has a startup script under `src/start/*.sh.etlua`
that gets preprocessed with [etlua]().
### Setup
@ -14,8 +12,8 @@ There are a few one-time set up things:
* Register your domain name, put it in the `config.lua` file
* Create an s3 bucket with any name, and put it's name in the `config.lua` file.
* run make
* Create a hosted zone for your domain name, and set up your registrar with AWS's DNS servers.
* Wait for DNS to resolve
* Connect to the sidecar server, and run certbot:
* while in sidecar server, run `service httpd start` and check that it works in your browser
certbot certonly -d domain.name --standalone
* Run `service httpd start` and check that connecting to the domain works.

View File

@ -1,6 +1,15 @@
local secrets = {
access_key = "<your access key here>",
secret_key = "<your secret key here>"
aws = {
access_key = "access_key",
secret_key = "secret_key",
},
namecheap = {
user_name = "user_name",
api_user = "api_user",
api_key = "api_key",
client_ip = "your_ip",
use_sandbox = true
}
}
return secrets

View File

@ -11,13 +11,12 @@ resource "aws_s3_object" "object" {
resource "aws_s3_object" "site" {
bucket = "<%- config.bucket_name %>"
key = "index.html"
source = "${path.module}/data/index.html"
key = "data.zip"
source = "${path.module}/data.zip"
etag = filemd5("${path.module}/data/index.html")
etag = filemd5("${path.module}/data.zip")
}
<% for filename, value in pairs(config.config.client) do %>
<% if e.is_immediate(value) then %>
resource "aws_s3_object" "config-<%- filename:gsub("[^A-Za-z0-9]","-") %>" {
@ -29,3 +28,16 @@ EOS
}
<% end %>
<% end %>
<% for filename, value in pairs(config.config.server) do %>
<% if e.is_immediate(value) then %>
resource "aws_s3_object" "config-<%- filename:gsub("[^A-Za-z0-9]","-") %>" {
bucket = "<%- config.bucket_name %>"
key = "<%- filename %>"
content = <<EOS
<%- value[1] %>
EOS
}
<% end %>
<% end %>

BIN
src/data/1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
src/data/2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
src/data/3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -44,9 +44,10 @@
stops_el = document.getElementById("stops");
starts_el.innerText = cronstrue.toString(starts_sched);
stops_el.innerText = cronstrue.toString(stops_sched);
set_timer();
});
setInterval(function() {
function set_timer(){
var next_start = later.schedule(starts).next(1);
var next_stop = later.schedule(stops).next(1);
if (next_stop < next_start){
@ -55,7 +56,9 @@
}else{
soon_el.innerText = msToTime(next_start - Date.now())
}
}, 1000);
}
setInterval(set_timer, 1000);
</script>
<h1> Server will come up <span id="soon">when it comes up</span></h1>
<p> Server starts <span id="starts"><%- config.server_starts %></span>
@ -63,4 +66,12 @@
In the meantime, you can download <a href="https://multimc.org/">MultiMC</a>
and add the <a href="/instance.zip">instance</a> so you can play right
away when the server comes up.
<h3> Click "Add Instance" </h3>
<p><img src="/1.png" />
<h3> Click "Import from zip" </h3>
<p><img src="/2.png" />
<h3> Copy paste the url: </h3>
<code><pre>https://txwea.boo/instance.zip</pre></code>
<p><img src="/3.png" />
<h3> And click ok, then launch the instance to connect.</h3>
</html>

Binary file not shown.

View File

@ -13,20 +13,33 @@ terraform {
source = "hashicorp/aws"
version = "~> 5.45"
}
namecheap = {
source = "namecheap/namecheap"
version = ">= 2.0.0"
}
}
required_version = ">= 0.14.9"
}
provider "aws" {
access_key = "<%- secrets.access_key %>"
secret_key = "<%- secrets.secret_key %>"
access_key = "<%- secrets.aws.access_key %>"
secret_key = "<%- secrets.aws.secret_key %>"
region = "<%- config.aws_region %>"
}
provider "namecheap" {
user_name = "<%- secrets.namecheap.user_name %>"
api_user = "<%- secrets.namecheap.api_user %>"
api_key = "<%- secrets.namecheap.api_key %>"
client_ip = "<%- secrets.namecheap.client_ip %>"
use_sandbox = false
}
<% local domain, tld = string.match(config.domain,"(.*)%.(.*)") %>
# This should be created manually, so it never gets accidentally destroyed.
# resource "aws_s3_bucket" "backup-bucket" {
# bucket = "txweaboo-backup"
# bucket = "txweaboo"
# acl = "private"
# }

View File

@ -43,3 +43,4 @@ resource "aws_volume_attachment" "<%- name %>" {
}
<% end %>
<% end %>

View File

@ -102,3 +102,11 @@ resource "aws_route53_record" "mc" {
ttl = 300
records = [aws_eip.main.public_ip]
}
resource "namecheap_domain_records" "my-domain2-com" {
domain = "<%- config.domain %>"
mode = "OVERWRITE"
nameservers = aws_route53_zone.main.name_servers
}

View File

@ -1,22 +1,21 @@
#!/bin/bash
<% local config = require "config" %>
<% local secrets = require "secrets" %>
<% local e = require "express" %>
exec 1>>~/message.log 2>&1
set -x
echo "Starting main" >> ~/message.log
aws configure set aws_access_key_id "<%- secrets.access_key %>"
aws configure set aws_secret_access_key "<%- secrets.secret_key %>"
aws configure set aws_access_key_id "<%- secrets.aws.access_key %>"
aws configure set aws_secret_access_key "<%- secrets.aws.secret_key %>"
mkdir /mnt
mount /dev/sdf /mnt
sudo yum install java-17-amazon-corretto-devel -y
cd /mnt
UA="User-Agent: tempmc (alex@cogarr.net)"
# Download the dedicated server if we don't have it
if [ ! -e fabric-server-mc.1.20.4-loader.0.15.9-launcher.1.0.0.jar ]; then
echo "Downloading fabricmc" >> ~/message.log
@ -33,11 +32,45 @@ echo "Downloading <%- #config.mods.server %> mods" >> ~/message.log
<% for _,mod in pairs(config.mods.server) do %>
URL=<%- mod %>
echo "Checking $(basename $URL)" >> ~/message.log
if [ ! -e "$(basename $URL)" ]; then
echo "Downloading $URL" >> ~/message.log
curl -OJ "$URL"
else
echo "$URL already exists" >> ~/message.log
fi
<% end %>
# Download any config
<% for filename, info in pairs(config.config.server) do %>
<% if e.is_immediate(info) then %>
aws s3 cp s3://<%- config.bucket_name %>/<%- filename %> <%- filename %>
<% elseif e.is_command(info) then %>
<%- info[1] %>
<% end %>
<% end %>
cat > /etc/systemd/system/mc.service<< EOF
[Unit]
Description=Minecraft
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
WorkingDirectory=/mnt
ExecStart=java -jar /mnt/fabric-server-mc.1.20.4-loader.0.15.9-launcher.1.0.0.jar
[Install]
WantedBy=multi-user.target
EOF
service mc start
systemctl enable mc
# Copy backups to s3 every hour
cat > cronfile <<EOF
1 * * * * aws s3 sync /mnt/backups/world/differential s3://<%- config.bucket_name %>/backup
EOF
crontab cronfile

View File

@ -9,7 +9,7 @@ set -x
echo "Hello, sidecar!" >> ~/message.log
cd ~
sudo yum install certbot cronie httpd mod_ssl -y
sudo yum install certbot cronie httpd mod_ssl gcc -y
cat > /etc/httpd/conf.d/ssl.conf<< EOF
LoadModule ssl_module modules/mod_ssl.so
@ -23,18 +23,20 @@ Listen 443
</VirtualHost>
EOF
aws configure set aws_access_key_id "<%- secrets.access_key %>"
aws configure set aws_secret_access_key "<%- secrets.secret_key %>"
aws configure set aws_access_key_id "<%- secrets.aws.access_key %>"
aws configure set aws_secret_access_key "<%- secrets.aws.secret_key %>"
# Scripts that start and stop the main instance
cat > start.sh<< EOF
EID=$(aws ec2 describe-instances | jq -r ".Reservations[].Instances[] | select(.Tags[].Value == \"main instance\").InstanceId")
aws ec2 start-instances --instance-ids $EID
EID=\$(aws ec2 describe-instances | jq -r ".Reservations[].Instances[] | select(.Tags[].Value == \"main instance\").InstanceId")
aws ec2 start-instances --instance-ids \$EID
EOF
chmod +x start.sh
cat > stop.sh<< EOF
EID=$(aws ec2 describe-instances | jq -r ".Reservations[].Instances[] | select(.Tags[].Value == \"main instance\").InstanceId")
aws ec2 stop-instances --instance-ids $EID
EID=\$(aws ec2 describe-instances | jq -r ".Reservations[].Instances[] | select(.Tags[].Value == \"main instance\").InstanceId")
aws ec2 stop-instances --instance-ids \$EID
EOF
chmod +x stop.sh
# Download the multimc instance from s3
@ -69,6 +71,7 @@ if [ ! -e $(basename $URL) ]; then
fi
<% end %>
cd ../..
<% for filename, info in pairs(config.config.client) do %>
<% if e.is_immediate(info) then %>
aws s3 cp s3://<%- config.bucket_name %>/<%- filename %> <%- filename %>
@ -79,12 +82,19 @@ aws s3 cp s3://<%- config.bucket_name %>/<%- filename %> <%- filename %>
<% end %>
<% end %>
# Set up a crontab to start and stop the main server on a schedule
# Then re-zip the instance, and serve a webpage
cd ~
zip -r instance instance
cp instance.zip /var/www/html
aws s3 cp s3://<%- config.bucket_name %>/index.html /var/www/html/index.html
aws s3 cp s3://<%- config.bucket_name %>/data.zip .
unzip -j -n data.zip -d /var/www/html
service httpd start
systemctl enable httpd
# Set up a crontab to start and stop the main server on a schedule
cat > cronfile <<EOF
<%- config.server_starts %> /root/start.sh
<%- config.server_stops %> /root/stop.sh
EOF
crontab cronfile