我安装了一个名为“plexconnect”的 Python 脚本,它基本上是一个用来欺骗我的 Apple TV3 在其他地方寻找预告片的脚本。来源:https://github.com/iBaa/PlexConnect
然后我制作了一个初始化脚本。来源:https://forums.plex.tv/discussion/156534/install-on-ubuntu-server
我在使用该守护进程时遇到的(小)问题是,重新启动后,该服务始终以活动状态(退出)启动:
● plexconnect.service - LSB: This is the Plex Connect daemon
Loaded: loaded (/etc/init.d/plexconnect; bad; vendor preset: enabled)
Active: active (exited) since sø. 2016-03-27 14:29:27 CEST; 1min 14s ago
Docs: man:systemd-sysv-generator(8)
Process: 1043 ExecStart=/etc/init.d/plexconnect start (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 512)
mars 27 14:29:26 lenox2 systemd[1]: Starting LSB: This is the Plex Connect daemon...
mars 27 14:29:27 lenox2 plexconnect[1043]: * Starting the process PlexConnect
mars 27 14:29:27 lenox2 systemd[1]: Started LSB: This is the Plex Connect daemon.
我重新启动服务后,它可以正常工作(正在运行):
● plexconnect.service - LSB: This is the Plex Connect daemon
Loaded: loaded (/etc/init.d/plexconnect; bad; vendor preset: enabled)
Active: active (running) since sø. 2016-03-27 14:31:09 CEST; 1s ago
Docs: man:systemd-sysv-generator(8)
Process: 1911 ExecStop=/etc/init.d/plexconnect stop (code=exited, status=0/SUCCESS)
Process: 1921 ExecStart=/etc/init.d/plexconnect start (code=exited, status=0/SUCCESS)
Tasks: 6 (limit: 512)
CGroup: /system.slice/plexconnect.service
├─1930 /usr/bin/SCREEN -S PlexConnect -d -m /usr/local/lib/PlexConnect/PlexConnect.py
├─1933 python /usr/local/lib/PlexConnect/PlexConnect.py
├─1936 python /usr/local/lib/PlexConnect/PlexConnect.py
├─1940 python /usr/local/lib/PlexConnect/PlexConnect.py
├─1942 python /usr/local/lib/PlexConnect/PlexConnect.py
└─1944 python /usr/local/lib/PlexConnect/PlexConnect.py
mars 27 14:31:09 lenox2 systemd[1]: Starting LSB: This is the Plex Connect daemon...
mars 27 14:31:09 lenox2 plexconnect[1921]: * Starting the process PlexConnect
mars 27 14:31:09 lenox2 systemd[1]: Started LSB: This is the Plex Connect daemon.
我尝试停止 plexmediaserver 并重新启动 plexconnect 以查看是否存在依赖关系问题,但它在没有 plexmediaserver 的情况下运行良好。我还尝试将 plexmediaserver 作为必需启动添加到 init 脚本:
#Required-Start: networking plexmediaserver
然后:
sudo update-rc.d plexconnect defaults
insserv: Service plexmediaserver has to be enabled to start service plexconnect
insserv: exiting now!
很明显,我在这里陷入了困境,需要帮助。我现在唯一的线索是重启后底部服务状态中的额外 python 行。可能是因为 python 需要成为必需启动?
初始化脚本的完整代码:
#!/bin/bash
### BEGIN INIT INFO
# Provides: plexconnect
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: This is the Plex Connect daemon
# Description: This script starts the Plex Connect
# Python scripts in a detached screen.
### END INIT INFO
# Using the lsb functions to perform the operations.
./lib/lsb/init-functions
# Process name ( For display )
NAME=PlexConnect
# Daemon name, where is the actual executable
DAEMON="/usr/bin/screen"
DAEMON_OPTS="-S PlexConnect -d -m /usr/local/lib/PlexConnect/PlexConnect.py"
DAEMON_USER="root"
# pid file for the daemon
PIDFILE=/var/run/PlexConnect.pid
# If the daemon is not there, then exit.
test -x "$DAEMON"||exit5
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 $DAEMON_OPTS""$NAME process"&& status="0"|| status="$?"
# If the status is SUCCESS then don't need to start again.
if[ $?="0"];then
log_success_msg "Starting the process $NAME"
exit# Exit
fi
fi
# Start the daemon.
# Start the daemon with the help of start-stop-daemon
# Log the message appropriately
if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -p $PIDFILE -- ${DAEMON_OPTS};then
while read line ;do[[ $line =~([0-9]*).PlexConnect]]&& echo ${BASH_REMATCH[1]};done<<(screen -ls)> $PIDFILE
log_success_msg "Starting the process $NAME"
else
log_failure_msg "Starting the process $NAME"
fi
;;
stop)
# Stop the daemon.
if[-e $PIDFILE ];then
status_of_proc -p $PIDFILE "$DAEMON DAEMON_OPTS""Stoppping the $NAME process"&& status="0"|| status="$?"
if["$?"=0];then
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
/bin/rm -rf $PIDFILE
log_success_msg ""Stopping the $NAME process""
fi
else
log_failure_msg "$NAME process is not running"
fi
;;
restart)
# Restart the daemon.
$0 stop && sleep 2&& $0 start
;;
status)
# Check the status of the process.
if[-e $PIDFILE ];then
status_of_proc -p $PIDFILE "$DAEMON $DAEMON_OPTS""$NAME process"&&exit0||exit $?
log_success_msg "$NAME process is running"
else
log_failure_msg "$NAME process is not running"
fi
;;
reload)
$0 restart
;;
*)
# For invalid arguments, print the usage message.
echo "Usage: $0 {start|stop|restart|reload|status}"
exit2
;;
esac
编辑:
我一直在研究将 sysvinit(plexconnect)转换为 Upstart.conf,因为 plexconnect 是一个 Upstart.conf,但后来我发现 ubuntu 现在使用 systemd。
我现在遇到的问题是,由于某种原因,plexmediaserver 作为 Upstart 运行,当我尝试制作 Upstart plexconnect.conf 时发生了以下情况:
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
所以现在我更加困惑了...如果 16.04 不允许我更新 Upstart,plexmediaplayer 如何成为 Upstart 服务?(通过 Ubuntu 包安装)。
答案1
主要问题是 Plexmediaserver 使用 Upstart/systemD,因此初始化脚本失败。
我在本指南中提供了更多信息:http://forums.plex.tv/discussion/213637/ubuntu-15-debian-8-raspbian-jessie-arch-or-based-autostart