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

A bit of RedHat and Debian slave initd script merging #171

Merged
merged 1 commit into from
Sep 22, 2014
Merged
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
File renamed without changes.
32 changes: 25 additions & 7 deletions templates/jenkins-slave.erb → files/jenkins-slave.RedHat
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
#
RETVAL=0

PID_FILE=/var/run/jenkins-slave.pid
LOCK_FILE=/var/lock/jenkins-slave
NAME=jenkins-slave
JENKINS_CONFIG=/etc/sysconfig/$NAME
LOCK_FILE=/var/lock/$NAME

# Source function library.
. /etc/init.d/functions

# Read config
[ -f "$JENKINS_CONFIG" ] && . "$JENKINS_CONFIG"

if [ -x /sbin/runuser ] ; then
RUNUSER=runuser
Expand All @@ -19,16 +26,27 @@ fi

slave_start() {
echo Starting Jenkins Slave...
$RUNUSER - <%= @slave_user -%> -c 'java -jar <%= @slave_home -%>/<%= @client_jar -%> <%= @ui_user_flag -%> <%= @ui_pass_flag -%> -mode <%= @slave_mode -%> -name <%= @fqdn || @hostname -%> -executors <%= @executors -%> <%= @masterurl_flag -%> <%= @labels_flag -%> <%= @disable_ssl_verification_flag -%> <%= @fsroot_flag -%> &'
pgrep -f -u <%= @slave_user -%> <%= @client_jar -%> > $PID_FILE

# the default location is /var/run/jenkins/jenkins.pid but the parent directory needs to be created
mkdir `dirname $PIDFILE` > /dev/null 2>&1 || true
chown $JENKINS_SLAVE_USER `dirname $PIDFILE`

# create log directory
mkdir -p `dirname $JENKINS_SLAVE_LOG` > /dev/null 2>&1 || true
chown $JENKINS_SLAVE_USER -R `dirname $JENKINS_SLAVE_LOG`

# --user in daemon doesn't prepare environment variables like HOME, USER, LOGNAME or USERNAME,
# so we let su do so for us now
$RUNUSER - $JENKINS_SLAVE_USER -c "$JAVA $JAVA_ARGS -jar $JENKINS_SLAVE_JAR $JENKINS_SLAVE_ARGS &>> $JENKINS_SLAVE_LOG &"
pgrep -f -u $JENKINS_SLAVE_USER $JENKINS_SLAVE_JAR > $PIDFILE
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
}
slave_stop() {
echo Stopping Jenkins Slave...
pid=`cat $PID_FILE`
pid=`cat $PIDFILE`

killproc -p $PID_FILE
killproc -p $PIDFILE

# Wait until the monitor exits
while (checkpid $pid)
Expand All @@ -50,7 +68,7 @@ slave_restart() {
}
slave_status() {
echo Jenkins Slave status:
status -p $PID_FILE
status -p $PIDFILE
RETVAL=$?
}
case "$1" in
Expand Down
85 changes: 22 additions & 63 deletions manifests/slave.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@
}
}

#If disable_ssl_verification is set to true
if $disable_ssl_verification {
#disable SSL verification to the init script
$disable_ssl_verification_flag = '-disableSslVerification'
} else {
$disable_ssl_verification_flag = ''
}

