6 _daemonName
="Minecraft server"
7 _logDir
="/var/log/minecraft-server"
8 _runDir
="/var/run/minecraft-server"
9 _srvDir
="/srv/minecraft"
10 _expectScript
=$
(cat << EOS
13 expect "Saving chunks" {return 0}
17 spawn attachtty "$_runDir/socket"
32 stat_busy
"Starting $_daemonName"
33 if [[ ! -f "$_runDir/server.pid" ]]; then
35 if [[ ! -d "$_runDir" ]]; then
36 install -m755 -d "$_runDir"
37 chown minecraft
:minecraft
"$_runDir"
39 su minecraft
-c "source /etc/profile &&
40 detachtty --dribble-file '$_logDir/server_stdout.log' \
41 --log-file '$_logDir/detachtty.log' \
42 --pid-file '$_runDir/server.pid' \
43 '$_runDir/socket' '/usr/bin/minecraft-server' nogui" &&
44 chmod 770 "$_runDir/socket" &&
45 chmod 644 "$_runDir/server.pid" &&
46 chown minecraft
:log
"$_logDir/server_stdout.log" &&
47 chown minecraft
:log
"$_logDir/detachtty.log" &&
48 chmod 640 "$_logDir/server_stdout.log" &&
49 chmod 640 "$_logDir/detachtty.log" &&
50 add_daemon minecraft-server
&&
51 stat_done || stat_fail
57 stat_busy
"Stopping $_daemonName"
58 if [[ ! -f "$_runDir/server.pid" ]]; then
60 rm_daemon minecraft-server
63 if [[ -S "$_runDir/socket" ]]; then
64 echo "$_expectScript" | expect
- &> /dev
/null
&&
66 rm_daemon minecraft-server
&&
72 rm_daemon minecraft-server
83 stat_busy
"Checking $_daemonName status"
84 ck_status minecraft-server
87 echo "usage: $0 {start|stop|restart|status}"