Daemon

rngd - 來自初始化腳本的多個實例

  • December 10, 2014

在 Ubuntu >=12.04 上,使用 init 腳本讓 rngd 在多個實例中執行的最正確/最漂亮的方法是什麼?目前只接受一個隨機源,因此需要多個實例。

即我想rngd用“服務”命令來控制。

當我手動啟動時rngd,它會像我希望的那樣工作,因此收集隨機性的速度是單一來源的兩倍。

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

任何想法如何解決這個問題?

編輯

最終版本看起來像這樣,感謝@CameronNemo:/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

您可以嘗試使用實例編寫 Upstart 作業(設備文件將是實例),然後另一個作業會在啟動時啟動您想要的所有實例。

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

如果您根據設備名稱製作 pidfile,對您來說會更容易,所以它類似於“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。

引用自:https://unix.stackexchange.com/questions/171749