Index: head/games/minecraft-server/Makefile =================================================================== --- head/games/minecraft-server/Makefile (revision 390647) +++ head/games/minecraft-server/Makefile (revision 390648) @@ -1,66 +1,67 @@ # $FreeBSD$ PORTNAME= minecraft-server PORTVERSION= 1.8.7 +PORTREVISION= 1 CATEGORIES= games java MASTER_SITES= https://s3.amazonaws.com/Minecraft.Download/versions/${PORTVERSION}/ DISTNAME= minecraft_server.${PORTVERSION}.jar EXTRACT_SUFX= EXTRACT_ONLY= MAINTAINER= freebsd@jonathanprice.org COMMENT= Dedicated server for the game Minecraft OPTIONS_SINGLE= RUN OPTIONS_SINGLE_RUN= DAEMON STANDALONE DAEMON_DESC= Run as a service STANDALONE_DESC= Run the .jar file directly OPTIONS_SUB= yes OPTIONS_DEFAULT= STANDALONE USERS= mcserver GROUPS= ${USERS} NO_BUILD= yes USE_JAVA= yes SUB_FILES= minecraft-server \ pkg-message \ pkg-deinstall SUB_LIST= VERSION=${PORTVERSION} PLIST_SUB= VERSION=${PORTVERSION} CONFIG_FILES= banned-ips.json \ banned-players.json \ eula.txt \ ops.json \ server.properties \ usercache.json \ whitelist.json .include .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} ${MKDIR} ${STAGEDIR}${ETCDIR} ${MKDIR} ${STAGEDIR}/var/db/minecraft-server ${MKDIR} ${STAGEDIR}/var/log/minecraft-server .if ${PORT_OPTIONS:MSTANDALONE} ${INSTALL_SCRIPT} ${WRKDIR}/minecraft-server ${STAGEDIR}${PREFIX}/bin ${CP} ${FILESDIR}/java-args.txt ${STAGEDIR}${ETCDIR} .endif .for file in ${CONFIG_FILES} ${LN} -s ${ETCDIR}/${file} ${STAGEDIR}${PREFIX}/${PORTNAME}/${file} .endfor ${LN} -sf /var/log/minecraft-server ${STAGEDIR}${PREFIX}/${PORTNAME}/logs ${LN} -sf /var/log/minecraft-server/debug ${STAGEDIR}${PREFIX}/${PORTNAME}/debug ${LN} -sf /var/db/minecraft-server ${STAGEDIR}${PREFIX}/${PORTNAME}/world .include Index: head/games/minecraft-server/files/minecraft.in =================================================================== --- head/games/minecraft-server/files/minecraft.in (revision 390647) +++ head/games/minecraft-server/files/minecraft.in (revision 390648) @@ -1,91 +1,100 @@ #!/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" +extra_commands="console status kill" start_cmd="${name}_start" stop_cmd="${name}_stop" console_cmd="${name}_console" status_cmd="${name}_status" +kill_cmd="${name}_kill" -minecraft_start() +is_running() { pgrep -qu mcserver java - isrunning=$? - if [ ${isrunning} -eq 0 ]; then - echo "${name} already running." + return $? +} + +minecraft_start() +{ + if is_running; then + echo "${name} is 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.%%VERSION%%.jar nogui'" fi } minecraft_stop() { - pgrep -qu mcserver java - isrunning=$? - if [ ${isrunning} -eq 0 ]; then + if is_running; 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 + if is_running; then sleep 1 else - echo "${name} stopped." + echo "${name} has been stopped." return fi done - echo "ERROR: ${name} could not be stopped." + echo "WARN: ${name} could not be stopped or is taking longer than expected." + echo "WARN: To view the console, type 'service ${name} console'" + echo "WARN: To kill $[name}, type 'service ${name} kill'" else - echo "${name} not running." + echo "${name} is not running." fi } minecraft_console() { - pgrep -qu mcserver java - isrunning=$? - if [ ${isrunning} -ne 0 ]; then - echo "${name} not running." + if ! is_running; then + echo "${name} is 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 + if is_running; then echo "${name} is running." else echo "${name} is not running." + fi +} + +minecraft_kill() +{ + if ! is_running; then + echo "${name} is not running." + else + pkill -KILL -u mcserver java + echo "${name} has been killed." fi } run_rc_command "$1"