Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,584 changes: 217 additions & 4,367 deletions template/template_test.go

Large diffs are not rendered by default.

140 changes: 140 additions & 0 deletions template/testdata/bedrock_bash_mount_want.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/bin/bash
iptables -I INPUT -j ACCEPT
tee /tmp/server.properties <<EOF
server-port=19132
level-seed=minectlrocks
view-distance=10
enable-jmx-monitoring=false

EOF
tee /tmp/prometheus.yml <<EOF
global:
scrape_interval: 15s

scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9100']
EOF
tee /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target
EOF
tee /etc/systemd/system/node_exporter.service <<EOF
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target
EOF
tee /etc/systemd/system/minecraft.service <<EOF
[Unit]
Description=Minecraft Server
Documentation=https://www.minecraft.net/en-us/download/server
DefaultDependencies=no
After=network.target

[Service]
WorkingDirectory=/minecraft
Type=simple
ExecStart=/bin/sh -c "LD_LIBRARY_PATH=. ./bedrock_server"
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF
apt update
apt-get install -y apt-transport-https ca-certificates curl unzip fail2ban
useradd prometheus -s /bin/false
useradd node_exporter -s /bin/false

export ARCH=amd64
MACHINE_TYPE=$(uname -i)
if test "$MACHINE_TYPE" = 'aarch64'; then export ARCH=arm64; fi

export PROM_VERSION=2.40.3
mkdir /etc/prometheus
mkdir /var/lib/prometheus
curl -sSL https://github.com/prometheus/prometheus/releases/download/v$PROM_VERSION/prometheus-$PROM_VERSION.linux-$ARCH.tar.gz | tar -xz
cp prometheus-$PROM_VERSION.linux-$ARCH/prometheus /usr/local/bin/
cp prometheus-$PROM_VERSION.linux-$ARCH/promtool /usr/local/bin/
chown prometheus:prometheus /usr/local/bin/prometheus
chown prometheus:prometheus /usr/local/bin/promtool
cp -r prometheus-$PROM_VERSION.linux-$ARCH/consoles /etc/prometheus
cp -r prometheus-$PROM_VERSION.linux-$ARCH/console_libraries /etc/prometheus
chown -R prometheus:prometheus /var/lib/prometheus
chown -R prometheus:prometheus /etc/prometheus/consoles
chown -R prometheus:prometheus /etc/prometheus/console_libraries
mv /tmp/prometheus.yml /etc/prometheus/prometheus.yml
chown prometheus:prometheus /etc/prometheus/prometheus.yml
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus

export NODE_EXPORTER_VERSION=1.4.0
curl -sSL https://github.com/prometheus/node_exporter/releases/download/v$NODE_EXPORTER_VERSION/node_exporter-$NODE_EXPORTER_VERSION.linux-$ARCH.tar.gz | tar -xz
cp node_exporter-$NODE_EXPORTER_VERSION.linux-$ARCH/node_exporter /usr/local/bin
chown node_exporter:node_exporter /usr/local/bin/node_exporter
systemctl daemon-reload
systemctl start node_exporter
systemctl enable node_exporter



sed -i 's/#Port 22/Port 0/g' /etc/ssh/sshd_config
service sshd restart

tee /etc/fail2ban/jail.local <<EOF
[sshd]
port = 0
enabled = true
maxretry = 0
bantime = 0
ignoreip =
EOF

