Skip to content

Instantly share code, notes, and snippets.

@sko00o sko00o/Makefile
Last active Jul 11, 2019

Embed
What would you like to do?
Makefile for manage Minecraft server
BASEPATH=$(PWD)
EXEC=server.jar # forge-1.14.3-27.0.12.jar # you can change to forge
BACKUPNAME="world-$(shell date '+%F-%H%M').tar.gz"
BAKPATH=$(BASEPATH)/backup-worlds
MAKEFLAGS += --silent
all: help
## require: install required programs
.PHONY: require
require: path-require
sudo apt-get -y install screen
sudo apt-get -y install openjdk-8-jre
.PHONY: path-require
path-require:
mkdir -p $(BAKPATH)
## start: start minecraft server in screen session
.PHONY: start
start:
screen -dm -S minecraft \
java -Xms1024M -Xmx2048M -jar $(BASEPATH)/$(EXEC) nogui
@echo 'press Ctrl+A,D to quit screen'
sleep 1
screen -d -r minecraft
## console: control mc server in console
.PHONY: console
console:
screen -d -r minecraft
## stop: stop mc server in screen session
.PHONY: stop
stop:
screen -X -S minecraft quit
## backup: tar world dir for backup
.PHONY: backup
backup:
@tar czvf $(BACKUPNAME) world
@mv $(BACKUPNAME) $(BAKPATH)/.
## help: show this menu
.PHONY: help
help: Makefile
@echo
@echo " Choose a command run: "
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.