# # # bundle agent sympa { classes: "sympa_b"; vars: debian:: "lib_dir" string => "/usr/lib/sympa"; "var_lib_dir" string => "/var/lib/sympa"; "share_dir" string => "/usr/share/sympa"; "conf_dir" string => "/etc/sympa"; "sympa_conf" string => "$(conf_dir)/sympa/sympa.conf"; "service_name" string => "sympa"; "wwservice_name" string => "wwsympa"; "wwsympa_socket" string => "/var/run/sympa/wwsympa.socket"; "sympa_pl_cmd" string => "/usr/bin/sympa"; "pkgs" slist => { "sympa" }; centos:: "lib_dir" string => "/usr/lib/sympa"; "var_lib_dir" string => "/var/lib/sympa"; "share_dir" string => "/usr/share/sympa"; "conf_dir" string => "/etc/sympa"; "sympa_conf" string => "$(conf_dir)/sympa/sympa.conf"; "service_name" string => "sympa"; "wwservice_name" string => "wwsympa"; "wwsympa_socket" string => "/var/run/sympa/wwsympa.socket"; "sympa_pl_cmd" string => "/usr/bin/sympa"; "pkgs" slist => { "sympa" }; debian&sympa_s:: "install_dir" string => "/usr/local/sympa"; "queue_cmd" string => "$(install_dir)/bin/queue"; "bouncequeue_cmd" string => "$(install_dir)/bin/bouncequeue"; "static_content_dir" string => "$(install_dir)/static_content"; "css_dir" string => "$(static_content_dir)/css"; "pictures_dir" string => "$(static_content_dir)/pictures"; any:: "queue_cmd" string => "$(lib_dir)/bin/queue"; "bouncequeue_cmd" string => "$(lib_dir)/bin/bouncequeue"; "static_content_dir" string => "$(share_dir)/static_content"; "pictures_dir" string => "$(static_content_dir)/pictures"; "css_dir" string => "$(var_lib_dir)/css"; "sendmail_aliases" string => "$(conf_dir)/sympa_transport"; "postfix_master_cfg" string => readfile("$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/sympa/postfix-master-cfg.mustache"); "apache_cfg" string => " Alias /css-sympa $(sympa.css_dir) Alias /pictures-sympa $(sympa.pictures_dir) Alias /static-sympa $(sympa.static_content_dir) Require all granted Require all granted Require all granted SetHandler \\\"proxy:unix:$(sympa.wwsympa_socket)|fcgi://\\\" Require all granted "; reports: # "MUSTACHE: $(postfix_master_cfg_m)"; # "RF: $(sys.workdir)/inputs/$(wmde_lib)/templates/sympa-postfix-master-cfg.mustache"; } bundle agent sympa_init_db(cfg) { classes: "run_backups" expression => isvariable("cfg[backup_dir]"); run_backups:: "sql_backup_exists" expression => fileexists("$(cfg[backup_dir])/sympa.sql"); methods: "any" usebundle => mysql_table_exists(@(cfg[db_settings]),"user_table"); run_backups:: "any" usebundle => restore_mysql_db(@(cfg[db_settings]),"$(cfg[backup_dir])/sympa.sql"), depends_on => {"sympa_config_updated"}, if => "sql_backup_exists&(!mysql_sympa_user_table_exists)", handle => "sympa_db_initialized"; commands: "!mysql_sympa_user_table_exists":: "$(sympa.sympa_pl_cmd)" args => "--health_check", handle => "sympa_db_initialized", depends_on => {"sympa_config_updated"}; } bundle agent sympa_create_postfix_maps { classes: "sympa_run_postmap" expression => not(fileexists("$(sympa.sendmail_aliases).db")); files: "$(sympa.sendmail_aliases)" create => "true", classes => if_repaired("sympa_run_postmap"), perms => mog("644","sympa","sympa"), handle => "sympa_sendmail_aliases_created"; "$(sympa.conf_dir)/list_aliases.tt2" create => "true", copy_from => local_dcp("$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/sympa/list_aliases.tt2.mustache"), perms => mog("644","sympa","sympa"); commands: "sympa_run_postmap":: "$(postfix.postmap_cmd)" args => "$(sympa.sendmail_aliases)", classes => if_repaired("postfix_repaired"), depends_on => {"sympa_sendmail_aliases_created"}; reports: # "create maps"; # "sympa_sendmail_aliases_repaired":: # "POSTMAP CALL"; } bundle agent sympa_create_postfix_general_maps(cfg,dest_file) { vars: "dl" slist => getindices(@(cfg[domains])); "cnt" string => string_mustache(" # # Managed by CFEngine # {{#dl}} sympa@{{.}} sympa:sympa@{{.}} listmaster@{{.}} sympa:listmaster@{{.}} bounce@{{.}} sympabounce:bounce@{{.}} abuse-feedback-report@{{.}} sympabounce:abuse-feedback-report@{{.}} {{/dl}} ", bundlestate("$(this.bundle)")); classes: "postfix_repaired" expression => not(fileexists("$(dest_file).db")), scope => "namespace"; files: "$(dest_file)" perms => m("644"), create => "true", content => "$(cnt) ", classes => if_repaired("postfix_repaired"), handle => "sympa_postfix_general_maps_created" ; commands: postfix_repaired:: "$(postfix.postmap_cmd)" args => "$(dest_file)", inform => "true", depends_on => {"sympa_postfix_general_maps_created"}; reports: } bundle agent sympa_postfix_sql(cfg) { vars: "file[sympa_virtual_mailbox_maps]" string => "query = SELECT 'present' FROM list_table WHERE name_list='%u' or name_list = replace('%u', '-request', '') or name_list = replace('%u', '-editor', '') or name_list = replace('%u', '-subscribe', '') or name_list = replace('%u', '-unsubscribe', '') "; "idx" slist => getindices("file"); "maps_dir" string => "$(postfix.cfg_dir)/sql"; "$(idx)" string => "$(maps_dir)/$(idx).sql"; files: "$(maps_dir)/." create => "true", perms => m("755"); "$(maps_dir)/$(idx).sql" create=>"true", perms=>m("644"), content=>" user = $(cfg[db_user]) password = $(cfg[db_pass]) hosts = $(cfg[db_host]) dbname = $(cfg[db_name]) $(file[$(idx)]) "; reports: } bundle agent sympa_update_config(cfg) { vars: "default_settings" data => '{ "aliases_db_type":"hash", "aliases_program":"$(postfix.postmap_cmd)", "sendmail_aliases":"$(sympa.sendmail_aliases)", "db_type":"$(cfg[db_settings][db_type])", "db_name":"$(cfg[db_settings][db_name])", "db_host":"$(cfg[db_settings][db_host])", "db_passwd":"$(cfg[db_settings][db_pass])", "db_user":"$(cfg[db_settings][db_user])" }'; "settings_data" data => mergedata(@(default_settings),@(cfg[settings])); "idx" slist => getindices(@(settings_data)); "settings[$(idx)]" string => "$(settings_data[$(idx)])"; files: "$(sympa.sympa_conf)" edit_line => set_config_values("$(this.bundle).settings"), handle => "sympa_config_updated", classes => if_repaired("sympa_repaired"), depends_on => { "sympa_pkgs_installed" }; reports: } bundle agent install_sympa_domain(domain,data) { vars: "default_settings" data => '{ }'; "settings_data" data => mergedata(@(default_settings),@(data[settings])); "idx" slist => getindices(@(settings_data)); "settings[$(idx)]" string => "$(settings_data[$(idx)])"; "settings[domain]" string => "$(domain)"; files: "$(sympa.conf_dir)/$(domain)/." create => "true", perms => m("755"); "$(sympa.conf_dir)/$(domain)/robot.conf" perms => m("644"), copy_from => seed_cp("$(sys.workdir)/inputs/$(def.wmde_libdir)/templates/sympa/robot.conf"), handle => "sympa_robot_$(domain)_ready"; "$(sympa.conf_dir)/$(domain)/robot.conf" create => "true", perms => m("644"), #"sympa","sympa"), edit_line => set_config_values("$(this.bundle).settings"), handle => "sympa_robots_created", classes => if_repaired("sympa_repaired"), depends_on => { "sympa_pkgs_installed","sympa_robot_$(domain)_ready" }; reports: # "INSTALL DOMAIN $(domain)"; # "WWSYMuRL:$(data[settings][wwsympa_url])"; # "OUT: $(settings)"; # "JO: $(jo)"; } bundle agent install_sympa_domains(dl) { vars: "idx" slist => getindices(@(dl)); methods: "any" usebundle => install_sympa_domain("$(idx)",@(dl[$(idx)])); reports: } bundle agent install_sympa(cfg) { vars: # "cfg_domains" data => @(cfg[domains]); "domains_idx" slist => getindices(@(cfg[domains])); # "cfg_domains" slist => {"a","b","c"}; methods: "any" usebundle => wmde_install_packages(@(sympa.pkgs),"sympa"); "any" usebundle => sympa_update_config(@(cfg)); "any" usebundle => sympa_init_db(@(cfg)); "any" usebundle => wmde_service("$(sympa.service_name)","sympa_kept","sympa_repaired"), depends_on => { "sympa_pkgs_installed", "sympa_config_updated" }; "any" usebundle => wmde_service("$(sympa.wwservice_name)","sympa_kept","sympa_repaired"), depends_on => { "sympa_pkgs_installed", "sympa_config_updated", "sympa_robots_created" }; # "any" usebundle => install_sympa_domain("@(cfg[domains][$(domains_idx)])"); "any" usebundle => install_sympa_domains(@(cfg[domains])); reports: # "IDX $(domains_idx)"; # "DOMCONF: $(cfg[$(idx)])"; } bundle agent install_sympa_src(cfg) { classes: "run_backups" expression => isvariable("cfg[backup_dir]"); run_backups:: "sql_backup_exists" expression => fileexists("$(cfg[backup_dir])/sympa.sql"); methods: "any" usebundle => mysql_table_exists(@(cfg),"user_table"); "run_backups&sql_backup_exists&(!mysql_sympa_user_table_exists)":: "any" usebundle => restore_mysql_db(@(cfg),"$(cfg[backup_dir])/sympa.sql"); vars: debian:: "pkgs" slist => { "clang", "gcc", "make", "mhonarc", "libdbd-mysql-perl", "spawn-fcgi", "libdbd-mysql-perl", "libdatetime-format-mail-perl", "libmime-encwords-perl", "libmime-lite-html-perl", "cpanminus" }; "cfg_file" string => "/etc/sympa/sympa.conf"; "log_file" string => "/var/log/sympa.log"; "syslog_cfg" string => "/etc/rsyslog.d/sympa.conf"; "syslog_service" string => "rsyslog"; freebsd:: "pkgs" slist => {}; "cfg_file" string => "/usr/local/etc/sympa/sympa.conf"; "log_file" string => "/var/log/sympa.log"; "syslog_cfg" string => "/etc/syslog.d/sympa.conf"; "syslog_service" string => "syslogd"; any:: "src_tgz" string => "sympa-$(cfg[version]).tar.gz"; "extract_dir" string => "$(sys.workdir)/data/agent/sympa"; "compile_dir" string => "$(extract_dir)/sympa-$(cfg[version])"; "configure_options" string => "--prefix $(sympa.install_dir)"; "sympa_pl_cmd" string => "$(sympa.install_dir)/bin/sympa.pl"; classes: "compile_and_install" expression => not(fileexists("$(compile_dir)/installed.txt")); commands: 'if grep -q sympa /etc/group ; then echo "+sympa_group_exists"; else echo "-sympa_group_exists" ; fi' module => "true", inform => "false", contain => wmde_cmd_useshell; debian&(!sympa_group_exists):: "/usr/sbin/groupadd" args => "sympa", handle => "sympa_group_created"; debian&sympa_group_exists:: "/usr/bin/true" inform => "false", handle => "sympa_group_created"; methods: "any" usebundle => wmde_install_packages(@(pkgs),"sympabuild"); files: "$(extract_dir)/." create => "true", handle => "sympa_extract_dir_created"; users: "sympa" policy => "present", description => "Sympa System", home_dir => "$(sympa.install_dir)", group_primary => "sympa", depends_on => {"sympa_group_created"}, shell => "/bin/bash"; methods: "any" usebundle => download_and_untar ( "sympa", "$(def.hub_public_dir)/$(src_tgz)", "$(sys.workdir)/data/public/$(src_tgz)", "$(extract_dir)", "$(compile_dir)/configure" ), depends_on => {"sympabuild_pkgs_installed","sympa_extract_dir_created"}, handle => "sympa_downloaded"; commands: compile_and_install:: "cd $(compile_dir) && ./configure $(configure_options) && make && make install && cpanm --installdeps --with-recommends -n . && touch installed.txt" contain => wmde_cmd_useshell, depends_on => {"sympa_downloaded"}, handle => "sympa_installed"; !compile_and_install:: "/usr/bin/true" inform => "false", handle => "sympa_installed"; vars: "settings[domain]" string => "$(cfg[domain])"; "settings[listmaster]" string => "$(cfg[listmaster])"; "settings[db_type]" string => "$(cfg[db_type])"; "settings[db_host]" string => "$(cfg[db_host])"; "settings[db_user]" string => "$(cfg[db_user])"; "settings[db_passwd]" string => "$(cfg[db_pass])"; "settings[wwsympa_url]" string => "$(cfg[wwsympa_url])"; "settings[listmaster]" string => "$(cfg[listmaster])"; "settings[sendmail_aliases]" string=> "$(cfg[sendmail_aliases])"; "settings[aliases_program]" string=> "$(cfg[aliases_program])"; files: "$(cfg_file)" edit_line => set_config_values("$(this.bundle).settings"), handle => "sympa_config_edited_old", classes => if_repaired("sympa_config_changed"), depends_on => { "sympa_installed" }; commands: "sympa_config_changed|(!mysql_sympa_user_table_exists)":: "$(sympa.sympa_pl_cmd)" args => "--health_check", depends_on => {"sympa_config_edited_old"}; # Sympa Logs files: "$(log_file)" create=>"true", perms=>m("644"); "$(syslog_cfg)" create=>"true", content=>"local1.* -/var/log/sympa.log ", handle => "sympa_syslog_cfg_ready", classes => if_repaired("sympa_syslog_cfg_repaired"); services: sympa_syslog_cfg_repaired:: "$(syslog_service)" depends_on => {"sympa_syslog_cfg_ready"}, service_policy=>"restart"; # Configure Backup stuff files: run_backups:: "$(cfg[backup_dir])/." create => "true"; methods: run_backups:: "any" usebundle => create_mysql_backup_cron_job(@(cfg),"$(cfg[backup_dir])/sympa.sql","user_table","true"); !run_backups:: "any" usebundle => create_mysql_backup_cron_job(@(cfg),"$(cfg[backup_dir])/sympa.sql","user_table","false"); reports: }