Skip to content

Commit

Permalink
Fix missing Zabbix agent log dir
Browse files Browse the repository at this point in the history
Logs are stored on a tmpfs to limit writes to storage. Logs are persisted through Graylog anyway. But seems Zabbix agent isn't recreating its log dir if it's missing. This fix ensures the logging directory is created on boot.
  • Loading branch information
JenswBE committed Mar 23, 2024
1 parent 52a4902 commit ec50a5c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ sudo systemctl enable --now sunrise-alarm

# Run Ansible
cd deployment
LC_ALL=C.UTF-8 ansible-galaxy collection install -r requirements.yml
LC_ALL=C.UTF-8 ansible-galaxy collection install --force -r requirements.yml
LC_ALL=C.UTF-8 ansible-playbook main.yml

# Reboot
Expand Down
9 changes: 9 additions & 0 deletions deployment/ensure-var-log-zabbix-exists.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Ensure /var/log/zabbix exists
After=var-log.mount
Requires=var-log.mount

[Service]
Type=oneshot
ExecStartPre=/usr/bin/mkdir -p /var/log/zabbix
ExecStart=/usr/bin/chown zabbix:zabbix /var/log/zabbix
31 changes: 31 additions & 0 deletions deployment/zabbix-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@
name: zabbix-agent2
state: present

- name: Setup ensure-var-log-zabbix-exists.service
register: setup_log_dir
ansible.builtin.copy:
src: ensure-var-log-zabbix-exists.service
dest: /etc/systemd/system/ensure-var-log-zabbix-exists.service
owner: root
group: root
mode: "644"

- name: Setup zabbix-agent2 drop-in folder
ansible.builtin.file:
path: /etc/systemd/system/zabbix-agent2.service.d/
state: directory
owner: root
group: root
mode: "755"

- name: Setup zabbix-agent2 drop-in
register: zabbix_agent2_dropin
ansible.builtin.copy:
src: zabbix-agent2_dropin.service
dest: /etc/systemd/system/zabbix-agent2.service.d/ensure-log-dir-exists.conf
owner: root
group: root
mode: "644"

- name: Reload systemd daemon
when: setup_log_dir.changed or zabbix_agent2_dropin.changed
ansible.builtin.systemd:
daemon_reload: true

- name: Zabbix agent - Update config
register: zabbix_agent_config
ansible.builtin.lineinfile:
Expand Down
3 changes: 3 additions & 0 deletions deployment/zabbix-agent2_dropin.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Unit]
After=ensure-var-log-zabbix-exists.service
Requires=ensure-var-log-zabbix-exists.service

0 comments on commit ec50a5c

Please sign in to comment.