Skip to content

Add nice and ionice #97

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
101 changes: 85 additions & 16 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,78 @@
$use_chroot = 'yes',
$uid = 'nobody',
$gid = 'nobody',
$nice = '0',
$ionice = '2',
$modules = {},
) inherits rsync {

$conf_file = $::osfamily ? {
'Debian' => '/etc/rsyncd.conf',
'suse' => '/etc/rsyncd.conf',
'RedHat' => '/etc/rsyncd.conf',
'FreeBSD' => '/usr/local/etc/rsync/rsyncd.conf',
default => '/etc/rsync.conf',
}
$servicename = $::osfamily ? {
'suse' => 'rsyncd',
'RedHat' => 'rsyncd',
'FreeBSD' => 'rsyncd',
default => 'rsync',
case $::osfamily {
'Debian': {
$conf_file = '/etc/rsyncd.conf'
$servicename = 'rsync'

case $::operatingsystem {
'Debian': {
if $::operatingsystemmajrelease <= 7 {
$initstyle = 'init'
} else {
$initstyle = 'systemd'
}
}
'Ubuntu': {
if $::lsbmajdistrelease <= 14 {
$initstyle = 'upstart'
} else {
$initstyle = 'systemd'
}
}
default: {
$conf_file = '/etc/rsync.conf'
$servicename = 'rsync'
$initstyle = 'init'
}
}
}
'RedHat': {
$conf_file = '/etc/rsyncd.conf'
$servicename = 'rsyncd'

if $::operatingsystemmajrelease <= 6 {
$initstyle = 'init'
} else {
$initstyle = 'systemd'
}
}
'suse': {
$conf_file = '/etc/rsyncd.conf'
$servicename = 'rsyncd'

if $::lsbdistrelease <= 11 {
$initstyle = 'init'
} else {
$initstyle = 'systemd'
}
}
'FreeBSD': {
$conf_file = '/usr/local/etc/rsync/rsyncd.conf'
$servicename = 'rsyncd'
$initstyle = 'bsd'
}
default: {
$conf_file = '/etc/rsync.conf'
$servicename = 'rsync'
$initstyle = 'init'
}
}

if $use_xinetd {
include xinetd
xinetd::service { 'rsync':
bind => $address,
port => '873',
server => '/usr/bin/rsync',
server_args => "--daemon --config ${conf_file}",
nice => $nice,
server => '/usr/bin/ionice',
server_args => "-c${ionice} /usr/bin/rsync --daemon --config ${conf_file}",
require => Package['rsync'],
}
} else {
Expand All @@ -48,10 +96,31 @@
subscribe => Concat[$conf_file],
}

if $initstyle == 'systemd' {
file { 'systemd_rsync_service_d':
ensure => directory,
path => "/etc/systemd/system/${servicename}.service.d",
}

file { 'systemd_nice':
path => "/etc/systemd/system/${servicename}.service.d/nice.conf",
content => "[Service]\nNice=${nice}",
require => File['systemd_rsync_service_d'],
notify => Service[$servicename],
}

file { 'systemd_ionice':
path => "/etc/systemd/system/${servicename}.service.d/ionice.conf",
content => "[Service]\nIOSchedulingClass=${ionice}",
require => File['systemd_rsync_service_d'],
notify => Service[$servicename],
}
}

if ( $::osfamily == 'Debian' ) {
file { '/etc/default/rsync':
source => 'puppet:///modules/rsync/defaults',
notify => Service['rsync'],
content => template('rsync/defaults.erb'),
notify => Service['rsync'],
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions files/defaults → templates/defaults.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RSYNC_ENABLE=true
# using a remote shell. When using a different file for
# rsync you might want to symlink /etc/rsyncd.conf to
# that file.
# RSYNC_CONFIG_FILE=
RSYNC_CONFIG_FILE=<%= @conf_file %>

# what extra options to give rsync --daemon?
# that excludes the --daemon; that's always done in the init.d script
Expand All @@ -28,7 +28,7 @@ RSYNC_OPTS=''
# the rsync daemon can impact performance due to much I/O and CPU usage,
# so you may want to run it at a nicer priority than the default priority.
# Allowed values are 0 - 19 inclusive; 10 is a reasonable value.
RSYNC_NICE=''
RSYNC_NICE='<%= @nice %>'

# run rsyncd with ionice?
# "ionice" does for IO load what "nice" does for CPU load.
Expand All @@ -37,7 +37,7 @@ RSYNC_NICE=''
# See the manpage for ionice for allowed options.
# -c3 is recommended, this will run rsync IO at "idle" priority. Uncomment
# the next line to activate this.
# RSYNC_IONICE='-c3'
RSYNC_IONICE='-c<%= @ionice %>'

# Don't forget to create an appropriate config file,
# else the daemon will not start.