我不确定这是否会完全解决您的问题,但这是我在尝试pyro-nsd
使用 python2.7 时学到的。在这种情况下,我使用了 Ubuntu 14.04。Wheezy 版本可能会有所不同。
- 我使用安装,
sudo apt-get install pyro4
因为pyro4-nsd
不是通过 pip 安装的。
- 我注意到的第一件事
pyro4-nsc list
是没有被识别。
- 那么我使用 pyro4 进行
sudo pip install pyro4
.
- 现在
pyro4-nsc list
工作,但我得到了Failed to locate the nameserver
错误。
所以我看了一下配置/etc/init.d/pyro4-nsd
,发现了一些有趣的东西。
1.
该脚本检查是否安装了 python3。如果是,它将使用 pyro4 的 python3 版本,它作为依赖项安装sudo apt-get install pyro4
.
这里我只是让它使用python2.7
。
现在pyro4-nsc list
实际上有效,但我收到此错误:Error: CommunicationError - cannot connect: hmac key config not symmetric
,导致数字 2
2.
接下来我注意到的export PYRO_HMAC_KEY=12345
是pyro4-nsd
.
在Pyro4/configuration.py
文件中,这似乎仅用于 python3:(https://github.com/delmic/Pyro4/blob/ccea9c2870a1280010bcc56f4146bc1617ec6e8d/src/Pyro4/configuration.py#L81)。在此处查看此片段:
if self.HMAC_KEY and sys.version_info>=(3,0):
if type(self.HMAC_KEY) is not bytes:
self.HMAC_KEY=bytes(self.HMAC_KEY, "utf-8") # convert to bytes
所以,基本上我只是删除了PYRO_HMAC_KEY
出口线。
3.
次要的事情sudo service pyro4-nsd restart
,但是当它应该停止服务然后启动它时,启动然后停止服务。
这是修改后的 pyro4-nsd 文件:
#!/bin/sh
### BEGIN INIT INFO
# Provides: pyro4-nsd
# Required-Start: $time $local_fs $remote_fs $network
# Required-Stop: $time $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Pyro4 name server daemon
# Description: Debian init script for pyro4-nsd (Pyro4 name server daemon)
### END INIT INFO
# -------------------------------------------------------------------------
# <Pyro4 NameServer Daemon Script>
# Copyright (C) <2011> <Pierre PACORY> - ppacory@gmail.com
# Licensed under the "MIT Software License" for inclusion in Pyro4.
# -------------------------------------------------------------------------
LISTEN_ADDRESS=0.0.0.0
LISTEN_PORT=9999
MESSAGEDIR=/var/log/Pyro4
MESSAGELOG=/var/log/Pyro4/NameServer.log
PID=/var/run/Pyro4-NameServer.pid
# Defaults - don't touch, edit /etc/default/pyro-nsd
ENABLED=0
if [ -f /etc/default/pyro4-nsd ] ; then
. /etc/default/pyro4-nsd
fi
if [ "$ENABLED" = "0" ]; then
echo "pyro4-nsd: disabled, see /etc/default/pyro4-nsd"
exit 0
fi
# Add Pyro Config
# here you can add others ...
# NOTE: Comment out PYRO_HMAC_KEY since it appears to be used only for Python3
#export PYRO_HMAC_KEY=12345
export PYRO_LOGFILE="$MESSAGELOG"
export PYRO_LOGLEVEL=DEBUG
. /lib/lsb/init-functions
# Check the script is being run by root user
if [ "$(id -u)" != "0" ]; then
echo 1>&2 "ERROR: The $0 script must be run as root"
exit 1
fi
# Create the PID File
touch $PID
# Detect if Python 2.x or Python 3.y is installed
# NOTE: For the use of python2.7 here
PYTHON=python2.7
[ -x /usr/bin/$PYTHON ] || PYTHON=python
case "$1" in
start)
# create the log directory if not exist
[ ! -d "$MESSAGEDIR" ] && mkdir -p "$MESSAGEDIR"
echo "Starting Pyro4 Name Server"
# test if not already running
if [ ! -f "/proc/$(cat $PID)/exe" ]; then
$PYTHON -m Pyro4.naming -n "$LISTEN_ADDRESS" -p "$LISTEN_PORT" >/dev/null 2>&1 &
echo $!>"$PID"
else
echo "Pyro4 Name Server already running"
fi
;;
stop)
echo "Stopping Pyro4 Name Server"
# test if running
if [ -f "/proc/$(cat $PID)/exe" ]; then
kill -9 "$(cat $PID)"
rm -rf "$PID"
else
echo "Pyro4 Name Server already stopped"
fi
;;
restart)
# Stop, then Start
$0 stop
$0 start
;;
force-reload)
# Stop, then Start
$0 stop
$0 start
;;
*)
echo "usage: $0 {start|stop|restart|force-reload}"
esac
exit 0