lib.sls 1.51 KB
Newer Older
Julien Cigar's avatar
Julien Cigar committed
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
################
# STOP SERVICE #
################

{% macro stop_service(name) -%}
{% set service = '/var/service' | path_join(name) %}
{{ name }}_stop_service:
  cmd.run:
    - name: sv down {{ service }}
    - onlyif:
      - test -d {{ service }}
{%- endmacro %}

#################
# START SERVICE #
#################

{% macro start_service(name) -%}
{% set service = '/var/service' | path_join(name) %}
{{ name }}_start_service:
  file.managed:
    - name: {{ service | path_join('run') }}
    - mode: 754
  cmd.run:
    - name: sv up {{ service }}
    - onlyif:
      - test -d {{ service }}
      - test -p {{ service | path_join('supervise', 'ok') }}
    - require:
      - file: {{ name }}_start_service
{%- endmacro %}

###################
# RESTART SERVICE #
###################

{% macro restart_service(name) -%}
{% set service = '/var/service' | path_join(name) %}
{{ name }}_restart_service:
  cmd.run:
    - name: sv restart {{ service }}
    - onlyif:
      - test -d {{ service }}
{%- endmacro %}

##################
# SIGNAL SERVICE #
##################

{% macro signal_service(name, signal='hup') -%}
{% set service = '/var/service' | path_join(name) %}
{{ name }}_signal_service:
  cmd.run:
    - name: sv {{ signal }} {{ service }}
    - onlyif:
      - test -d {{ service }}
{%- endmacro %}

##################
# REMOVE SERVICE #
##################

{% macro remove_service(name) -%}
{% set service = '/var/service' | path_join(name) %}
{{ name }}_remove_service:
  file.absent:
    - name: {{ service }}
{%- endmacro %}