lib.sls 1.58 KB
Newer Older
Julien Cigar's avatar
Julien Cigar committed
1
2
{% from "runit/map.jinja" import runit with context %}

Julien Cigar's avatar
Julien Cigar committed
3
4
5
6
7
################
# STOP SERVICE #
################

{% macro stop_service(name) -%}
Julien Cigar's avatar
Julien Cigar committed
8
{% set service = runit.service_dir | path_join(name) %}
Julien Cigar's avatar
Julien Cigar committed
9
10
11
12
13
14
15
16
17
18
19
20
{{ name }}_stop_service:
  cmd.run:
    - name: sv down {{ service }}
    - onlyif:
      - test -d {{ service }}
{%- endmacro %}

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

{% macro start_service(name) -%}
Julien Cigar's avatar
Julien Cigar committed
21
{% set service = runit.service_dir | path_join(name) %}
Julien Cigar's avatar
Julien Cigar committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{{ 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) -%}
Julien Cigar's avatar
Julien Cigar committed
40
{% set service = runit.service_dir | path_join(name) %}
Julien Cigar's avatar
Julien Cigar committed
41
42
43
44
45
46
47
48
49
50
51
52
{{ name }}_restart_service:
  cmd.run:
    - name: sv restart {{ service }}
    - onlyif:
      - test -d {{ service }}
{%- endmacro %}

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

{% macro signal_service(name, signal='hup') -%}
Julien Cigar's avatar
Julien Cigar committed
53
{% set service = runit.service_dir | path_join(name) %}
Julien Cigar's avatar
Julien Cigar committed
54
55
56
57
58
59
60
61
62
63
64
65
{{ name }}_signal_service:
  cmd.run:
    - name: sv {{ signal }} {{ service }}
    - onlyif:
      - test -d {{ service }}
{%- endmacro %}

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

{% macro remove_service(name) -%}
Julien Cigar's avatar
Julien Cigar committed
66
{% set service = 'runit.service_dir' | path_join(name) %}
Julien Cigar's avatar
Julien Cigar committed
67
68
69
70
{{ name }}_remove_service:
  file.absent:
    - name: {{ service }}
{%- endmacro %}