1

I'm trying to get a Bukkit server to run inside a screen as a service, started from an LSB script but I cant get it to stop correctly. What I essentially want it to do is reattach the screen and send a 'stop' command to the server console so it saves everything instead of just being killed, but 'sudo service bukkit stop' doesn't seem to do anything with my script.

It still seems to stop if I reattach the screen in a terminal and type 'stop' to the Bukkit console.

Anyone know what the problem is? My init.d script is below...

#!/bin/bash
### BEGIN INIT INFO
# Provides:          scriptname
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

cd /etc/minecraftbukkit
case $1 in
 start)
  # Checked the PID file exists and check the actual status of process
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
   # If the status is SUCCESS then don't need to start again.
   if [ $status = "0" ]; then
    exit # Exit
   fi
  fi
  # Start the daemon.
  screen -d -A -m -S "Bukkit152" sh ./bukkitrunner.sh
  ;;
 stop)
  # Stop the daemon.
  screen -d -r "Bukkit152"
  sleep 2
  stop
  ;;
 *)

esac
bhygate
  • 11
  • 2
  • Once you launch `screen` the shell loses control so your `stop` doesn't get sent to screen. You could try redirection, but screen is a pain to automate. `tmux` might be easier. – chicks Feb 29 '16 at 19:10

1 Answers1

0

Managed to get it working with screen eventually. I was forgetting to send a return carraige after the "stop" command, also found out i had to use "stuff" to send commands to screen :P

Heres the working code:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          scriptname
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

cd /etc/minecraftbukkit
case $1 in
 start)
  # Checked the PID file exists and check the actual status of process
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
   # If the status is SUCCESS then don't need to start again.
   if [ $status = "0" ]; then
    exit # Exit
   fi
  fi
  # Start the daemon.
  screen -d -A -m -S "Bukkit152" sh ./bukkitrunner.sh
  ;;
 stop)
  # Stop the daemon.
  screen -S "Bukkit152" -p 0 -X stuff "stop$(printf \\r)"
  sleep 2
  ;;
 *)

esac

Thanks to @chicks for the heads-up about tmux, i'm looking into it in case there are any more problems...

bhygate
  • 11
  • 2