dbactions.pp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # == Class: oradb::dbactions
  2. #
  3. #
  4. # action = stop|start
  5. #
  6. #
  7. # oradb::dbactions{ 'stop testDb':
  8. # oracleHome => '/oracle/product/11.2/db',
  9. # user => 'oracle',
  10. # group => 'dba',
  11. # action => 'stop',
  12. # dbName => 'test',
  13. # }
  14. #
  15. #
  16. #
  17. define oradb::dbactions( $oracleHome = undef,
  18. $user = 'oracle',
  19. $group = 'dba',
  20. $action = 'start',
  21. $dbName = 'orcl',
  22. )
  23. {
  24. case $::kernel {
  25. Linux, SunOS: {
  26. $execPath = "${oracleHome}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:"
  27. Exec { path => $execPath,
  28. user => $user,
  29. group => $group,
  30. logoutput => true,
  31. }
  32. File {
  33. ensure => present,
  34. mode => 0775,
  35. owner => $user,
  36. group => $group,
  37. }
  38. }
  39. default: {
  40. fail("Unrecognized operating system")
  41. }
  42. }
  43. if $action == 'stop' {
  44. exec { "stop oracle database ${title}":
  45. command => "sqlplus /nolog <<-EOF
  46. connect / as sysdba
  47. shutdown immediate
  48. EOF",
  49. environment => ["ORACLE_HOME=${oracleHome}", "ORACLE_SID=${dbName}", "LD_LIBRARY_PATH=${oracleHome}/lib"],
  50. logoutput => true,
  51. onlyif => "/bin/ps -ef | grep -v grep | /bin/grep 'ora_smon_${dbName}'",
  52. }
  53. } elsif $action == 'start' {
  54. exec { "start oracle database ${title}":
  55. command => "sqlplus /nolog <<-EOF
  56. connect / as sysdba
  57. startup
  58. EOF",
  59. environment => ["ORACLE_HOME=${oracleHome}", "ORACLE_SID=${dbName}", "LD_LIBRARY_PATH=${oracleHome}/lib"],
  60. logoutput => true,
  61. unless => "/bin/ps -ef | grep -v grep | /bin/grep 'ora_smon_${dbName}'",
  62. }
  63. }
  64. }