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

Jenkins restart service doesn't support safe restart #368

Open
v1v opened this issue Sep 4, 2015 · 2 comments
Open

Jenkins restart service doesn't support safe restart #368

v1v opened this issue Sep 4, 2015 · 2 comments
Labels
enhancement New feature or request

Comments

@v1v
Copy link
Contributor

v1v commented Sep 4, 2015

Use case: if any changes then restart jenkins but bear in mind if you restart it might stop/abort those builds which are still running.

Current configuration:

File: manifests/services.pp

  service { 'jenkins':
    ensure     => $jenkins::service_ensure,
    enable     => $jenkins::service_enable,
    hasstatus  => true,
    hasrestart => true,
  }
Suggested configuration:

File: manifests/services.pp

  file { '/var/lib/jenkins/jenkins-safe-restart.sh':
    ensure  => 'file',
    mode    => '0750',
    owner   => 'jenkins',
    group   => 'jenkins',
    content => template("${module_name}/jenkins-safe-restart.erb"),
  }

  service { 'jenkins':
    ensure     => $jenkins::service_ensure,
    enable     => $jenkins::service_enable,
    restart    => '/var/lib/jenkins/jenkins-safe-restart.sh',
    hasstatus  => true,
    hasrestart => true,
    require    => [
      File['/var/lib/jenkins/jenkins-safe-restart.sh'],
      # Package['wget'], #might need this package in order to avoid issues when running jenkins-safe-restart.sh
    ],
  }

File: templates//jenkins-safe-restart.erb

#!/bin/bash
cd /var/lib/jenkins
if [ ! -e jenkins-cli.jar ] ; then
  wget http://localhost:<%= @port %>/jnlpJars/jenkins-cli.jar
fi

java -jar jenkins-cli.jar -s http://localhost:<%= @port %> safe-restart 2> jenkins-safe-restart.stderr
Downsides:

It works as long your Administration security is not in place or you already configured with some granted privileges... or added some cli login setup via -i flag "-i ~jenkins/.ssh/jenkins_id_rsa" or so

In fact: jenkins::cli::safe-restart command might not work if those security layouts are in place AFAIK

Further details: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI (Working with Credentials section).

Let me know your thoughts

Cheers

@v1v v1v added needs-feedback Further information is requested enhancement New feature or request labels Sep 4, 2015
@rtyler rtyler removed the needs-feedback Further information is requested label Sep 9, 2015
@rtyler
Copy link

rtyler commented Sep 9, 2015

@v1v for the record, I use the feedback-needed label when I need feedback from the original submitter of an issue. This got overlooked because I assumed it was waiting for somebody to add more details in :)

Anyways, I think the idea is a reasonable one but the number of ways a process might be configured to prevent CLI access concerns me. We'll need to make the script much more bullet-proof I think to where if it cannot access the Jenkins service for whatever reason it falls back to the raw process kill/restart semantics

@jhoblitt
Copy link
Member

jhoblitt commented Oct 2, 2015

It shouldn't be to difficult to implement a service provider that uses the cli to invoke safe-restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants