urandomfix.pp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # jdk7::urandomfix
  2. #
  3. # On Linux low entropy can cause certain operations to be very slow.
  4. # Encryption operations need entropy to ensure randomness. Entropy is
  5. # generated by the OS when you use the keyboard, the mouse or the disk.
  6. #
  7. # If an encryption operation is missing entropy it will wait until
  8. # enough is generated.
  9. #
  10. # three options
  11. # use rngd service (this class)
  12. # set java.security in JDK ( jre/lib/security )
  13. # set -Djava.security.egd=file:/dev/./urandom param
  14. #
  15. class jdk7::urandomfix () {
  16. case $::kernel {
  17. 'Linux': { $path = '/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:' }
  18. default : { fail("Unrecognized operating system") }
  19. }
  20. # set the Exec defaults
  21. Exec {
  22. path => $path,
  23. logoutput => true,
  24. user => 'root',
  25. }
  26. package { "rng-tools": ensure => present, }
  27. case $osfamily {
  28. 'RedHat': {
  29. exec { "set urandom /etc/sysconfig/rngd":
  30. command => "sed -i -e's/EXTRAOPTIONS=\"\"/EXTRAOPTIONS=\"-r \\/dev\\/urandom -o \\/dev\\/random -b\"/g' /etc/sysconfig/rngd",
  31. unless => "/bin/grep '^EXTRAOPTIONS=\"-r /dev/urandom -o /dev/random -b\"' /etc/sysconfig/rngd",
  32. require => Package["rng-tools"],
  33. }
  34. service { "start rngd service":
  35. ensure => true,
  36. name => "rngd",
  37. enable => true,
  38. require => Exec["set urandom /etc/sysconfig/rngd"],
  39. }
  40. exec { "chkconfig rngd":
  41. command => "chkconfig --add rngd",
  42. require => Service["start rngd service"],
  43. unless => "chkconfig | /bin/grep 'rngd'",
  44. }
  45. }
  46. 'Debian','Suse' : {
  47. exec { "set urandom /etc/default/rng-tools":
  48. command => "sed -i -e's/#HRNGDEVICE=\\/dev\\/null/HRNGDEVICE=\\/dev\\/urandom/g' /etc/default/rng-tools",
  49. unless => "/bin/grep '^HRNGDEVICE=/dev/urandom' /etc/default/rng-tools",
  50. require => Package["rng-tools"],
  51. }
  52. service { "start rng-tools service":
  53. ensure => true,
  54. name => "rng-tools",
  55. enable => true,
  56. require => Exec["set urandom /etc/default/rng-tools"],
  57. }
  58. }
  59. default: {
  60. fail("Unrecognized osfamily ${::osfamily}, please use it on a Linux host")
  61. }
  62. }
  63. }