diff --git a/README.md b/README.md index e4d87af..a784b22 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,37 @@ Puppet Csync2 ============= -Here is what it can do, followed by an example configuration. -You can use csync2 much like other tools (Unison, rsync, etc.), but what is nice about Csync2 is it is -very fast and maintains a sqlite database of all file changes. -This means it is capable of managing several hundred thousand files to be synced between multiple systems -with very little lag between results (essentially a few seconds most of the time). Unlike rsync you can do -multi-write style replication which is a requirement if you have several web-servers all being written to. +Puppet module for managing csync2. +For general csync2 information and documentation, please refer to: http://oss.linbit.com/csync2/ This module utilizes a resource collector on each defined node to build a sync configuration. -Example usage below, all configs go into your node configuration: +## Example usage - class {'csync2': } +First you will need to define a csync2 GROUP key using csync2 on the command line: - @@csync2::groupnode { $::fqdn: - group => 'default', } +```bash +csync2 -k csync2.example.key +``` - csync2::group { 'default': - includes => ["path1", "path2"], - excludes => ['*.svn'], - auto => 'younger', - } +Deploy that key with puppet and configure the csync2 class: -Additionally, you will need to define a csync2 GROUP key. To do this you will need to have a csync2 -installation somewhere. You will then use 'csync2 -k ' to write the key. Define this key on your puppet -master or as a local file and define it in the key_source variable in the csync2::group. +```puppet +class {'csync2': } + +csync2::groupnode { $::fqdn: + group => 'default', } + +csync2::group { 'default': + includes => ['/tmp/example/path1', '/tmp/example/path2'], + excludes => ['*.svn'], + auto => 'younger', + group_key => 'example', + key_source => 'puppet:///modules/csync2/keys/csync2.example.key', +} +``` + +## Requirements + +- [puppetlabs-concat](https://github.com/puppetlabs/puppetlabs-concat) -For more general csync2 documentation, please refer to: http://oss.linbit.com/csync2/ diff --git a/files/csync2-inotify.service b/files/csync2-inotify.service new file mode 100644 index 0000000..3513d2b --- /dev/null +++ b/files/csync2-inotify.service @@ -0,0 +1,12 @@ +[Unit] +Description=csync2-inotify Service +After=xinetd.service + +[Service] +Type=simple +User=root +ExecStart=/usr/local/bin/csync2-inotify +Restart=on-failure + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/manifests/group.pp b/manifests/group.pp index 22ae5b5..cd5aa21 100644 --- a/manifests/group.pp +++ b/manifests/group.pp @@ -1,25 +1,32 @@ -#Resource definition for a csync2 GROUP. This is the core resource realized on -#each node in the csync2 cluster. -#Options: -#[group_key] This defines the name of the group-key to utilize for the defined -#group. By default it will be based off of the NAME of the defined resource. -#[key_source] Defines the location (local or from puppet-server) of the key -#to use for syncing this particular group -#[includes] The list of folders, or single folders to use with a sync group. -#Defaults to a test path. -#[excludes] A default list of files or folders to EXCLUDE from syncing. This -#defaults to everything so make sure to modify this option! -#[configfile] The default config-file to use for csync2. You probably -#shouldn't modify. -#[configpath] The default config-path to use for csync2. -#[auto] The logic to use for syncing of conflicts. This defaults to none. You -#can choose from: -#none, first, younger, older, bigger, smaller, left, right. Probably younger or -#none is what you want. -#[checkfreq] The amount of sleep timing to wait after a file modification has -#been detected. Default to 5s. +# Resource definition for a csync2 GROUP. +# This is the core resource to be applied on each cluster node + +# Options: +# [group_key] This defines the name of the group-key to utilize for the defined +# group. By default it will be based off of the NAME of the defined resource. +# +# [key_source] Defines the location (local or from puppet-server) of the key +# to use for syncing this particular group +# +# [includes] The list of folders, or single folders to use with a sync group. +# Defaults to a test path. +# +# [excludes] A default list of files or folders to EXCLUDE from syncing. This +# defaults to everything so make sure to modify this option! +# +# [configfile] The default config-file to use for csync2. You probably +# shouldn't modify. +# +# [configpath] The default config-path to use for csync2. +# +# [auto] The logic to use for syncing of conflicts. This defaults to none. +# Options: +# none, first, younger, older, bigger, smaller, left, right. Probably younger or +# none is what you want. +# +# [checkfreq] The amount of sleep timing to wait after a file modification has +# been detected. Default to 5s. -#Base resource definition for a csync2 group. define csync2::group ( $group_key = "csync2.${name}.key", $key_source = $::csync2::params::default_key, @@ -46,7 +53,8 @@ validate_absolute_path($csync2_exec) validate_string($csync2_package) - #Copy the key to the host + # Copy the key to the host + # Can be generated on a host by running csync2 -k csync2.example.key file { "${configpath}/${group_key}": ensure => present, source => $key_source, diff --git a/manifests/groupnode.pp b/manifests/groupnode.pp index e27fdec..adf1d75 100644 --- a/manifests/groupnode.pp +++ b/manifests/groupnode.pp @@ -1,15 +1,19 @@ -#Defines a csync2 group single node. Implemented as a resource collection -#Options: -#[group] The default group-name of this defined node in which to tag the entry. -#This is used in resource collection on the group -#[hostname] This specifies the hostname to use for the defined node. By default -#the hostname of the system. -#[ipaddress] The IP address to use to actually connect to the server. This -#could ALSO be a separate hostname. By default it's the primary IP on the -#system/server. -#[configfile] You probably shouldn't touch this. -#[slave] Set this node in master or slave status with csync2. -#If slave it will pull from defined master(s). +# Defines a csync2 group single node. +# +# Options: +# [group] The default group-name of this defined node in which to tag the entry. +# This is used in resource collection on the group +# +# [hostname] This specifies the hostname to use for the defined node. By default +# the hostname of the system. +# +# [ipaddress] The IP address to use to connect to the server. +# Can also be a hostname. By default it's the primary IP on the host. +# +# [configfile] You probably shouldn't touch this. +# +# [slave] Set this node in master or slave status with csync2. +# If slave it will pull from defined master(s). define csync2::groupnode ( $group = 'default', diff --git a/manifests/init.pp b/manifests/init.pp index 9b3492b..ba508ff 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,9 +1,29 @@ -#The base csync2 resource initialization. -#Options: -#[ensure] Set to (absent/present). Defaults to present for the csync2 resources +# Installs and manages Csync2 with iNotify support # -#[checkfreq] The default check frequency for all groups on the csync2 hosts +# Options: +# [ensure] Set to (absent/present). Defaults to present for the csync2 resources # +# [checkfreq] The default check frequency for all groups on the csync2 hosts +# +# First you will need to define a csync2 GROUP key using csync2 on the command line: +# +# csync2 -k csync2.example.key +# +# Deploy that key with puppet and configure the csync2 class: +# +# class {'csync2': } +# +# csync2::groupnode { $::fqdn: +# group => 'default', } +# +# csync2::group { 'default': +# includes => ['/tmp/example/path1', '/tmp/example/path2'], +# excludes => ['*.svn'], +# auto => 'younger', +# group_key => 'example', +# key_source => 'puppet:///modules/csync2/keys/csync2.example.key', +# } + class csync2 ( $ensure = 'present', $checkfreq = $::csync2::params::checkfreq, @@ -25,6 +45,10 @@ { ensure => $ensure } ) + file { '/etc/csync2': + ensure => directory, + } + #Csync2 needs xinetd xinetd::service { 'csync2': ensure => $ensure, @@ -35,6 +59,7 @@ server_args => '-i', flags => 'REUSE', protocol => 'tcp', + require => File['/etc/csync2'], } } diff --git a/manifests/inotify.pp b/manifests/inotify.pp index e0957ca..0c1d46c 100644 --- a/manifests/inotify.pp +++ b/manifests/inotify.pp @@ -1,7 +1,8 @@ -#Internal inotify class description. There isn't really much to edit here. +#Internal inotify class description. +# #This defines a simple script which launches into the background on the node #waiting for inotify data. -# + class csync2::inotify ( $ensure = $::csync2::ensure, $syncfolders = [], @@ -12,7 +13,7 @@ #Validate variables validate_re($ensure, '^present$|^absent$') validate_array($syncfolders) - validate_string($sleeptime) + validate_string($sleeptimer) #The inotify script file { '/usr/local/bin/csync2-inotify': @@ -23,11 +24,32 @@ content => template('csync2/inotify_body.erb'), } - #Basic upstart init script for inotify - file { '/etc/init/csync2.conf': - ensure => $ensure, - source => 'puppet:///modules/csync2/csync2.conf', - require => File['/usr/local/bin/csync2-inotify'], + case $service_provider { + + 'upstart': { + #Basic upstart init script for inotify + file { 'csync2-service': + ensure => $ensure, + source => 'puppet:///modules/csync2/csync2.conf', + path => '/etc/init/csync2-inotify.conf', + require => File['/usr/local/bin/csync2-inotify'], + } + } + + 'systemd': { + #Basic upstart init script for inotify + file { 'csync2-service': + ensure => $ensure, + path => '/etc/systemd/system/csync2-inotify.service', + source => 'puppet:///modules/csync2/csync2-inotify.service', + require => File['/usr/local/bin/csync2-inotify'], + notify => Exec['reload-systemd'], + } + exec { 'reload-systemd': + command => '/usr/bin/systemctl daemon-reload', + refreshonly => true, + } + } } #Selector for turning 'present' to true @@ -37,11 +59,10 @@ } #Start the csync2 service - service { 'csync2': + service { 'csync2-inotify': ensure => $service_ensure, enable => $service_ensure, - require => File['/etc/init/csync2.conf'], + require => File['csync2-service'], } - } diff --git a/manifests/params.pp b/manifests/params.pp index 7da5e8c..9ccd027 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,6 +1,5 @@ -#If additional OS versions are to be added eventually for support the config -#path and file will have to be changed to something else. -# +# Sets default parameters + class csync2::params { #Some class defaults diff --git a/templates/csync2_body.erb b/templates/csync2_body.erb index c8153f8..6513816 100644 --- a/templates/csync2_body.erb +++ b/templates/csync2_body.erb @@ -5,7 +5,7 @@ include <%= incval %>; <% end -%> -<% if excludes -%> +<% if @excludes -%> <% Array(@excludes).sort.each do |excval| -%> exclude <%= excval %>; <% end -%>