Skip to content

Commit

Permalink
Merge pull request #7 from frankiethekneeman/feature/niceness
Browse files Browse the repository at this point in the history
Adding Niceness Control for the CI Runner Process.
  • Loading branch information
frankiethekneeman committed Sep 3, 2015
2 parents cbb65b6 + d6ac530 commit af22849
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ The version of the gitlab-ci-multi-runner package is restricted to `v0.4.2` for
##Usage

```puppet
class {'gitlab_ci_multi_runner': }
class {'gitlab_ci_multi_runner':
nice => 15
}
gitlab_ci_multi_runner::runner { "This is My Runner":
gitlab_ci_url => 'http://ci.gitlab.examplecorp.com'
Expand All @@ -34,6 +36,12 @@ gitlab_ci_multi_runner::runner { "This is My Second Runner":
}
```

##Installation Options

#### nice

control the niceness of the actual process running the CI Jobs. Valid values are from -20 to 19. Leading '+' is optional.

##Runner Options

All options are pulled from the Gitlab CI MultiRunner registration command - The name of the runner will be used to
Expand Down
64 changes: 62 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
class gitlab_ci_multi_runner (
$nice = undef
) {
$package_type = $::osfamily ? {
'redhat' => 'rpm',
'debian' => 'deb',
default => 'unknown',
}

$IssuesLink = 'https://github.com/frankiethekneeman/puppet-gitlab-ci-multi-runner/issues'
if $package_type == 'unknown' {
fail("Target Operating system (${::operatingsystem}) not supported")
} elsif $package_type == 'deb' {
warning("${::operatingsystem} support is still in Beta - please report any issues to the main repository at https://github.com/frankiethekneeman/puppet-gitlab-ci-multi-runner/issues")
warning("${::operatingsystem} support is still in Beta - please report any issues to the main repository at ${IssuesLink}")
}

# Get the file created by the "repo adding" step.
Expand Down Expand Up @@ -89,4 +90,63 @@
provider => shell,
}
}
if $nice != undef {
if $nice =~ /^(-20|[-+]?1?[0-9])$/ {
$path = '/bin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/sbin'
case $serviceFile {
'/etc/init.d/gitlab-ci-multi-runner': {
$niceval = $nice ? {
/^[-+]/ => $nice,
default => "+${nice}"
} #The nice value passed to the daemon function must have a leading sign
exec {'Ensure Niceness':
command => "sed -i 's/ daemon \\([+-][0-9]\\+ \\)\\?/ daemon $niceval /g' $serviceFile",
user => root,
provider => shell,
path => $path,
require => Exec['Ensure Service'],
onlyif => "! grep 'daemon $niceval ' $serviceFile", #Only if the niceness isn't already set
notify => Service[$service]
}
}
'/etc/systemd/system/gitlab-runner.service': {
$initCommand = "sed -i '/\\[Service\\]/a Nice=$nice' $serviceFile"
$updateCommand = "sed -i 's/Nice=[+-]\\?[0-9]\\+/Nice=$nice/g' $serviceFile"
$checkCommand = "grep 'Nice=[+-]\\?[0-9]\\+' $serviceFile"
exec {'Ensure Niceness':
command => "$checkCommand && $updateCommand || $initCommand",
user => root,
provider => shell,
path => $path,
require => Exec['Ensure Service'],
onlyif => "! grep 'Nice=$nice *\$' $serviceFile", #Only if the niceness isn't already set
} ~>
exec {'Reload Service Info': #Because Puppet won't automagically do this
command => "systemctl daemon-reload",
user => root,
provider => shell,
path => $path,
refreshonly => true,
notify => Service[$service]
}
}
'/etc/init/gitlab-runner.conf': {
exec {'Ensure Niceness':
command => "sed -i 's/ start-stop-daemon \\(-N [+-]\\?[0-9]\\+ \\)\\?/ start-stop-daemon -N $nice /g' $serviceFile",
user => root,
provider => shell,
path => $path,
require => Exec['Ensure Service'],
onlyif => "! grep 'start-stop-daemon -N $nice ' $serviceFile", #Only if the niceness isn't already set
notify => Service[$service]
}
}
default: {
warning("Niceness not enabled for Service file $serviceFile. Please report this to ${IssuesLink}")
}
}
} else {
fail("Invalid nice value: ${nice}")
}
}
}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frankiethekneeman-gitlab_ci_multi_runner",
"version": "0.1.7",
"version": "0.2.0",
"author": "Francis J.. Van Wetering IV",
"license": "MIT",
"summary": "A Module to Install and register the Gitlab CI Multirunner.",
Expand Down

0 comments on commit af22849

Please sign in to comment.