3

On Ubuntu >=12.04, what is the most correct/prettiest way to get rngd to run in multiple instances using an init script? The current one only accepts one random source, so multiple instances are needed.

I.e. I would like rngd to be controlled with the "service" command.

When I manually start rngd, it works as I hoped and thus gathering randomness twice the speed of just a single source.

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

Any ideas how to solve this?

Edit

End version looks like this, thanks @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
1

You can try to write an Upstart job using instances (the device file would be the instance), then another job that starts all the instances you want at boot.

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

It would be easier for you if you made the pidfiles based on the device name, so it would be something like "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

then another job, rng-tools, like this:

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

You place these files as /etc/init/rngd-instance.conf and /etc/init/rng-tools.conf.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.