Skip to content

Commit 5710d69

Browse files
author
Olivier Locard
authored
Merge pull request #20 from olo-dw/Add_SystemD
Add systemD
2 parents de9c771 + 998860d commit 5710d69

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

tasks/install.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
package:
1717
name: "{{ haproxy_extra_packages }}"
1818

19-
- name: 'Enable it'
20-
service:
21-
name: haproxy
22-
enabled: yes
23-
2419
- name: 'Ensure chroot directory exists'
2520
file:
2621
name: "{{ haproxy_global.chroot }}"

tasks/install/Debian.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
---
2-
- name: Add haproxy apt repo (jessie)
2+
- name: Debian - Ensure haproxy apt repo is added.
33
apt_repository:
44
repo: "deb http://http.debian.net/debian {{ ansible_distribution_release }} main"
55
state: present
66
update_cache: yes
7-
when: ansible_distribution_release == 'jessie'
87

9-
- name: Install HAProxy (jessie)
8+
- name: Debian - Ensure HAProxy is installed.
109
apt:
1110
name: "{{ haproxy_package_name }}"
1211
default_release: "{{ ansible_distribution_release }}"
13-
when: ansible_distribution_release == 'jessie'

tasks/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
- include: install.yml
33

4+
- include: systemd.yml
5+
when: ansible_service_mgr == "systemd"
6+
7+
- include: service.yml
8+
49
- include: configure.yml
510
when: haproxy_manage_config

tasks/service.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: Service - Ensure service is enabled.
3+
service:
4+
name: haproxy
5+
enabled: yes

tasks/systemd.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
- name: Systemd - Ensure service script is present.
3+
become: true
4+
template:
5+
src: "haproxy.systemd.j2"
6+
dest: "/lib/systemd/system/haproxy.service"
7+
owner: root
8+
group: root
9+
mode: 0755
10+
register: systemd_service_file
11+
notify: restart haproxy
12+
13+
- name: Systemd - Ensure service is linked into /etc/systemd.
14+
file:
15+
src: "/lib/systemd/system/haproxy.service"
16+
dest: "/etc/systemd/system/multi-user.target.wants/haproxy.service"
17+
state: link
18+
19+
#
20+
# Keep systemd-specific bits here instead of pushing a global handler.
21+
#
22+
- name: Systemd - Ensure systemd daemon is reloaded.
23+
systemd:
24+
daemon_reload: yes
25+
when: systemd_service_file.changed

templates/haproxy.systemd.j2

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
Description=HAProxy Load Balancer
3+
Documentation=man:haproxy(1)
4+
Documentation=file:/usr/share/doc/haproxy/configuration.txt.gz
5+
After=network.target syslog.service
6+
Wants=syslog.service
7+
8+
[Service]
9+
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid"
10+
EnvironmentFile=-/etc/default/haproxy
11+
ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
12+
ExecStart=/usr/sbin/haproxy-systemd-wrapper -f $CONFIG -p $PIDFILE $EXTRAOPTS
13+
ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
14+
ExecReload=/bin/kill -USR2 $MAINPID
15+
KillMode=mixed
16+
Restart=always
17+
18+
[Install]
19+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)