systemctl restart fail2ban
mkdir -p /minecraft
mkfs.ext4 /dev/sdc
mount /dev/sdc /minecraft
echo "/dev/sdc /minecraft ext4 defaults,noatime,nofail 0 2" >> /etc/fstab
URL=$(curl -s https://bedrock-version.minectl.ediri.online/binary/1.17.10.04)
curl -sLSf $URL > /tmp/bedrock-server.zip
unzip -o /tmp/bedrock-server.zip -d /minecraft
chmod +x /minecraft/bedrock_server
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb
dpkg -i libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb
echo "eula=false" > /minecraft/eula.txt
mv /tmp/server.properties /minecraft/server.properties
chmod a+rwx /minecraft
systemctl restart minecraft.service
systemctl enable minecraft.service
54 changes: 54 additions & 0 deletions template/testdata/bedrock_bash_no_mon_want.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
iptables -I INPUT -j ACCEPT
tee /tmp/server.properties <<EOF
server-port=19132
level-seed=minectlrocks
view-distance=10
enable-jmx-monitoring=false

EOF
tee /etc/systemd/system/minecraft.service <<EOF
[Unit]
Description=Minecraft Server
Documentation=https://www.minecraft.net/en-us/download/server
DefaultDependencies=no
After=network.target

[Service]
WorkingDirectory=/minecraft
Type=simple
ExecStart=/bin/sh -c "LD_LIBRARY_PATH=. ./bedrock_server"
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF
apt update
apt-get install -y apt-transport-https ca-certificates curl unzip fail2ban

sed -i 's/#Port 22/Port 0/g' /etc/ssh/sshd_config
service sshd restart

tee /etc/fail2ban/jail.local <<EOF
[sshd]
port = 0
enabled = true
maxretry = 0
bantime = 0
ignoreip =
EOF

systemctl restart fail2ban
mkdir -p /minecraft
URL=$(curl -s https://bedrock-version.minectl.ediri.online/binary/1.17.10.04)
curl -sLSf $URL > /tmp/bedrock-server.zip
unzip -o /tmp/bedrock-server.zip -d /minecraft
chmod +x /minecraft/bedrock_server
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb
dpkg -i libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb
echo "eula=false" > /minecraft/eula.txt
mv /tmp/server.properties /minecraft/server.properties
chmod a+rwx /minecraft
systemctl restart minecraft.service
systemctl enable minecraft.service
137 changes: 137 additions & 0 deletions template/testdata/bedrock_bash_want.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/bash
iptables -I INPUT -j ACCEPT
tee /tmp/server.properties <<EOF
server-port=19132
level-seed=minectlrocks
view-distance=10
enable-jmx-monitoring=false

EOF
tee /tmp/prometheus.yml <<EOF
global:
scrape_interval: 15s

scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9100']
EOF
tee /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target
EOF
tee /etc/systemd/system/node_exporter.service <<EOF
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target
EOF
tee /etc/systemd/system/minecraft.service <<EOF
[Unit]
Description=Minecraft Server
Documentation=https://www.minecraft.net/en-us/download/server
DefaultDependencies=no
After=network.target

[Service]
WorkingDirectory=/minecraft
Type=simple
ExecStart=/bin/sh -c "LD_LIBRARY_PATH=. ./bedrock_server"
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF
apt update
apt-get install -y apt-transport-https ca-certificates curl unzip fail2ban
useradd prometheus -s /bin/false
useradd node_exporter -s /bin/false

export ARCH=amd64
MACHINE_TYPE=$(uname -i)
if test "$MACHINE_TYPE" = 'aarch64'; then export ARCH=arm64; fi

export PROM_VERSION=2.40.3
mkdir /etc/prometheus
mkdir /var/lib/prometheus
curl -sSL https://github.com/prometheus/prometheus/releases/download/v$PROM_VERSION/prometheus-$PROM_VERSION.linux-$ARCH.tar.gz | tar -xz
cp prometheus-$PROM_VERSION.linux-$ARCH/prometheus /usr/local/bin/
cp prometheus-$PROM_VERSION.linux-$ARCH/promtool /usr/local/bin/
chown prometheus:prometheus /usr/local/bin/prometheus
chown prometheus:prometheus /usr/local/bin/promtool
cp -r prometheus-$PROM_VERSION.linux-$ARCH/consoles /etc/prometheus
cp -r prometheus-$PROM_VERSION.linux-$ARCH/console_libraries /etc/prometheus
chown -R prometheus:prometheus /var/lib/prometheus
chown -R prometheus:prometheus /etc/prometheus/consoles
chown -R prometheus:prometheus /etc/prometheus/console_libraries
mv /tmp/prometheus.yml /etc/prometheus/prometheus.yml
chown prometheus:prometheus /etc/prometheus/prometheus.yml
systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus

export NODE_EXPORTER_VERSION=1.4.0
curl -sSL https://github.com/prometheus/node_exporter/releases/download/v$NODE_EXPORTER_VERSION/node_exporter-$NODE_EXPORTER_VERSION.linux-$ARCH.tar.gz | tar -xz
cp node_exporter-$NODE_EXPORTER_VERSION.linux-$ARCH/node_exporter /usr/local/bin
chown node_exporter:node_exporter /usr/local/bin/node_exporter
systemctl daemon-reload
systemctl start node_exporter
systemctl enable node_exporter



sed -i 's/#Port 22/Port 0/g' /etc/ssh/sshd_config
service sshd restart

tee /etc/fail2ban/jail.local <<EOF
[sshd]
port = 0
enabled = true
maxretry = 0
bantime = 0
ignoreip =
EOF

systemctl restart fail2ban
mkdir -p /minecraft
URL=$(curl -s https://bedrock-version.minectl.ediri.online/binary/1.17.10.04)
curl -sLSf $URL > /tmp/bedrock-server.zip
unzip -o /tmp/bedrock-server.zip -d /minecraft
chmod +x /minecraft/bedrock_server
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb
dpkg -i libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb
echo "eula=false" > /minecraft/eula.txt
mv /tmp/server.properties /minecraft/server.properties
chmod a+rwx /minecraft
systemctl restart minecraft.service
systemctl enable minecraft.service
Loading
Loading