Skip to content

Instantly share code, notes, and snippets.

@troeger
Last active January 2, 2023 22:21
Embed
What would you like to do?
Running a Minecraft server as daemon on Amazon Linux
#!/bin/bash
#
# chkconfig: 2345 95 05
#
### BEGIN INIT INFO
# Provides: minecraft-server
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Should-Start: $syslog
# Should-Stop: $syslog
# Short-Description: start and stop minecraft server
# Description: Minecraft Server
### END INIT INFO
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
prog=minecraft-server
realprog=startup.sh
workingdir=/usr/local/minecraft-server
lockfile=/var/lock/subsys/$prog
start() {
[ "$EUID" != "0" ] && exit 4
[ "$NETWORKING" = "no" ] && exit 1
# Start daemon.
echo -n $"Starting $prog: "
cd $workingdir
daemon $workingdir/$realprog -u minecraft-server:daemon -p /var/run/minecraft-server.pid $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
return $RETVAL
}
stop() {
[ "$EUID" != "0" ] && exit 4
echo -n $"Shutting down $prog: "
killproc $realprog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
;;
restart|force-reload)
stop
start
;;
try-restart|condrestart)
if status $prog > /dev/null; then
stop
start
fi
;;
reload)
exit 3
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
exit 2
esac
#!/bin/sh
/usr/bin/java -jar /usr/local/minecraft-server/server.jar
@troeger
Copy link
Author

troeger commented Jan 24, 2017

Installation guide:

  • Become root.
  • Put minecraft-server into /etc/init.d.
  • Create a directory /usr/local/minecraft-server/.
  • Put startup.sh into /usr/local/minecraft-server/.
  • Create the daemon user: useradd --home-dir /usr/local/minecraft-server --no-create-home -g daemon --shell /bin/false minecraft-server
  • Download the Minecraft server JAR to /usr/local/minecraft-server/. The kids often demand specific versions for their hacks / mods / skins, https://mcversions.net is your friend.
  • Run startup.sh manually once, so that the server application creates all config files in their default version. Edit eula.txt as you've been told.
  • Add your kid to /usr/local/minecraft-server/ops.json (see here) for playing god. http://minecraft-techworld.com/uuid-lookup-tool is your friend.
  • Perform chkconfig --add minecraft-server once.
  • Make sure that port 25565 is reachable from the outside world (firewall / port forwarding).
  • Reboot. Test. Enjoy your free weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment