我正在尝试将 Serviio 转变为 Debian 上的服务,使其能够在引导时启动并通过服务命令行实用程序进行控制。
我有一个专门的用户 serviio 来运行守护程序。我暂时为该用户提供了一个 shell 并登录以该用户身份启动守护程序并确认其正常工作,因此这不是与此相关的问题。
这是我正在使用的脚本,位于 /etc/init.d/serviio 中。该脚本来自 serviio 论坛,多年来每个人都报告使用它取得了成功,直到最近这个月。
#!/bin/bash
#
#########################################################
#- Daemon script for Serviio media server
#- By Ian Laird; converted for Debian by Jacob Lundbergand edited by Jopie
#- /etc/init.d/serviio
#########################################################
#
### BEGIN INIT INFO
# Provides: serviio
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Start/stop serviio media server
# Description: The Serviio media server makes your media available to
# all kinds of networked devices.
### END INIT INFO
. /lib/lsb/init-functions
if [ -f /etc/default/serviio ]; then
. /etc/default/serviio
fi
DAEMON_STOP=" -stop"
NAME="$(basename $0)"
PIDFILE="/tmp/serviiod.pid"
TIMEOUT=10
if [ -f /etc/default/serviio ]; then
. /etc/default/serviio
fi
[ -x "$DAEMON" ] || exit 0
running() {
if [ "x$1" == "x" ]; then
echo 0
return 1
fi
PS=$(ps h -p $(echo $1 | sed -r 's/[\t \n]+/ -p /') | wc -l)
echo $PS
if [ $PS -gt 0 ]; then
return 0
else
return 1
fi
}
start() {
log_daemon_msg "Starting Serviio media server daemon" "$NAME"
start-stop-daemon --start -q -b -p "$PIDFILE" -m -c "${SERVICE_ACCOUNT}" -x "${DAEMON}" start
log_end_msg $?
}
stop() {
log_daemon_msg "Stopping Serviio media server daemon" "$NAME"
if [ -r "$PIDFILE" ]; then
PIDS=$(pstree -p $(<"$PIDFILE") | awk -F'[\(\)]' '/^[A-Za-z0-9]/ { print $2" "$4; }')
if running "$PIDS" > /dev/null; then
"${DAEMON}" "${DAEMON_STOP}"
for PID in $PIDS; do
if running $PID > /dev/null; then
kill -TERM $PID
fi
done
fi
COUNTDOWN=$TIMEOUT
while let COUNTDOWN--; do
if ! running "$PIDS" > /dev/null; then
break
fi
if [ $COUNTDOWN -eq 0 ]; then
for PID in $PIDS; do
if running $PID > /dev/null; then
kill -KILL $PID
fi
done
else
echo -n .
sleep 1
fi
done
fi
if running "$PIDS" > /dev/null; then
log_end_msg 1
else
rm -f "$PIDFILE"
log_end_msg $?
fi
}
status() {
echo -n "$NAME should be"
if [ -r "$PIDFILE" ]; then
echo -n " up with primary PID $(<"$PIDFILE")"
PIDS=$(pstree -p $(<"$PIDFILE") | awk -F'[\(\)]' '/^[A-Za-z0-9]/ { print $2" "$4; }')
RUNNING=$(running "$PIDS")
if [[ $RUNNING && $RUNNING -gt 0 ]]; then
echo -n " and $RUNNING processes are running."
else
echo -n " but it is not running."
fi
else
echo -n " stopped."
fi
echo
}
case "${1:-}" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
log_success_msg "Usage: /etc/init.d/$NAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
我也在 /etc/default/serviio 中
NAME="Serviio Media Server"
DAEMON="/opt/Serviio/bin/serviio.sh" ## Update this to point at serviio_root/bin/serviio.sh
SERVICE_ACCOUNT="serviio" ## DON'T RUN UNDER ROOT!
我使用适当的服务命令将服务添加到系统中。
但是,每当我尝试启动该服务时...systemd 都会将其报告为已成功启动,但守护进程实际上并未运行。没有报告错误消息。
从 /etc/init.d/serviio start 手动运行脚本也不起作用。
我该如何排查并解决这个问题?