first commit

This commit is contained in:
2025-07-04 01:04:19 +02:00
commit 5d340a6711
6 changed files with 106 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
logs/

21
Dockerfile Normal file
View File

@@ -0,0 +1,21 @@
FROM debian:12.11-slim
RUN apt-get update && apt-get install -y wget
ENV MAX_LOGS="20"
ENV LOG_DIR="/var/log/glassminers"
ENV LOG_DATE_FORMAT="%Y-%m-%d-%H-%M-%S"
RUN mkdir -p ${LOG_DIR}
WORKDIR "/usr/local/bin/glassminers"
COPY ./scripts/download_server.sh ./
COPY ./scripts/run_server.sh ./
RUN chmod 777 ./*.sh
RUN ./download_server.sh
CMD ["./run_server.sh"]
EXPOSE 9876

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
# Glassminers Server Docker
This project aims to dockerize the server of the [Glassminers](https://github.com/surrealtm/Glassminers)

15
docker-compose.yaml Normal file
View File

@@ -0,0 +1,15 @@
services:
glassminers_server:
build:
context: .
dockerfile: Dockerfile
network: host
restart: unless-stopped
environment:
- MAX_LOGS=5
# - LOG_DIR="/var/log/glassminers"
# - LOG_DATE_FORMAT="%Y-%m-%d-%H-%M-%S" # No spaces
volumes:
- ./logs:/var/log/glassminers
ports:
- 9876:9876/tcp

View File

@@ -0,0 +1,14 @@
#!/bin/bash
EXEC=server.out
echo "[Info] Downloading latest server version..."
wget https://github.com/surrealtm/Glassminers/releases/latest/download/GMServer.out -O "$EXEC"
if [ $? -ne 0 ]; then
echo "[Error] Download failed! Aborting."
exit 1
fi
chmod +x "$EXEC"
echo "[Info] Download completed successfully."

52
scripts/run_server.sh Normal file
View File

@@ -0,0 +1,52 @@
#!/bin/bash
MAX_LOGS=${MAX_LOGS:-20}
LOG_DIR=${LOG_DIR:-"/var/log/glassminers"}
LOG_DATE_FORMAT=${LOG_DATE_FORMAT:-"%Y-%m-%d-%H-%M-%S"}
EXEC=./server.out
TIMESTAMP=$(date +"$LOG_DATE_FORMAT")
delete_old_logs() {
if [ -d "$LOG_DIR" ]; then
NUM_LOGS=$(ls -1q "$LOG_DIR"/*.log 2>/dev/null | wc -l)
if ((NUM_LOGS > MAX_LOGS)); then
OLDEST_LOGS=$(ls -1t "$LOG_DIR"/*.log | tail -n $((NUM_LOGS - MAX_LOGS)))
for log_file in $OLDEST_LOGS; do
rm "$log_file"
echo "[Info] Removed old log: $log_file"
done
fi
fi
}
rename_log() {
if [ -f "$LOG_DIR/latest.log" ]; then
STOP_TIMESTAMP=$(date +"$LOG_DATE_FORMAT")
mv "$LOG_DIR/latest.log" "$LOG_DIR/$STOP_TIMESTAMP.log"
echo "[Info] Renamed latest.log to $STOP_TIMESTAMP.log"
else
echo "[Warning] No latest.log file to rename"
fi
}
clean_up() {
rename_log
delete_old_logs
}
trap 'clean_up; exit 0' SIGTERM
echo "[Info] Max number of logs set to $MAX_LOGS"
echo "[Info] Server is starting at [$TIMESTAMP]"
$EXEC >"$LOG_DIR/latest.log" &
SERVER_PID=$!
wait $SERVER_PID
EXIT_STATUS=$?
clean_up
echo "[Info] Server stopped at [$(date +"$LOG_DATE_FORMAT")] with exit code: $EXIT_STATUS"
sleep 5