Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use systemd (and keep upstart compatibility) #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <keyfile>' 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/
12 changes: 12 additions & 0 deletions files/csync2-inotify.service
Original file line number Diff line number Diff line change
@@ -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
52 changes: 30 additions & 22 deletions manifests/group.pp
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
28 changes: 16 additions & 12 deletions manifests/groupnode.pp
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
33 changes: 29 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,6 +45,10 @@
{ ensure => $ensure }
)

file { '/etc/csync2':
ensure => directory,
}

#Csync2 needs xinetd
xinetd::service { 'csync2':
ensure => $ensure,
Expand All @@ -35,6 +59,7 @@
server_args => '-i',
flags => 'REUSE',
protocol => 'tcp',
require => File['/etc/csync2'],
}

}
43 changes: 32 additions & 11 deletions manifests/inotify.pp
Original file line number Diff line number Diff line change
@@ -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 = [],
Expand All @@ -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':
Expand All @@ -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
Expand All @@ -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'],
}


}
5 changes: 2 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion templates/csync2_body.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
include <%= incval %>;
<% end -%>

<% if excludes -%>
<% if @excludes -%>
<% Array(@excludes).sort.each do |excval| -%>
exclude <%= excval %>;
<% end -%>
Expand Down