#!/bin/sh
#
# PROVIDE: minecraft
# REQUIRE: LOGIN DAEMON NETWORKING mountcritlocal
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local to enable the minecraft server:
#
# minecraft_enable="YES"
#
# For default setup, create a user named 'minecraft', set its home directory
# to /srv/minecraft, and place minecraft_server.jar into /srv/minecraft
#
# See minecraft_server.jar for flags
. /etc/rc.subr
name=minecraft
rcvar=`set_rcvar`
load_rc_config ${name}
command=/usr/local/bin/screen
pidfile=/var/run/minecraft.pid
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
: ${minecraft_screen_session="minecraft-session"}
: ${minecraft_user="minecraft"}
: ${minecraft_flags=""}
: ${minecraft_args="/home/minecraft/start"}
minecraft_start() {
unset "${rc_arg}_cmd"
minecraft_flags="-d -m -S ${minecraft_screen_session} ${minecraft_args}"
if minecraft_running; then
echo "minecraft already running?"
else
run_rc_command "start"
fi
}
minecraft_stop() {
local cmd
cmd="${command} -p 0 -S ${minecraft_screen_session} -X eval 'stuff stop\015'"
if minecraft_running; then
echo "Stopping minecraft."
su -m ${minecraft_user} -c "${cmd}"
fi
}
minecraft_status() {
if minecraft_running; then
echo "minecraft is running."
return 0
else
echo "minecraft is not running."
return 1
fi
}
minecraft_running() {
local check ses
ses="${minecraft_screen_session}"
check=`su -m ${minecraft_user} -c "${command} -list" | grep ${ses}`
if [ "$check" ]; then
return 0
else
return 1
fi
}
run_rc_command "$1"