generic_service.pp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # == Define: nova::generic_service
  2. #
  3. # This defined type implements basic nova services.
  4. # It is introduced to attempt to consolidate
  5. # common code.
  6. #
  7. # It also allows users to specify ad-hoc services
  8. # as needed
  9. #
  10. # This define creates a service resource with title nova-${name} and
  11. # conditionally creates a package resource with title nova-${name}
  12. #
  13. # === Parameters:
  14. #
  15. # [*package_name*]
  16. # (mandatory) The package name (for the generic_service)
  17. #
  18. # [*service_name*]
  19. # (mandatory) The service name (for the generic_service)
  20. #
  21. # [*enabled*]
  22. # (optional) Define if the service must be enabled or not
  23. # Defaults to false.
  24. #
  25. # [*manage_service*]
  26. # (optional) Manage or not the service (if a service_name is provided).
  27. # Defaults to true.
  28. #
  29. # [*ensure_package*]
  30. # (optional) Control the ensure parameter for the package ressource.
  31. # Defaults to 'present'.
  32. #
  33. define nova::generic_service(
  34. $package_name,
  35. $service_name,
  36. $enabled = true,
  37. $manage_service = true,
  38. $ensure_package = 'present'
  39. ) {
  40. include ::nova::deps
  41. include ::nova::params
  42. $nova_title = "nova-${name}"
  43. # I need to mark that ths package should be
  44. # installed before nova_config
  45. if ($package_name) {
  46. if !defined(Package[$nova_title]) and !defined(Package[$package_name]) {
  47. package { $nova_title:
  48. ensure => $ensure_package,
  49. name => $package_name,
  50. tag => ['openstack', 'nova-package'],
  51. }
  52. }
  53. }
  54. if $service_name {
  55. if $manage_service {
  56. if $enabled {
  57. $service_ensure = 'running'
  58. } else {
  59. $service_ensure = 'stopped'
  60. }
  61. }
  62. service { $nova_title:
  63. ensure => $service_ensure,
  64. name => $service_name,
  65. enable => $enabled,
  66. hasstatus => true,
  67. tag => 'nova-service',
  68. }
  69. }
  70. }