Tutorials/FreeBSD startup script

This is an example of a possible Minecraft server rc.d startup script for FreeBSD.

Installation
minecraft_enable="yes"
 * Use adduser to create a new user named minecraft. When asked to select the new user's home directory, use /srv/minecraft.
 * Ensure that your /srv filesystem has enough free space (around ~100-200MB depending on your needs) - df -h will show how much space is available.
 * Install Java if necessary. The port is available at /usr/ports/java/openjdk8.
 * As root, run the following:
 * 1) cd /usr/ports/sysutils/screen && make install clean
 * 2) cd /srv/minecraft
 * 3) fetch https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar
 * 4) chown minecraft:minecraft *
 * 5) fetch -o /usr/local/etc/rc.d/minecraft http://vidya.dyndns.org/stuff/minecraft
 * 6) chmod 0555 /usr/local/etc/rc.d/minecraft
 * If you have existing server configuration files, world files, etc., copy them into /srv/minecraft and give ownership to your minecraft user.
 * Edit /etc/rc.conf.local (create if it doesn't exist) and add the following line:
 * The server should now start on boot. To launch, check status, and shut down, use the following commands:
 * 1) /usr/local/etc/rc.d/minecraft start
 * 2) /usr/local/etc/rc.d/minecraft status
 * 3) /usr/local/etc/rc.d/minecraft stop

Or:


 * 1) service minecraft start
 * 2) service minecraft status
 * 3) service minecraft stop

Script

 * 1) !/bin/sh
 * 2) PROVIDE: minecraft
 * 3) REQUIRE: LOGIN DAEMON NETWORKING mountcritlocal
 * 4) KEYWORD: shutdown
 * 5) Add the following lines to /etc/rc.conf.local to enable the minecraft server:
 * 6) minecraft_enable="YES"
 * 7) minecraft_user=" "
 * 8) minecraft_chdir=""
 * 9) minecraft_path=""
 * 10) minecraft_flags=" "
 * 11) For default setup, create a user named 'minecraft', set its home directory
 * 12) to /srv/minecraft, and place minecraft_server.jar into /srv/minecraft
 * 13) See minecraft_server.jar for flags
 * 1) For default setup, create a user named 'minecraft', set its home directory
 * 2) to /srv/minecraft, and place minecraft_server.jar into /srv/minecraft
 * 3) See minecraft_server.jar for flags
 * 1) See minecraft_server.jar for flags
 * 1) See minecraft_server.jar for flags

. /etc/rc.subr

name=minecraft rcvar=minecraft_enable

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_enable="NO"}
 * ${minecraft_session="minecraft-session"}
 * ${minecraft_user="minecraft"}
 * ${minecraft_chdir="/srv/minecraft"}
 * ${minecraft_path="/srv/minecraft/minecraft_server.jar"}
 * ${minecraft_flags="--nogui"}
 * ${minecraft_args="/usr/local/bin/java -Xmx1024M -Xms1024M \

-XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing \ -XX:ParallelGCThreads=4 -XX:+AggressiveOpts \ -jar ${minecraft_path} ${minecraft_flags}"}

minecraft_start { unset "${rc_arg}_cmd" minecraft_flags="-d -m -S ${minecraft_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_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." else echo "minecraft is not running." fi }

minecraft_running { local check ses ses="${minecraft_session}" check=`su -m ${minecraft_user} -c "${command} -list" | grep ${ses}` if [ "$check" ]; then return 0 else return 1 fi }

run_rc_command "$1"

教程/FreeBSD启动脚本