games/minecraft-server: Add support for running as a service
PR: 197387 Submitted by: maintainer (Jonathan Price)
This commit is contained in:
@@ -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}
|
||||
|
||||
91
games/minecraft-server/files/minecraft.in
Normal file
91
games/minecraft-server/files/minecraft.in
Normal file
@@ -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"
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user