# # Cookbook:: kosmos-ejabberd # Recipe:: default # # The MIT License (MIT) # # Copyright:: 2019, Kosmos Developers # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. include_recipe "kosmos-postgresql" cookbook_file "#{Chef::Config[:file_cache_path]}/pg.new.sql" do source "pg.new.sql" mode "0664" end ejabberd_version = node["kosmos-ejabberd"]["version"] package_checksum = node["kosmos-ejabberd"]["checksum"] package_path = "#{Chef::Config['file_cache_path']}/ejabberd_#{ejabberd_version}-0_amd64.deb" remote_file package_path do source "https://www.process-one.net/downloads/downloads-action.php?file=/ejabberd/#{ejabberd_version}/ejabberd_#{ejabberd_version}-0_amd64.deb" checksum package_checksum notifies :install, "dpkg_package[ejabberd]", :immediately end dpkg_package "ejabberd" do source package_path action :nothing notifies :create, "file[/lib/systemd/system/ejabberd.service]", :immediately end postgresql_connection_info = { host: '127.0.0.1', port: 5432, username: 'postgres', password: node['postgresql']['password']['postgres'] } postgresql_database 'ejabberd' do connection postgresql_connection_info action :create notifies :run, "execute[create db schema]", :delayed end postgresql_database_user 'ejabberd' do connection postgresql_connection_info password 'super_secret' database_name 'ejabberd' privileges [:all] action [:create, :grant] end execute "create db schema" do user "ejabberd" command "psql ejabberd < #{Chef::Config[:file_cache_path]}/pg.new.sql" action :nothing end template "/opt/ejabberd/conf/ejabberd.yml" do source "ejabberd.yml.erb" mode 0640 sensitive true variables pgsql_password: "super_secret" notifies :run, "execute[ejabberdctl reload_config]", :delayed end execute "ejabberdctl reload_config" do command "/opt/ejabberd-#{ejabberd_version}/bin/ejabberdctl reload_config" action :nothing end file "/etc/init.d/ejabberd" do action :delete end # Copy the systemd service file file "/lib/systemd/system/ejabberd.service" do content lazy { IO.read("/opt/ejabberd-#{ejabberd_version}/bin/ejabberd.service") } action :nothing notifies :run, "execute[systemctl daemon-reload]", :immediately end execute "systemctl daemon-reload" do command "systemctl daemon-reload" action :nothing end directory "/var/www/xmpp.kosmos.org/uploads" do owner "ejabberd" group "ejabberd" mode 0750 recursive true end service "ejabberd" do action [:enable, :start] end