default.rb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #
  2. # Cookbook Name:: dovecot
  3. # Recipe:: default
  4. #
  5. # Copyright 2013, Onddo Labs, Sl.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. #
  20. # packages
  21. #
  22. conf_files = node['dovecot']['conf_files']['core']
  23. case node['platform']
  24. when 'redhat','centos','scientific','fedora','suse','amazon' then
  25. # core, imap, pop3, lmtp, ldap, sqlite
  26. package 'dovecot'
  27. conf_files +=
  28. node['dovecot']['conf_files']['imap'] +
  29. node['dovecot']['conf_files']['pop3'] +
  30. node['dovecot']['conf_files']['lmtp'] +
  31. node['dovecot']['conf_files']['ldap']
  32. # sieve
  33. package 'dovecot-pigeonhole' do
  34. only_if do Dovecot::Plugins.required?('sieve', node['dovecot']) end
  35. end
  36. conf_files += node['dovecot']['conf_files']['sieve']
  37. when 'debian', 'ubuntu' then
  38. # core
  39. package 'dovecot-core'
  40. package 'dovecot-gssapi'
  41. # imap
  42. package 'dovecot-imapd' do
  43. only_if do Dovecot::Protocols.enabled?('imap', node['dovecot']['protocols']) end
  44. end
  45. conf_files += node['dovecot']['conf_files']['imap']
  46. # pop3
  47. package 'dovecot-pop3d' do
  48. only_if do Dovecot::Protocols.enabled?('pop3', node['dovecot']['protocols']) end
  49. end
  50. conf_files += node['dovecot']['conf_files']['pop3']
  51. # lmtp
  52. package 'dovecot-lmtpd' do
  53. only_if do Dovecot::Protocols.enabled?('lmtp', node['dovecot']['protocols']) end
  54. end
  55. conf_files += node['dovecot']['conf_files']['lmtp']
  56. # sieve
  57. package 'dovecot-sieve' do
  58. only_if do Dovecot::Plugins.required?('sieve', node['dovecot']) end
  59. end
  60. package 'dovecot-managesieved' do
  61. only_if do Dovecot::Plugins.required?('sieve', node['dovecot']) end
  62. end
  63. conf_files += node['dovecot']['conf_files']['sieve']
  64. # ldap
  65. package 'dovecot-ldap' do
  66. only_if do node['dovecot']['auth']['ldap'].kind_of?(Array) and node['dovecot']['auth']['ldap'].length > 0 end
  67. end
  68. conf_files += node['dovecot']['conf_files']['ldap']
  69. # sqlite
  70. package 'dovecot-sqlite' do
  71. only_if do node['dovecot']['conf']['sql']['driver'] == 'sqlite' end
  72. end
  73. else
  74. log('Unsupported platform, trying to guess dovecot packages') { level :warn }
  75. package 'dovecot'
  76. end
  77. package 'dovecot-mysql' do
  78. only_if do node['dovecot']['conf']['sql']['driver'] == 'mysql' end
  79. end
  80. package 'dovecot-pgsql' do
  81. only_if do node['dovecot']['conf']['sql']['driver'] == 'pgsql' end
  82. end
  83. #
  84. # system users
  85. #
  86. user node['dovecot']['user'] do
  87. comment 'Dovecot mail server'
  88. home node['dovecot']['lib_path']
  89. shell '/bin/false'
  90. system true
  91. end
  92. group node['dovecot']['group'] do
  93. members [ node['dovecot']['user'] ]
  94. system true
  95. append true
  96. end
  97. #
  98. # config files
  99. #
  100. # create the required directories
  101. directory node['dovecot']['lib_path'] do
  102. owner node['dovecot']['conf_files_user']
  103. group node['dovecot']['conf_files_group']
  104. mode '00755'
  105. end
  106. conf_files_dirs = conf_files.map{ |f| ::File.dirname(f) }.uniq
  107. conf_files_dirs.each do |dir|
  108. directory dir do
  109. owner 'root'
  110. group node['dovecot']['group']
  111. mode '00755'
  112. only_if do dir != '.' end
  113. end
  114. end
  115. # create the conf files
  116. conf_files.each do |conf_file|
  117. template "#{node['dovecot']['conf_path']}/#{conf_file}" do
  118. source "#{conf_file}.erb"
  119. owner node['dovecot']['conf_files_user']
  120. group node['dovecot']['conf_files_group']
  121. mode node['dovecot']['conf_files_mode']
  122. variables(
  123. :auth => node['dovecot']['auth'],
  124. :protocols => node['dovecot']['protocols'],
  125. :services => node['dovecot']['services'],
  126. :plugins => node['dovecot']['plugins'],
  127. :namespaces => node['dovecot']['namespaces'],
  128. :conf => node['dovecot']['conf']
  129. )
  130. notifies :reload, 'service[dovecot]'
  131. end
  132. end
  133. service 'dovecot' do
  134. supports :restart => true, :reload => true, :status => true
  135. action [ :enable, :start ]
  136. end