Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added variable vic_vm_alert_service_name for vmalert service name #67

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions roles/vmalert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ Installs `vmalert` as binary running with systemd
| vic_vm_alert_service_args | Passes options defined above to `vmalert`. | see [defaults.yml](./defaults/main.yml) |
| vic_vm_alert_service_args | Passes options defined above to `vmalert`. | see [defaults.yml](./defaults/main.yml) |
| vic_vm_alert_rules | Rules | see [defaults.yml](./defaults/main.yml) |
| vic_vm_alert_service_name | Service name that will be created by systemd or init | see [defaults.yml](./defaults/main.yml)
1 change: 1 addition & 0 deletions roles/vmalert/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ vic_vm_alert_version: "v1.102.0"
vic_vm_alert_enterprise: false
vic_vm_alert_license_key: ""
vic_vm_alert_license_key_file: ""
vic_vm_alert_service_name: vic-vmalert

vic_vm_alert_repo_url: "https://github.com/VictoriaMetrics/VictoriaMetrics"
vic_vm_alert_platform: "{% if vic_vm_alert_version.replace('v', '') is version('1.79.0', '>=') %}-linux{% endif %}"
Expand Down
6 changes: 4 additions & 2 deletions roles/vmalert/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# handlers file for VictoriaMetrics
---
- name: Restart VMalert service
- name: "Restart VMalert service {{ vic_vm_alert_service_name }}"
become: true
ansible.builtin.service:
name: vic-vmalert
name: "{{ vic_vm_alert_service_name }}"
state: restarted
ignore_errors: '{{ ansible_check_mode }}'
listen: "Restart VMalert service"
13 changes: 7 additions & 6 deletions roles/vmalert/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- name: "Systemd | Copy VMalert systemd unit file"
ansible.builtin.template:
src: systemd-service.j2
dest: /etc/systemd/system/vic-vmalert.service
dest: "/etc/systemd/system/{{ vic_vm_alert_service_name }}.service"
owner: root
group: root
mode: 0644
Expand All @@ -22,25 +22,26 @@
- name: Ensure VMalert service is enabled on boot
become: true
ansible.builtin.systemd:
name: vic-vmalert
name: "{{ vic_vm_alert_service_name }}"
enabled: true
ignore_errors: '{{ ansible_check_mode }}'

- name: Configure upstart
when: ansible_service_mgr == "upstart"
block:
- name: "Upstart | Install vic-vmalert service file"
- name: "Upstart | Install service file {{ vic_vm_alert_service_name }}"
ansible.builtin.template:
src: "upstart.j2"
dest: "/etc/init.d/vic-vmalert"
dest: "/etc/init.d/{{ vic_vm_alert_service_name }}"
mode: "0755"
owner: root
group: root
notify: Restart VMalert service
register: config_template

- name: "Upstart | Enable vic-vmalert service"
- name: "Upstart | Enable service {{ vic_vm_alert_service_name }}"
ansible.builtin.service:
name: "vic-vmalert"
name: "{{ vic_vm_alert_service_name }}"
enabled: "yes"

- name: Prepare configuration dir
Expand Down
2 changes: 1 addition & 1 deletion roles/vmalert/templates/systemd-service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ User={{ vic_vm_alert_system_user }}
Group={{ vic_vm_alert_system_group }}
ExecStart=/usr/local/bin/vmalert-prod {% for flag, flag_value in vic_vm_alert_service_args.items() %}--{{ flag }}={{ flag_value }} {% endfor %}

SyslogIdentifier=vic-vmalert
SyslogIdentifier={{ vic_vm_alert_service_name }}
Restart=always

PrivateTmp=yes
Expand Down
8 changes: 4 additions & 4 deletions roles/vmalert/templates/upstart.j2
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: vic-vmalert
# Provides: {{ vic_vm_alert_service_name }}
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: vic-vmalert - VictoriaMetrics scrape agent
# Description: vic-vmalert - VictoriaMetrics scrape agent
# Short-Description: {{ vic_vm_alert_service_name }} - VictoriaMetrics scrape agent
# Description: {{ vic_vm_alert_service_name }} - VictoriaMetrics scrape agent
### END INIT INFO


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/VMalert-prod
DAEMON_ARGS="{% for flag, flag_value in vic_vm_alert_service_args.items() %}--{{ flag }}={{ flag_value }} {% endfor %}"
NAME=vic-vmalert
NAME={{ vic_vm_alert_service_name }}
DESC="VictoriaMetrics scrape agent"

test -x $DAEMON || exit 0
Expand Down
Loading