Skip to content
This repository was archived by the owner on May 31, 2023. It is now read-only.

Commit a35c492

Browse files
RichardHeelinpaulfantom
authored andcommitted
Add support for running in socket mode (#161)
* Added support for running the server in socket mode Check for the presence of the socket when the server is in socket mode * Manage the socket directory permissions Ensure that grafana can write to the directory the socket is in * Ensure newline at end of file * Fixed typo
1 parent 94ccf8b commit a35c492

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

tasks/configure.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@
4747
- "{{ grafana_data_dir }}/dashboards"
4848
- "{{ grafana_data_dir }}/plugins"
4949

50+
- block:
51+
- name: Create grafana socket directory
52+
file:
53+
path: "{{ grafana_server.socket | dirname }}"
54+
state: directory
55+
mode: 0775
56+
owner: "grafana"
57+
group: "grafana"
58+
59+
- name: Ensure grafana socket directory created on startup
60+
template:
61+
src: tmpfiles.j2
62+
dest: /etc/tmpfiles.d/grafana.conf
63+
owner: root
64+
group: root
65+
mode: 0644
66+
when:
67+
- grafana_server.protocol is defined and grafana_server.protocol == 'socket'
68+
- grafana_server.socket | dirname != '/var/run'
69+
5070
- name: Enable grafana to ports lower than port 1024
5171
capabilities:
5272
path: /usr/sbin/grafana-server

tasks/main.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,23 @@
4747
- grafana_dashboards
4848
- grafana_run
4949

50-
- name: Wait for grafana to start
50+
- name: Wait for grafana to start (http/s)
5151
wait_for:
5252
host: "{{ grafana_address }}"
5353
port: "{{ grafana_port }}"
54+
when: grafana_server.protocol is undefined or grafana_server.protocol in ['http', 'https']
55+
tags:
56+
- grafana_install
57+
- grafana_configure
58+
- grafana_datasources
59+
- grafana_notifications
60+
- grafana_dashboards
61+
- grafana_run
62+
63+
- name: Wait for grafana to start (socket)
64+
wait_for:
65+
path: "{{ grafana_server.socket }}"
66+
when: grafana_server.protocol is defined and grafana_server.protocol == 'socket'
5467
tags:
5568
- grafana_install
5669
- grafana_configure

tasks/preflight.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,10 @@
8383
when:
8484
- grafana_port <= 1024
8585
- not grafana_cap_net_bind_service
86+
87+
- name: Fail if grafana_server.socket not defined when in socket mode
88+
fail:
89+
msg: "You need to configure grafana_server.socket when grafana_server.protocol is set to 'socket'"
90+
when:
91+
- grafana_server.protocol is defined and grafana_server.protocol == 'socket'
92+
- grafana_server.socket is undefined or grafana_server.socket == ''

templates/grafana.ini.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ plugins = {{ grafana_data_dir }}/plugins
1515

1616
# HTTP options
1717
[server]
18+
{% if grafana_server.protocol is undefined or grafana_server.protocol in ['http', 'https'] %}
1819
http_addr = {{ grafana_address }}
1920
http_port = {{ grafana_port }}
21+
{% endif %}
2022
domain = {{ grafana_domain }}
2123
root_url = {{ grafana_url }}
2224
{% for k,v in grafana_server.items() %}

templates/tmpfiles.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ ansible_managed | comment }}
2+
d {{ grafana_server.socket | dirname }} 0775 grafana grafana

0 commit comments

Comments
 (0)