forked from saltstack-formulas/openvpn-formula
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservice.sls
74 lines (67 loc) · 2.1 KB
/
service.sls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Ensure openvpn service is running and autostart is enabled
{%- from "openvpn/map.jinja" import mapdata as map with context %}
add timestamp to logfile:
file.replace:
- name: /usr/lib/systemd/system/[email protected]
- pattern: ' --suppress-timestamps'
- repl: ''
cmd.run:
- name: systemctl daemon-reload
- shell: /bin/bash
{% if map.multi_services %}
# If the OS is using systemd, then each openvpn config has its own service
# e.g for office.conf -> openvpn@office
{% for type, names in salt['pillar.get']('openvpn', {}).items() %}
{% if type in ['client', 'server', 'peer'] %}
{% for name in names %}
# How to name the service (instance)?
{% if salt['grains.has_value']('systemd') %}
{#-
Some distributions use /etc/openvpn/{client,server} as their working directory
and openvpn-{client,server} as their service.
#}
{% set service_name = map.get(type, {}).get("service", map.service) ~ '@' ~ name %}
{#-
For an successful upgrade we need to make sure the old services are deactivated.
This affects at least Debian.
#}
{% set obsolete_service_name = map.service ~ '@' ~ name %}
{% if obsolete_service_name != service_name %}
obsolete_openvpn_{{ name }}_service:
service.dead:
- name: {{ obsolete_service_name }}
- enable: False
{% endif %}
{% else %}
{% set service_name = map.service ~ '_' ~ name %}
{% endif %}
# Create an init script?
{% if grains['os_family'] == 'FreeBSD' %}
/usr/local/etc/rc.d/openvpn_{{ name }}:
file.symlink:
- target: /usr/local/etc/rc.d/openvpn
{% endif %}
openvpn_{{ name }}_service:
service.{{ map.service_function }}:
- name: {{ service_name }}
- enable: True
- require:
- pkg: openvpn_pkgs
- sls: openvpn.install
{% if grains['os_family'] == 'FreeBSD' %}
- watch:
- file: /usr/local/etc/rc.d/openvpn_{{ name }}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% else %}
# Ensure openvpn service is running and autostart is enabled
openvpn_service:
service.{{ map.service_function }}:
- name: {{ map.service }}
- enable: True
- require:
- pkg: openvpn_pkgs
- sls: openvpn.install
{% endif %}