Merge "Make collectd run as root inside the container"
[apex-tripleo-heat-templates.git] / docker / services / sensu-client.yaml
1 heat_template_version: pike
2
3 description: >
4   Containerized Sensu client service
5
6 parameters:
7   DockerSensuClientImage:
8     description: image
9     type: string
10   DockerSensuConfigImage:
11     description: The container image to use for the sensu config_volume
12     type: string
13   EndpointMap:
14     default: {}
15     description: Mapping of service endpoint -> protocol. Typically set
16                  via parameter_defaults in the resource registry.
17     type: json
18   ServiceData:
19     default: {}
20     description: Dictionary packing service data
21     type: json
22   ServiceNetMap:
23     default: {}
24     description: Mapping of service_name -> network name. Typically set
25                  via parameter_defaults in the resource registry.  This
26                  mapping overrides those in ServiceNetMapDefaults.
27     type: json
28   DefaultPasswords:
29     default: {}
30     type: json
31   RoleName:
32     default: ''
33     description: Role name on which the service is applied
34     type: string
35   RoleParameters:
36     default: {}
37     description: Parameters specific to the role
38     type: json
39   SensuDockerCheckCommand:
40     type: string
41     default: |
42       for i in $(docker ps --format '{{.ID}}'); do
43         if result=$(docker inspect --format='{{.State.Health.Status}}' $i 2>/dev/null); then
44           if [ "$result" != 'healthy' ]; then
45             echo "$(docker inspect --format='{{.Name}}' $i) ($i): $(docker inspect --format='{{json .State}}' $i)" && exit 2;
46           fi
47         fi
48       done
49   SensuDockerCheckInterval:
50     type: number
51     description: The frequency in seconds the docker health check is executed.
52     default: 10
53   SensuDockerCheckHandlers:
54     default: []
55     description: The Sensu event handler to use for events
56                  created by the docker health check.
57     type: comma_delimited_list
58   SensuDockerCheckOccurrences:
59     type: number
60     description: The number of event occurrences before sensu-plugin-aware handler should take action.
61     default: 3
62   SensuDockerCheckRefresh:
63     type: number
64     description: The number of seconds sensu-plugin-aware handlers should wait before taking second action.
65     default: 90
66
67 resources:
68
69   ContainersCommon:
70     type: ./containers-common.yaml
71
72   SensuClientBase:
73     type: ../../puppet/services/monitoring/sensu-client.yaml
74     properties:
75       EndpointMap: {get_param: EndpointMap}
76       ServiceData: {get_param: ServiceData}
77       ServiceNetMap: {get_param: ServiceNetMap}
78       DefaultPasswords: {get_param: DefaultPasswords}
79
80 outputs:
81   role_data:
82     description: Role data for the Sensu client role.
83     value:
84       service_name: {get_attr: [SensuClientBase, role_data, service_name]}
85       config_settings:
86         map_merge:
87           - get_attr: [SensuClientBase, role_data, config_settings]
88           - sensu::checks:
89               check-docker-health:
90                 standalone: true
91                 command: {get_param: SensuDockerCheckCommand}
92                 interval: {get_param: SensuDockerCheckInterval}
93                 handlers: {get_param: SensuDockerCheckHandlers}
94                 occurrences: {get_param: SensuDockerCheckOccurrences}
95                 refresh: {get_param: SensuDockerCheckRefresh}
96       step_config: &step_config
97         get_attr: [SensuClientBase, role_data, step_config]
98       service_config_settings: {get_attr: [SensuClientBase, role_data, service_config_settings]}
99       # BEGIN DOCKER SETTINGS
100       puppet_config:
101         config_volume: sensu
102         puppet_tags:  sensu_rabbitmq_config,sensu_client_config,sensu_check_config,sensu_check
103         step_config: *step_config
104         config_image: {get_param: DockerSensuConfigImage}
105       kolla_config:
106         /var/lib/kolla/config_files/sensu-client.json:
107           command: /usr/bin/sensu-client -d /etc/sensu/conf.d/ -l /var/log/sensu/sensu-client.log
108           config_files:
109             - source: "/var/lib/kolla/config_files/src/*"
110               dest: "/"
111               merge: true
112               preserve_properties: true
113           permissions:
114             - path: /var/log/sensu
115               owner: sensu:sensu
116               recurse: true
117       docker_config:
118         step_3:
119           sensu_client:
120             image: {get_param: DockerSensuClientImage}
121             net: host
122             privileged: true
123             # NOTE(mmagr) kolla image changes the user to 'sensu', we need it
124             # to be root have rw permission to docker.sock to run successfully
125             # "docker inspect" command
126             user: root
127             restart: always
128             volumes:
129               list_concat:
130                 - {get_attr: [ContainersCommon, volumes]}
131                 -
132                   - /var/run/docker.sock:/var/run/docker.sock:rw
133                   - /var/lib/kolla/config_files/sensu-client.json:/var/lib/kolla/config_files/config.json:ro
134                   - /var/lib/config-data/puppet-generated/sensu/:/var/lib/kolla/config_files/src:ro
135                   - /var/log/containers/sensu:/var/log/sensu:rw
136             environment:
137               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
138       host_prep_tasks:
139         - name: create persistent logs directory
140           file:
141             path: /var/log/containers/sensu
142             state: directory
143       upgrade_tasks:
144         - name: Stop and disable sensu-client service
145           tags: step2
146           service: name=sensu-client.service state=stopped enabled=no