#add jenkins slave user if necessary.
if $manage_slave_user and $slave_uid {
user { 'jenkins-slave_user':
Expand Down Expand Up @@ -126,72 +118,39 @@
## needs to be fixed if you create another version..
}

if $ui_user {
$ui_user_flag = "-username ${ui_user}"
}
else {$ui_user_flag = ''}

if $ui_pass {
$ui_pass_flag = "-password ${ui_pass}"
} else {
$ui_pass_flag = ''
}

if $masterurl {
$masterurl_flag = "-master ${masterurl}"
} else {
$masterurl_flag = ''
}

if $labels {
$labels_flag = "-labels \'${labels}\'"
} else {
$labels_flag = ''
}

if $slave_home {
$fsroot_flag = "-fsroot ${slave_home}"
}

# choose the correct init functions
# customizations based on the OS family
case $::osfamily {
Debian: {
file { '/etc/init.d/jenkins-slave':
ensure => 'file',
mode => '0700',
owner => 'root',
group => 'root',
source => "puppet:///modules/${module_name}/jenkins-slave",
notify => Service['jenkins-slave'],
require => File['/etc/default/jenkins-slave'],
}

file { '/etc/default/jenkins-slave':
ensure => 'file',
mode => '0600',
owner => 'root',
group => 'root',
content => template("${module_name}/jenkins-slave-defaults.${::osfamily}"),
notify => Service['jenkins-slave'],
require => Package['daemon'],
}
$defaults_location = '/etc/default'

package {'daemon':
ensure => present,
before => Service['jenkins-slave'],
}
}
default: {
file { '/etc/init.d/jenkins-slave':
ensure => 'file',
mode => '0700',
owner => 'root',
group => 'root',
content => template("${module_name}/jenkins-slave.erb"),
notify => Service['jenkins-slave'],
}
$defaults_location = '/etc/sysconfig'
}
}

file { '/etc/init.d/jenkins-slave':
ensure => 'file',
mode => '0755',
owner => 'root',
group => 'root',
source => "puppet:///modules/${module_name}/jenkins-slave.${::osfamily}",
notify => Service['jenkins-slave'],
}

file { "${defaults_location}/jenkins-slave":
ensure => 'file',
mode => '0600',
owner => 'root',
group => 'root',
content => template("${module_name}/jenkins-slave-defaults.erb"),
notify => Service['jenkins-slave'],
}

service { 'jenkins-slave':
ensure => running,
enable => $enable,
Expand Down
6 changes: 3 additions & 3 deletions spec/classes/jenkins_slave_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
it { should contain_service('jenkins-slave') }
it { should contain_user('jenkins-slave_user').with_uid(nil) }
# Let the different platform blocks define `slave_runtime_file` separately below
it { should contain_file(slave_runtime_file).with_content(/-fsroot \/home\/jenkins-slave/) }
it { should contain_file(slave_runtime_file).with_content(/^FSROOT="\/home\/jenkins-slave"$/) }

describe 'with ssl verification disabled' do
let(:params) { { :disable_ssl_verification => true } }
Expand All @@ -23,13 +23,13 @@
describe 'with a non-default $slave_home' do
let(:home) { '/home/rspec-runner' }
let(:params) { {:slave_home => home } }
it { should contain_file(slave_runtime_file).with_content(/-fsroot #{home}/) }
it { should contain_file(slave_runtime_file).with_content(/^FSROOT="#{home}"$/) }
end
end

describe 'RedHat' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystem => 'CentOS' } }
let(:slave_runtime_file) { '/etc/init.d/jenkins-slave' }
let(:slave_runtime_file) { '/etc/sysconfig/jenkins-slave' }

it_behaves_like 'a jenkins::slave catalog'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,50 @@ RUN_STANDALONE=true
# log location. this may be a syslog facility.priority
JENKINS_SLAVE_LOG=/var/log/$NAME/$NAME.log

# slave mode, can be either 'normal' (utilize this slave as much as possible)
# or 'exclusive' (leave this machine for tied jobs only).
JENKINS_SLAVE_MODE=<%= @slave_mode -%>

# OS LIMITS SETUP
# comment this out to observe /etc/security/limits.conf
# this is on by default because http://github.com/jenkinsci/jenkins/commit/2fb288474e980d0e7ff9c4a3b768874835a3e92e
# reported that Ubuntu's PAM configuration doesn't include pam_limits.so, and as a result the # of file
# descriptors are forced to 1024 regardless of /etc/security/limits.conf
MAXOPENFILES=8192

MASTER_URL="<%= @masterurl_flag -%> <%= @labels_flag -%>"
MASTER_URL="<%= @masterurl -%>"
LABELS="<%= @labels -%>"

EXECUTORS=<%= @executors -%>

CLIENT_NAME=<%= @fqdn -%>
CLIENT_NAME="<%= @fqdn -%>"

FSROOT="<%= @slave_home -%>"

# credentials
JENKINS_USERNAME="<%= @ui_user -%>"
JENKINS_PASSWORD="<%= @ui_pass -%>"

OTHER_ARGS="<%= '-disableSslVerification' if @disable_ssl_verification -%>"

if [ -n "$JENKINS_USERNAME" ]; then
CREDENTIALS_ARG="-username $JENKINS_USERNAME -password $JENKINS_PASSWORD"
fi

if [ -n "$CLIENT_NAME" ]; then
NAME_ARG="-name $CLIENT_NAME"
fi

if [ -n "$MASTER_URL" ]; then
MASTER_URL_ARG="-master $MASTER_URL"
fi

if [ -n "$LABELS" ]; then
LABELS_ARG="-labels '$LABELS'"
fi

MODE=<%= @slave_mode -%>
if [ -n "$FSROOT" ]; then
FSROOT_ARG="-fsroot '$FSROOT'"
fi

JENKINS_SLAVE_ARGS="<%= @ui_user_flag -%> <%= @ui_pass_flag -%> -name $CLIENT_NAME <%= @disable_ssl_verification_flag -%> -executors $EXECUTORS -mode $MODE $MASTER_URL <%= @fsroot_flag -%>"
JENKINS_SLAVE_ARGS="-mode $JENKINS_SLAVE_MODE -executors $EXECUTORS $CREDENTIALS_ARG $NAME_ARG $MASTER_URL_ARG $LABELS_ARG $FSROOT_ARG $OTHER_ARGS"