Skip to content

Commit

Permalink
Merge pull request geerlingguy#391 from lookslikematrix/feature/add_j…
Browse files Browse the repository at this point in the history
…enkins_disable_restart

Add `jenkins_restart_method` to allow a `safe restart` to be performed.
  • Loading branch information
geerlingguy authored Sep 24, 2024
2 parents d929709 + a9513f5 commit eba6ee7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ Changes made to the Jenkins systemd override.conf file; the default set of chang

If you are running Jenkins behind a proxy server, configure these options appropriately. Otherwise Jenkins will be configured with a direct Internet connection.

jenkins_restart_method: `service`

You can change `jenkins_restart_method` to `safe-restart`, if you want to make sure all running jobs on the Jenkins server are completed. Otherwise `service` will restart the Jenkins systemd-service.

## Dependencies

None.
Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ jenkins_proxy_noproxy:

jenkins_init_folder: "/etc/systemd/system/jenkins.service.d"
jenkins_init_file: "{{ jenkins_init_folder }}/override.conf"

jenkins_restart_behavior: "service"
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: restart jenkins
service: name=jenkins state=restarted
include_tasks: tasks/restart.yml

- name: configure default users
template:
Expand Down
8 changes: 8 additions & 0 deletions tasks/restart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: restart jenkins via service
service: name=jenkins state=restarted
when: jenkins_restart_behavior == 'service'

- name: safe-restart jenkins via CLI
ansible.builtin.command: java -jar {{ jenkins_jar_location }} -auth {{ jenkins_admin_username }}:{{ jenkins_admin_password }} -s http://{{ jenkins_hostname }}:{{ jenkins_http_port }} safe-restart

Check warning on line 7 in tasks/restart.yml

View workflow job for this annotation

GitHub Actions / Lint

7:151 [line-length] line too long (197 > 150 characters)

Check warning on line 7 in tasks/restart.yml

View workflow job for this annotation

GitHub Actions / Lint

7:151 [line-length] line too long (197 > 150 characters)

Check warning on line 7 in tasks/restart.yml

View workflow job for this annotation

GitHub Actions / Lint

7:151 [line-length] line too long (197 > 150 characters)

Check warning on line 7 in tasks/restart.yml

View workflow job for this annotation

GitHub Actions / Lint

7:151 [line-length] line too long (197 > 150 characters)

Check warning on line 7 in tasks/restart.yml

View workflow job for this annotation

GitHub Actions / Lint

7:151 [line-length] line too long (197 > 150 characters)
when: jenkins_restart_behavior == 'safe-restart'

0 comments on commit eba6ee7

Please sign in to comment.