![当 LSB 启动脚本停止时在屏幕上运行命令](https://linux22.com/image/677831/%E5%BD%93%20LSB%20%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC%E5%81%9C%E6%AD%A2%E6%97%B6%E5%9C%A8%E5%B1%8F%E5%B9%95%E4%B8%8A%E8%BF%90%E8%A1%8C%E5%91%BD%E4%BB%A4.png)
我正在尝试让 Bukkit 服务器作为服务在屏幕内运行,从 LSB 脚本启动,但我无法让它正确停止。我本质上想让它做的是重新连接屏幕并向服务器控制台发送“停止”命令,以便它保存所有内容而不是直接被杀死,但“sudo service bukkit stop”似乎对我的脚本没有任何作用。
如果我将屏幕重新连接到终端并在 Bukkit 控制台中输入“停止”,它似乎仍会停止。
有人知道问题是什么吗?我的 init.d 脚本如下...
#!/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
答案1
最终设法让它与屏幕一起工作。我忘记在“停止”命令后发送回车,还发现我必须使用“东西”向屏幕发送命令:P
以下是工作代码:
#!/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
感谢@chicks 对 tmux 的提醒,我正在调查此事以防出现更多问题……