rngd - 来自 init 脚本的多个实例

rngd - 来自 init 脚本的多个实例

在 Ubuntu >=12.04 上,使用 init 脚本让 rngd 在多个实例中运行的最正确/最漂亮的方法是什么?当前仅接受一个随机源,因此需要多个实例。

即我想rngd用“service”命令进行控制。

当我手动启动时rngd,它按我所希望的方式工作,从而以比单一源快两倍的速度收集随机性。

$ rngd --pidfile=/var/run/rngd0.pid -r /dev/hwrng0  
$ rngd --pidfile=/var/run/rngd1.pid -r /dev/hwrng1

有什么想法如何解决这个问题吗?

编辑

最终版本看起来像这样,谢谢@卡梅伦尼莫:/etc/init/rng-tools.conf:

description     "rng-tools daemon"

start on runlevel [2345]
stop on runlevel [016]

env DEVLIST="$(find /dev/hwrng* -follow -type c)"

pre-start script
  for device in $DEVLIST; do
    start rngd-instance DEVICE=$device || failed="${failed}$device "
  done
  test -n "$failed" || { echo "Failed to start instances: $failed"; exit 1; }
end script

/etc/init/rngd-instance.conf:

stop on stopping rng-tools or runlevel [016]

description "rngd instance"
usage "DEVICE=full path to rng device"

instance $DEVICE

pre-start script
  test -c "$DEVICE" || { echo "Not a device: $DEVICE"; exit 1; }
  mkdir -p /var/run/rngd
end script

exec rngd --foreground --pidfile=/var/run/rngd/$(basename "$DEVICE") -r $DEVICE

/etc/init.d/rng-tools :

$ cd /etc/init.d/
$ sudo ln -sf /lib/init/upstart-job rng-tools

答案1

您可以尝试使用实例编写一个 Upstart 作业(设备文件就是实例),然后编写另一个在启动时启动您想要的所有实例的作业。

http://upstart.ubuntu.com/cookbook/#instance

如果您根据设备名称创建 pidfiles,对您来说会更容易,因此它将类似于“rngd-instance”:

stop on stopping rng-tools or runlevel [016]

instance $DEVICE
usage "DEVICE=full path to rng device"

pre-start script
    test -c $DEVICE || { echo "Not a device: $DEVICE"; exit 1; }
    mkdir -p $(dirname /var/run/rngd/$DEVICE)
end script

exec rngd --foreground --pidfile=/var/run/rngd/$DEVICE -r $DEVICE

然后是另一项工作,rng-tools,如下所示:

start on runlevel [2345]
stop on runlevel [016]

env DEVLIST="/dev/hwrng0 /dev/hwrng1"

pre-start script
    for d in $DEVLIST; do
        initctl start rngd-instance DEVICE=$d || failed="${failed}$d "
    done
    test -n "$failed" || { echo "Failed to start instances: $failed"; exit 1; }
end script

您将这些文件放置为 /etc/init/rngd-instance.conf 和 /etc/init/rng-tools.conf。

相关内容