diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e43b0f98 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/Dockerfile b/Dockerfile index aa04a8d6..f39cdb00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,9 @@ ENV SPIGOT_HOME=/minecraft \ # add extra files needed COPY rootfs / +# add overviewer repository & key +RUN echo "deb http://overviewer.org/debian ./" >> /etc/apt/sources.list && curl http://overviewer.org/debian/overviewer.gpg.asc | apt-key add - + RUN apt-get update && \ # upgrade OS @@ -18,8 +21,8 @@ RUN apt-get update && \ # Make info file about this build printf "Build of nimmis/spigot:latest, date: %s\n" `date -u +"%Y-%m-%dT%H:%M:%SZ"` > /etc/BUILDS/spigot && \ - # install application - apt-get install -y wget git && \ + # install applications, including nginx & overviewer + apt-get install -y wget git nginx minecraft-overviewer && \ # Make special user for minecraft to run in /usr/sbin/useradd -s /bin/bash -d /minecraft -m minecraft && \ @@ -27,8 +30,8 @@ RUN apt-get update && \ # remove apt cache from image apt-get clean all - # expose minecraft port EXPOSE 25565 - +# expose nginx port for overviewer +EXPOSE 80 diff --git a/README.md b/README.md index 1c6a5423..0328ece5 100644 --- a/README.md +++ b/README.md @@ -1,72 +1,72 @@ -## Minecraft server SPIGIT on Ubuntu 16.04 with openjava 1.8 -[![](https://images.microbadger.com/badges/image/nimmis/spigot.svg)](https://microbadger.com/images/nimmis/spigot "Get your own image badge on microbadger.com") +# Docker image with Minecraft (Spigot server) & Overviewer (Mapping) -This docker image builds and runs the spigot version of minecraft. +This docker image builds and runs the spigot version of minecraft. It deploys overviewer within the same container to view your minecraft map. -If the spigot.jar is not found in the minecraft directory the system pulls down BuildTool and build a new spigot.jar from the latest -released minecraft.jar +![Image of a minecraft overworld map rendered in overviewer showing player locations](http://i.imgur.com/846ALCA.png) -Each time the container is started the presence of the file /minecraft/spigot.jar, if the file is missing a build of spigot.jar is started. +All credit to [nimmis](https://github.com/nimmis). This image build upon their work and haphazidly adds overviewer plus some automation. Please see their [README.md](https://github.com/nimmis/docker-spigot) for more info. -The spigot daemon is started with superovisord, see my Ubuntu container for a more detailed description of my implementation of an init-process in ubuntu, see [nimmis/ubuntu](https://hub.docker.com/r/nimmis/ubuntu/) +### What's included? -Whats new is -- adjust minecraft user UID to match mounted volume -- selectable memory size for the Java process -- selectable spigot version -- do a nice shutdown of the server when the docker stop command is issued -- docker accessible commands to - - start/stop/restart the spigot server - - send console commands to the server - - look at console output from the server -- +- [Spigot](https://www.spigotmc.org) Minecraft server. + - The latest version is downloaded upon first run. +- [Overviewer](https://overviewer.org/) mapping. + - Player locations shown by default + - In-game [signs](http://minecraft.gamepedia.com/Sign) with the first row of text set to "!" can be shown or hidden. +- Automatic Overviewer map refreshes every 30 mins, with player locations and signs every 10 minutes. + - To be clear, player locations are not real time. +- Automatic Minecraft world backups. + - Saved to a tar.gz file, must be manually exported from the container. -## Why not a precompiled version of spigot is included +### Generating the container for the first time. -Due to legal reasons you can build it yourself but you can't redistribute the finished jar file. +**This is important and you only need to do it once.** -## Starting the container +1) You need your own Google Maps API key. Click this link: https://developers.google.com/maps/documentation/javascript/get-api-key and follow the instructions. -To run the latest stable version of this docker image run +2) [Install docker](https://docs.docker.com/engine/installation/) - docker run -d -p 25565:25565 -e EULA=true nimmis/spigot +3) Clone this repo and then run: -the parameter - - -e EULA=true - -The is because Mojang now requires the end user to access their EULA, located at -https://account.mojang.com/documents/minecraft_eula, the be able to start the server. - -the parameter - - -p 25565:25565 - -tell on witch external port the internal 25565 should be connected, in this case the same, if -you only type -p 25565 it will connect to a random port on the machine + docker build -t docker_spigot_overviewer . + +4) Subsitute these values into the command below. + +- Add your key to: + + - `GOOGLE_MAPS_KEY=<--replace with your google maps key-->`, for example, `GOOGLE_MAPS_KEY=abcdefg-H1J2Lm4PQ-dscasdwqeqweb321321Jn`. + +- Specify how much memory the minecraft server can utilise + + - `MC_MAXMEM=<--megabytes-->m`, for example, `MC_MAXMEM=1500m` + + or + + - `MC_MAXMEM=<--gigabytes-->g`, for example, `MC_MAXMEM=4g` -## Giving the container a name +When ready, run: -To make it easier to handle you container you can give it a name instead of the long -number thats normally give to it, add a +`docker run -d -p 25565:25565 -p 80:80 -e EULA=true -e MC_MAXMEM=<--replace with megabytes-->m -e GOOGLE_MAPS_KEY=<--replace with your google maps key--> --name mcserver docker_spigot_overviewer` - --name spigot +Further information about the docker run command: -to the run command to give it the name minecraft, then you can start it easier with +|Argument|Description| +|---|---| +|`-p 25565:25565`|Required. Opens the port minecraft uses for gameplay| +|`-p 80:80`|Required. Opens the http port so you can access Overviewer| +|`-e GOOGLE_MAPS_KEY=<--replace with your google maps key-->`|Required. You must add your own API key (which you can obtain from the link above) other overviewer **will not work**. +|`-e EULA=true`|Required. By adding arguemnt this you're accepting the [Minecraft EULA](https://account.mojang.com/documents/minecraft_eula).| +|`-e MC_MAXMEM=<--megabytes-->m`|Sets the maximum memory to use m for Mb or g for Gb, if this parameter is not set 1 Gb is chosen. +|`--name mcserver`|Names this docker container 'mcserver' so it's easier to address later.| - docker start spigot - docker stop spigot +### First time run -## First time run +The first run will take a couple of minutes depending on computer and network speed. It pulls down the latest version of BuildTools and builds a spigot.jar from the selected minecraft version. This is done in numerous steps so please be patient. -This will take a couple of minutes depending on computer and network speed. It will pull down -the selected version on BuildTools and build a spigot.jar from the selected minecraft version. -This is done in numerous steps so be patient. +You can follow the output from the compilation with the command: -you can follow the output from the compilation with then command (assume that you given the container -the name spigot) + # docker logs -f mcserver - docker logs -f spigot *** open logfile *** Run files in /etc/my_runonce/ *** Running /etc/my_runonce/set_timezone... @@ -77,7 +77,7 @@ the name spigot) Connecting to hub.spigotmc.org (hub.spigotmc.org)|104.27.195.96|:443... connected. HTTP request sent, awaiting response... 200 OK -Then the compilation is completed the server will start and you will see something like +When the compilation is complete your minecraft server will start and you will see something like: *** Log: Success! Everything compiled successfully. Copying final .jar files now. *** Log: Copying craftbukkit-1.11-R0.1-SNAPSHOT.jar to /minecraft/build/. @@ -93,50 +93,25 @@ Then the compilation is completed the server will start and you will see somethi spigot RUNNING pid 4825, uptime 0:00:03 syslog-ng RUNNING pid 4823, uptime 0:00:03 +Exit the log by pressing CTRL-C. -you can then exit from the log with CTRL-C - -### Selecting version to compile - -If you don't specify it will always compile the latest version but if you want a specific version you can specify it by adding - - -e SPIGOT_VER - -where is the version you would like to use, to build it with version 1.8 add - - -e SPIGOT_VER 1.8 +## Starting & Stopping -to the docker run line. +After the inital run you can start and stop the entire container via: -#### versions available + docker start mcserver + docker stop mcserver -The following version is atm avaliable 1.8, 1.8.3, 1.8.7, 1.8.8, 1.9, 1.9.2 and latest. Please check -the web page for [BuildTools](https://www.spigotmc.org/wiki/buildtools/#versions) to get the latest information. -### setup memory to use +## Useful Commands -There are two environment variables to set maximum and initial memory for spigot. +### Logs +To get details of the latest events from the minecraft spigot server type -#### MC_MAXMEM + docker exec mcserver mc_log -Sets the maximum memory to use m for Mb or g for Gb, if this parameter is not set 1 Gb is chosen, to set the maximum memory to 2 Gb - - -e MC_MAXMEM=2g - -#### MC_MINMEM - -sets the initial memory reservation used, use m for Mb or g for Gb, if this parameter is not set, it is set to MC_MAXMEM, to set the initial size t0 512 Mb - - -e MC_MINMEM=512m - -## look at the last output from the spigot server - -To get an output of the latest events from the spigot server type - - docker exec spigot mc_log - -and you will see the last 10 lines from the output, this is what you will see after startup +and you will be shown the latest logs, which will continue to update. For example: Abort with CTRL-C [13:02:15 INFO]: Zombie Aggressive Towards Villager: true @@ -150,16 +125,34 @@ and you will see the last 10 lines from the output, this is what you will see af [13:02:18 INFO]: Server permissions file permissions.yml is empty, ignoring it [13:02:18 INFO]: Done (3.650s)! For help, type "help" or "?" -It will continue to output everything from the console until you press CTRL-C +Exit the log by pressing CTRL-C. + +To get details of the latest events from the overviewer processes type + + docker exec mcserver ov_log + +For example: + + Abort with CTRL-C + 20170109 22:05:01 INFO] STARTING ov_render + 20170109 22:05:01 INFO] Updating map POIs... + 2017-01-09 22:05:01 Looking for entities in + 2017-01-09 22:05:12 Done. + 2017-01-09 22:05:12 Loaded UUID cache from '/usr/share/nginx/html/uuidcache.dat' with 7 entries + 2017-01-09 22:05:12 Done handling POIs + 2017-01-09 22:05:12 Writing out javascript files + 2017-01-09 22:05:12 Wrote UUID cache with 7 entries + 2017-01-09 22:05:12 Done + 20170109 22:05:12 INFO] Map POI update complete! -## sending commands to the server console -You don't need to have an interactive container to be able to send commands to the console. To send -a command to set the time to day you type +### Sending commands to the Minecraft server console - docker exec spigot mc_send "time set day" +Use the mc_send command to send minecraft server console commands. For example: -If this was the first command issued after a start the output should look like + docker exec mcserver mc_send "time set day" + +And the output: [13:02:15 INFO]: Zombie Aggressive Towards Villager: true [13:02:15 INFO]: Experience Merge Radius: 3.0 @@ -173,84 +166,18 @@ If this was the first command issued after a start the output should look like [13:02:18 INFO]: Done (3.650s)! For help, type "help" or "?" [13:12:35 INFO]: Set the time to 1000 -It will continue to output everything from the console until you press CTRL-C - -## starting and stopping the server - -To stop the server but not the container do - - docker exec spigot mc_stop - -To start it after being stopped do - - docker exec spigot mc_start - -Finally to restart it do - - docker exec spiot mc_restart - -## stopping the container - -When the container is stopped with the command - - docker stop spigot - -the spigot server is shutdown nicely with a console stop command to give it time to save everything before -stopping the container. If you look in the output from the server this show - - [13:01:51 INFO]: Stopping the server - [13:01:51 INFO]: Stopping server - [13:01:51 INFO]: Saving players - [13:01:51 INFO]: nimmis lost connection: Server closed - [13:01:51 INFO]: nimmis left the game. - [13:01:51 INFO]: Saving worlds - [13:01:51 INFO]: Saving chunks for level 'world'/Overworld - [13:01:51 INFO]: Saving chunks for level 'world_nether'/Nether - [13:01:51 INFO]: Saving chunks for level 'world_the_end'/The End - -## Having the minecraft files on the host machine - -If you delete the container all your filer in minecraft will be gone. To save them where it's -easier to edit and do a backup of the files you can attach a directory from the host machine -(where you run the docker command) and attach it to the local file system in the container. -The syntax for it is - - -v /host/path/to/dir:/container/path/to/dir - -To attach the minecraft directory in the container to directory /home/nimmis/mc-srv you add - - -v /home/nimmis/mc-srv:/minecraft - -### problems with external mounted volumes - -When a external volume is mounted the UID of the owner of the volume may not match the UID of the minecraft user (1000). This can result in problems with write/read access to the files. - -To address this problem a check is done between UID of the owner of /minecraft and the UID of the user minecraft. If there is a mismatch the UID of the minecraft user is changed to match the UID of the directory. - -If you don't want to do this and want to manually set the UID of the minecraft user there is a variable named SPIGOT_UID which defines the minecraft user UID, adding - - -e SPIGOT_UID=1132 - -sets the minecraft user UID to 1132. - -## Issues +This will show you the server's response to your command. For a full list of commands check the official [wiki](http://minecraft.gamepedia.com/Commands#Summary_of_commands). Exit the log by pressing CTRL-C. -If you have any problems with or questions about this image, please contact us by submitting a ticket through a [GitHub issue](https://github.com/nimmis/docker-spigot/issues "GitHub issue") +## Starting and stopping the minecraft server -1. Look to see if someone already filled the bug, if not add a new one. -2. Add a good title and description with the following information. - - if possible an copy of the output from **cat /etc/BUILDS/*** from inside the container - - any logs relevant for the problem - - how the container was started (flags, environment variables, mounted volumes etc) - - any other information that can be helpful +To stop the minecraft server inside the container run -## Contributing + docker exec mcserver mc_stop -You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can. +To start it after being stopped: -## Future features + docker exec mcserver mc_start -- automatic backup -- plugins -- more.... +Finally to restart it: + docker exec mcserver mc_restart diff --git a/rootfs/etc/init.d/minecraft_server b/rootfs/etc/init.d/minecraft_server index f369482d..2dbec1ca 100755 --- a/rootfs/etc/init.d/minecraft_server +++ b/rootfs/etc/init.d/minecraft_server @@ -214,6 +214,14 @@ buildjar() { java -jar BuildTools.jar --rev $1 cp $SPIGOT_HOME/build/Spigot/Spigot-Server/target/spigot-*.jar $SPIGOT_HOME/spigot-$1.jar cd $SPIGOT_HOME/ + # grab the minecraft server version, download the minecraft client for overviewer + rm -Rf /overviewer/jar + mkdir -p /overviewer/jar + MC_VERSION=`ls -1 /$SPIGOT_HOME/build/work/minecraft_server.*.jar | cut -d'.' -f2- | sed 's/\(.*\)\..*/\1/'` + export MC_VERSION + wget https://s3.amazonaws.com/Minecraft.Download/versions/${MC_VERSION}/${MC_VERSION}.jar -P /overviewer/jar + ls -1t /overviewer/jar | grep -v latest | head -1 | xargs -I{} ln -s {} /overviewer/jar/minecraft_client.latest.jar + chmod -R 777 /overviewer rm -Rf $SPIGOT_HOME/build fi execCMD "rm -f $SPIGOT_HOME/spigot.jar" @@ -394,7 +402,7 @@ case "$1" in log) echo "Abort with CTRL-C" - tail -f $MC_DIR/output.con + tail -f -n 50 $MC_DIR/output.con ;; console) diff --git a/rootfs/etc/my_runalways/my_env b/rootfs/etc/my_runalways/my_env new file mode 100755 index 00000000..687b046d --- /dev/null +++ b/rootfs/etc/my_runalways/my_env @@ -0,0 +1,6 @@ +#!/bin/bash +# save all env variables (incl ones from docker) for crontab use + +printenv | grep -v " " | sed 's/^\(.*\)$/export \1/g' > /minecraft/my_env.sh +chmod 755 /minecraft/my_env.sh +chown minecraft:minecraft /minecraft/my_env.sh diff --git a/rootfs/etc/my_runalways/run_nginx b/rootfs/etc/my_runalways/run_nginx new file mode 100755 index 00000000..f4a7ae5d --- /dev/null +++ b/rootfs/etc/my_runalways/run_nginx @@ -0,0 +1,20 @@ +#!/bin/bash +# start nginx + +# Not the best way to handle permissions, but meh. +chown -R minecraft:minecraft /usr/share/nginx/html +chmod -R 755 /usr/share/nginx/html + + +if [ ! -f /run/nginx.pid ] ; then + + echo "nginx not running, starting." + nginx + +else + + echo "nginx pid file found, already running, stoping then starting." + nginx -s stop + nginx + +fi diff --git a/rootfs/etc/my_runonce/initial_ov_keyfix b/rootfs/etc/my_runonce/initial_ov_keyfix new file mode 100755 index 00000000..1149c0e4 --- /dev/null +++ b/rootfs/etc/my_runonce/initial_ov_keyfix @@ -0,0 +1,5 @@ +#!/bin/bash +# +# run ov_keyfix + +ov_keyfix diff --git a/rootfs/etc/my_runonce/mc_cron_add b/rootfs/etc/my_runonce/mc_cron_add new file mode 100755 index 00000000..e2b4c4c2 --- /dev/null +++ b/rootfs/etc/my_runonce/mc_cron_add @@ -0,0 +1,14 @@ +#!/bin/bash +# +# add mc_backup to crontab + +if [ "$(grep "minecraft mc_backup" < /etc/crontab)" ] ; then + + echo "mc_backup already in crontab" + +else + + echo "mc_backup not in crontab, adding." + echo "30 16 * * * minecraft mc_backup >> /tmp/crontab.log 2>&1" >> /etc/crontab + +fi diff --git a/rootfs/etc/my_runonce/ov_cron_add b/rootfs/etc/my_runonce/ov_cron_add new file mode 100755 index 00000000..1c3cd7f7 --- /dev/null +++ b/rootfs/etc/my_runonce/ov_cron_add @@ -0,0 +1,16 @@ +#!/bin/bash +# +# add overviewer to crontab + +if [ "$(grep "ov_render" < /etc/crontab)" ] ; then + + echo "overviewer already in crontab" + +else + + echo "ov_render not in crontab, adding." + echo "0,30 * * * * minecraft . /minecraft/my_env.sh; ov_render >> /tmp/crontab.log 2>&1" >> /etc/crontab + echo "5,15,25,35,45,55 * * * * minecraft . /minecraft/my_env.sh; ov_render -gp >> /tmp/crontab.log 2>&1" >> /etc/crontab + echo "0 2 * * * root . /minecraft/my_env.sh; ov_keyfix >> /tmp/crontab.log 2>&1" >> /etc/crontab + +fi diff --git a/rootfs/etc/nginx/sites-enabled/default b/rootfs/etc/nginx/sites-enabled/default new file mode 100644 index 00000000..5d8f3ac1 --- /dev/null +++ b/rootfs/etc/nginx/sites-enabled/default @@ -0,0 +1,112 @@ +# You may add here your +# server { +# ... +# } +# statements for each of your virtual hosts to this file + +## +# You should look at the following URL's in order to grasp a solid understanding +# of Nginx configuration files in order to fully unleash the power of Nginx. +# http://wiki.nginx.org/Pitfalls +# http://wiki.nginx.org/QuickStart +# http://wiki.nginx.org/Configuration +# +# Generally, you will want to move this file somewhere, and start with a clean +# file but keep this around for reference. Or just disable in sites-enabled. +# +# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. +## + +server { + listen 80 default_server; + listen [::]:80 default_server ipv6only=on; + + root /usr/share/nginx/html; + index index.html index.htm; + + # Make site accessible from http://localhost/ + server_name localhost; + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + # Uncomment to enable naxsi on this location + # include /etc/nginx/naxsi.rules + } + + # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests + #location /RequestDenied { + # proxy_pass http://127.0.0.1:8080; + #} + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + #error_page 500 502 503 504 /50x.html; + #location = /50x.html { + # root /usr/share/nginx/html; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # fastcgi_split_path_info ^(.+\.php)(/.+)$; + # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini + # + # # With php5-cgi alone: + # fastcgi_pass 127.0.0.1:9000; + # # With php5-fpm: + # fastcgi_pass unix:/var/run/php5-fpm.sock; + # fastcgi_index index.php; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} + + +# another virtual host using mix of IP-, name-, and port-based configuration +# +#server { +# listen 8000; +# listen somename:8080; +# server_name somename alias another.alias; +# root html; +# index index.html index.htm; +# +# location / { +# try_files $uri $uri/ =404; +# } +#} + + +# HTTPS server +# +#server { +# listen 443; +# server_name localhost; +# +# root html; +# index index.html index.htm; +# +# ssl on; +# ssl_certificate cert.pem; +# ssl_certificate_key cert.key; +# +# ssl_session_timeout 5m; +# +# ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; +# ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; +# ssl_prefer_server_ciphers on; +# +# location / { +# try_files $uri $uri/ =404; +# } +#} diff --git a/rootfs/overviewer/overviewer.cfg b/rootfs/overviewer/overviewer.cfg new file mode 100644 index 00000000..397ba6d0 --- /dev/null +++ b/rootfs/overviewer/overviewer.cfg @@ -0,0 +1,26 @@ +worlds["Main"] = "/minecraft/world" + +def playerIcons(poi): + if poi['id'] == 'Player': + poi['icon'] = "http://overviewer.org/avatar/%s/head" % poi['EntityId'] + return "Last known location for %s" % poi['EntityId'] + +def signFilter(poi): + if poi['id'] == 'Sign' or poi['id'] == 'minecraft:sign': + if poi['Text1'] == '!': + return "\n".join([poi['Text2'], poi['Text3'], poi['Text4']]) + +renders["survivaldaysouth"] = { + "world": "Main", + "title": "Overworld", + "rendermode": smooth_lighting, + "dimension": "overworld", + "defaultzoom":"4", + "minzoom":"2", + "northdirection" : "upper-right", + "markers": [dict(name="Players", filterFunction=playerIcons, checked=True), + dict(name="Signs", filterFunction=signFilter)], +} + +outputdir = "/usr/share/nginx/html" +texturepath = "/overviewer/jar/minecraft_client.latest.jar" diff --git a/rootfs/usr/local/bin/mc_backup b/rootfs/usr/local/bin/mc_backup new file mode 100755 index 00000000..4b244b73 --- /dev/null +++ b/rootfs/usr/local/bin/mc_backup @@ -0,0 +1,24 @@ +#!/bin/bash +########################################################### +# +# mc world backup script +# +########################################################### + +mc_send_once "say Shutting down in 5 minutes to backup the world." +mc_send_once "say Backup should only take a couple minutes." +sleep 240 +mc_send_once "say Shutting down in 1 minute to backup the world..." +mc_send_once "say Backup should only take a couple minutes." +sleep 60 +mc_send_once "say Shutting down NOW to backup the world." +mc_send_once "say Backup should only take a couple minutes." +mc_send_once "say brb, bye now!" +sleep 5 + +mc_stop + +mkdir -p /minecraft/backup +tar zcvf /minecraft/backup/worldbackup-"$(date +%Y-%m-%d-%H%M)".tar.gz /minecraft/world* + +mc_start diff --git a/rootfs/usr/local/bin/mc_send_once b/rootfs/usr/local/bin/mc_send_once new file mode 100755 index 00000000..0f1a5ad2 --- /dev/null +++ b/rootfs/usr/local/bin/mc_send_once @@ -0,0 +1,9 @@ +#!/bin/bash +########################################################### +# +# script to send command to spigot, without mc_log +# +########################################################### + +echo "/etc/init.d/minecraft_server send \"$1\"" +/etc/init.d/minecraft_server send "$1" diff --git a/rootfs/usr/local/bin/ov_genpoi b/rootfs/usr/local/bin/ov_genpoi new file mode 100755 index 00000000..a96fc37b --- /dev/null +++ b/rootfs/usr/local/bin/ov_genpoi @@ -0,0 +1,8 @@ +#!/bin/sh +########################################################### +# +# script to generate overviewer points of interest +# +########################################################### + +ov_render -gp diff --git a/rootfs/usr/local/bin/ov_keyfix b/rootfs/usr/local/bin/ov_keyfix new file mode 100755 index 00000000..ec75e8aa --- /dev/null +++ b/rootfs/usr/local/bin/ov_keyfix @@ -0,0 +1,56 @@ +#!/bin/bash +########################################################################## +# +# Script to add a google maps key to overviewer if there isn't one already +# +# Working around issue: +# https://github.com/overviewer/Minecraft-Overviewer/issues/1308 +# +# This script is run at startup and also once a day, just in case +# overviewer is updated and the source index.html needs re-patching. +# +# Overviewer copies the source index.html at the beginning of the render, +# and then takes its sweet time rendering tiles, meaning for at least 3 +# minutes (possibly lots more if someone has explored the map) the website +# is unusable. Patching the source index ensures it is copied and the map +# always works. +# +########################################################################## + +TestString="https://maps.google.com/maps/api/js?sensor=false" +AddString="&key=" + +if [ "root" != "$(whoami)" ] ; then + echo "This script must be run as root user." 1>&2 + exit 1 +fi + +printf "\n%s INFO] STARTING ov_keyfix\n" "$(date "+%Y%m%d %H:%M:%S")" + +if [ -z "$GOOGLE_MAPS_KEY" ] ; then + echo "Google maps key not found. Ensure environment variable GOOGLE_MAPS_KEY is set." + exit 1 +else + printf "Google maps key: %s\n" "$GOOGLE_MAPS_KEY" +fi + +for f in $(find /usr/ -name "index.html" -print | grep overviewer_core/data/web_assets) +do + if [ "$(grep "$TestString" "$f")" ] ; then + echo "$f is a file to check" + if [ -z "$(grep "$TestString$AddString" "$f")" ] ; then + echo "$f doesn't have a key." + if [ ! -h "$f" ] ; then + echo "$f is not a symlink, lets get you patched up." + printf "Before adding the key: %s\n" "$(grep "$TestString" "$f")" + sed -i "s/\?sensor=false/&\&key=$GOOGLE_MAPS_KEY/g" "$f" + printf "After adding the key: %s\n" "$(grep "$TestString" "$f")" + else + echo "$f is a symlink, skipping..." + fi + fi + fi + if [ "$(grep "$TestString$AddString" "$f")" ] ; then + printf "$f has a key, see here: %s\n" "$(grep "$TestString$AddString" "$f")" + fi +done diff --git a/rootfs/usr/local/bin/ov_log b/rootfs/usr/local/bin/ov_log new file mode 100755 index 00000000..ea877087 --- /dev/null +++ b/rootfs/usr/local/bin/ov_log @@ -0,0 +1,9 @@ +#!/bin/bash +########################################################### +# +# script to track overviewer log +# +######################################################### + +echo "Abort with CTRL-C" +tail -f -n 50 /overviewer/logs/overviewer.log diff --git a/rootfs/usr/local/bin/ov_render b/rootfs/usr/local/bin/ov_render new file mode 100755 index 00000000..75a2c222 --- /dev/null +++ b/rootfs/usr/local/bin/ov_render @@ -0,0 +1,74 @@ +#!/bin/sh +############################################################ +# +# script to render overviewer or generate points of interest +# +############################################################ + +Script="nice -n 19 /usr/bin/overviewer.py --config=/overviewer/overviewer.cfg" +Action="Render" +LogFile="/overviewer/logs/overviewer.log" +ArchiveDir="/overviewer/logs/archive" +MaxFileSizeInMb="2" + +if [ "minecraft" != "$(whoami)" ] ; then + echo "This script must be run as minecraft user." 1>&2 + exit 1 +fi + +while test $# -gt 0; do + case "$1" in + -gp) + Script="$Script --genpoi" + Action="GenPoi" + shift + ;; + *) + break + ;; + esac +done + +mkdir -p $ArchiveDir +touch $LogFile +printf "\n%s INFO] STARTING ov_render\n" "$(date "+%Y%m%d %H:%M:%S")" >> $LogFile + +if [ -z "$(pgrep overviewer.py)" ];then + + if [ $Action = "Render" ];then + printf "%s INFO] Updating Map blocks...\n" "$(date "+%Y%m%d %H:%M:%S")" >> $LogFile + printf "%s INFO] Google maps key: %s\n" "$(date "+%Y%m%d %H:%M:%S")" "$GOOGLE_MAPS_KEY" >> $LogFile + fi + + if [ $Action = "GenPoi" ];then + printf "%s INFO] Updating map POIs...\n" "$(date "+%Y%m%d %H:%M:%S")" >> $LogFile + fi + + $Script >> $LogFile + + if [ $Action = "Render" ];then + printf "%s INFO] Google Maps Key in index.hmtl: %s\n" "$(date "+%Y%m%d %H:%M:%S")" "$(grep sensor=false /usr/share/nginx/html/index.html)" >> $LogFile + fi + + FileSize=$(du -m $LogFile | tr -s '\t' ' ' | cut -d' ' -f1) + + if [ "$FileSize" -gt $MaxFileSizeInMb ];then + Timestamp=$(date "+%Y%m%d %H:%M:%S") + mv $LogFile $LogFile."$Timestamp" + mv $LogFile."$Timestamp" $ArchiveDir + touch $LogFile + fi + + if [ $Action = "Render" ];then + mc_send_once "say Map blocks updated!" + echo "$(date "+%Y%m%d %H:%M:%S") INFO] Map block update complete!" >> $LogFile + fi + + if [ $Action = "GenPoi" ];then + mc_send_once "say Map points of interest updated!" + echo "$(date "+%Y%m%d %H:%M:%S") INFO] Map POI update complete!" >> $LogFile + fi + +else + echo "$(date "+%Y%m%d %H:%M:%S") ERROR] overviewer.py already running. Not performing another scan." >> $LogFile +fi