我已经安装了一个名为“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 作为Required-Start 添加到初始化脚本中:
#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 软件包安装)。
主要问题是 Plexmediaserver 正在使用 Upstart/systemD,因此 init 脚本失败。
我制作的本指南中的更多信息:http ://forums.plex.tv/discussion/213637/ubuntu-15-debian-8-raspbian-jessie-arch-or-based-autostart