diff options
author | John Marino <marino@FreeBSD.org> | 2015-03-01 22:21:09 +0000 |
---|---|---|
committer | John Marino <marino@FreeBSD.org> | 2015-03-01 22:21:09 +0000 |
commit | dc11cd281fd8aa87da7ba6ac1e32e566da956897 (patch) | |
tree | ffa8b6661ad7fa820510fcc8b5b4b4c2fc5f22af /games/minecraft-server | |
parent | fdf8800df4e81b1d6b77a1fc3e4a7329efaf167f (diff) | |
download | freebsd-ports-dc11cd281fd8aa87da7ba6ac1e32e566da956897.zip |
games/minecraft-server: Add support for running as a service
PR: 197387
Submitted by: maintainer (Jonathan Price)
Diffstat (limited to 'games/minecraft-server')
-rw-r--r-- | games/minecraft-server/Makefile | 12 | ||||
-rw-r--r-- | games/minecraft-server/files/minecraft.in | 91 | ||||
-rw-r--r-- | games/minecraft-server/files/pkg-message.in | 14 |
3 files changed, 113 insertions, 4 deletions
diff --git a/games/minecraft-server/Makefile b/games/minecraft-server/Makefile index 189e9f72fefc..62629264db24 100644 --- a/games/minecraft-server/Makefile +++ b/games/minecraft-server/Makefile @@ -2,6 +2,7 @@ PORTNAME= minecraft-server PORTVERSION= 1.8.1 +PORTREVISION= 1 CATEGORIES= games java MASTER_SITES= https://s3.amazonaws.com/Minecraft.Download/versions/${PORTVERSION}/ DISTNAME= minecraft_server.${PORTVERSION}.jar @@ -11,6 +12,10 @@ EXTRACT_ONLY= MAINTAINER= freebsd@jonathanprice.org COMMENT= Dedicated server for the game Minecraft +OPTIONS_DEFINE= DAEMON +DAEMON_DESC= Allows controlling via rc.d +OPTIONS_SUB= yes + USERS= mcserver GROUPS= ${USERS} @@ -27,6 +32,13 @@ CONFIG_FILES= banned-ips.json \ usercache.json \ whitelist.json +.include <bsd.port.options.mk> + +.if ${PORT_OPTIONS:MDAEMON} +USE_RC_SUBR+= minecraft +RUN_DEPENDS+= tmux:${PORTSDIR}/sysutils/tmux +.endif + do-install: ${MKDIR} ${STAGEDIR}${PREFIX}/${PORTNAME} ${INSTALL_DATA} ${DISTDIR}/${DISTNAME} ${STAGEDIR}${PREFIX}/${PORTNAME} diff --git a/games/minecraft-server/files/minecraft.in b/games/minecraft-server/files/minecraft.in new file mode 100644 index 000000000000..415f32339fd1 --- /dev/null +++ b/games/minecraft-server/files/minecraft.in @@ -0,0 +1,91 @@ +#!/bin/sh +# +# $FreeBSD$ +# PROVIDE: minecraft +# REQUIRE: LOGIN +# KEYWORD: shutdown +# +# rc.conf variables: +# minecraft_enable (Default: NO) +# minecraft_mem (Default: 1024M) +# minecraft_args (Default: "") +. /etc/rc.subr + +name=minecraft +rcvar=minecraft_enable +desc="Dedicated server for the game Minecraft" + +load_rc_config $name + +minecraft_mem=${minecraft_mem:-"1024M"} +minecraft_args=${minecraft_args:-""} + +extra_commands="console status" +start_cmd="${name}_start" +stop_cmd="${name}_stop" +console_cmd="${name}_console" +status_cmd="${name}_status" + +minecraft_start() +{ + pgrep -qu mcserver java + isrunning=$? + if [ ${isrunning} -eq 0 ]; then + echo "${name} already running." + else + echo "Starting ${name}." + cd %%PREFIX%%/minecraft-server + su mcserver -c "%%LOCALBASE%%/bin/tmux new-session -s minecraft -d '%%LOCALBASE%%/bin/java -Xmx${minecraft_mem} -Xms${minecraft_mem} ${minecraft_args} -jar %%PREFIX%%/minecraft-server/minecraft_server.1.8.1.jar nogui'" + fi +} + +minecraft_stop() +{ + pgrep -qu mcserver java + isrunning=$? + if [ ${isrunning} -eq 0 ]; then + echo "Stopping ${name}." + su mcserver -c "%%LOCALBASE%%/bin/tmux send-keys -t ${name} \"stop\" ENTER" + + i=0 + while [ $i -lt 10 ]; do + i=$(($i + 1)) + pgrep -qu mcserver java + stillrunning=$? + if [ ${stillrunning} -eq 0 ]; then + sleep 1 + else + echo "${name} stopped." + return + fi + done + echo "ERROR: ${name} could not be stopped." + else + echo "${name} not running." + fi +} + +minecraft_console() +{ + pgrep -qu mcserver java + isrunning=$? + if [ ${isrunning} -ne 0 ]; then + echo "${name} not running." + else + export TERM=xterm + su mcserver -c "%%LOCALBASE%%/bin/tmux attach-session -t ${name}" + fi +} + +minecraft_status() +{ + pgrep -qu mcserver java + isrunning=$? + if [ ${isrunning} -eq 0 ]; then + echo "${name} is running." + else + echo "${name} is not running." + fi +} + +run_rc_command "$1" diff --git a/games/minecraft-server/files/pkg-message.in b/games/minecraft-server/files/pkg-message.in index 379a70b1731f..fd86fa0a9925 100644 --- a/games/minecraft-server/files/pkg-message.in +++ b/games/minecraft-server/files/pkg-message.in @@ -1,16 +1,22 @@ When you first run minecraft-server, it will populate the file %%ETCDIR%%/eula.txt -It is required to read the EULA, and then set: -eula=true +It is required to read the EULA, and then set eula=true -- To run the server, run %%PREFIX%%/bin/minecraft-server - Configuration files can be found at %%ETCDIR%% - Log and debug output files can be found at /var/log/minecraft-server/ - World files can be found at /var/db/minecraft-server + +Without daemon option: +- To run the server, run %%PREFIX%%/bin/minecraft-server - To edit java's parameters, edit %%ETCDIR%%/java-args.txt -NOTE: +With daemon option: +- The service has been installed with the name 'minecraft' +- To adjust memory usage, use MINECRAFT_MEM= in /etc/rc.conf +- To add other java parameters, use MINECRAFT_ARGS= in /etc/rc.conf +- To see the interactive console, type service minecraft console + Users upgrading from version < 1.8 are advised to run the server to generate new config files, and then modify them based on their existing configuration, as most files are now JSON instead of txt. |