mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 18:29:21 +00:00 
			
		
		
		
	Refactor systemctl services and categories due to alarm bugs
This commit restructures systemctl service definitions and category mappings. Motivation: Alarm-related bugs revealed inconsistencies in service and role handling. Preparation step: lays the groundwork for fixing the alarm issues by aligning categories, roles, and service templates.
This commit is contained in:
		
							
								
								
									
										10
									
								
								roles/sys-ctl-hlth-disc-space/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								roles/sys-ctl-hlth-disc-space/README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| # sys-ctl-hlth-disc-space | ||||
|  | ||||
| ## Description | ||||
| Monitors disk-space usage and alerts if any filesystem usage exceeds your defined threshold. | ||||
|  | ||||
| ## Features | ||||
| - Uses `df` to gather current usage. | ||||
| - Compares against `size_percent_disc_space_warning` threshold. | ||||
| - Sends failure alerts via `sys-ctl-alm-compose`. | ||||
| - Runs on a configurable systemd timer. | ||||
| @@ -0,0 +1,15 @@ | ||||
| #!/bin/sh | ||||
| # @param $1 mimimum free disc space | ||||
| errors=0 | ||||
| minimum_percent_cleanup_disc_space="$1" | ||||
| echo "checking disc space use..." | ||||
| df | ||||
| for disc_use_percent in $(df --output=pcent | sed 1d) | ||||
| do | ||||
|     disc_use_percent_number=$(echo "$disc_use_percent" | sed "s/%//") | ||||
|     if [ "$disc_use_percent_number" -gt "$minimum_percent_cleanup_disc_space" ]; then | ||||
|       echo "WARNING: $disc_use_percent_number exceeds the limit of $minimum_percent_cleanup_disc_space%." | ||||
|       errors+=1; | ||||
|     fi | ||||
| done | ||||
| exit $errors; | ||||
							
								
								
									
										5
									
								
								roles/sys-ctl-hlth-disc-space/handlers/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								roles/sys-ctl-hlth-disc-space/handlers/main.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| - name: "reload sys-ctl-hlth-disc-space service" | ||||
|   systemd: | ||||
|     name: sys-ctl-hlth-disc-space{{ SYS_SERVICE_SUFFIX }} | ||||
|     enabled: yes | ||||
|     daemon_reload: yes | ||||
							
								
								
									
										21
									
								
								roles/sys-ctl-hlth-disc-space/meta/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								roles/sys-ctl-hlth-disc-space/meta/main.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| galaxy_info: | ||||
|   author: "Kevin Veen-Birkenbach" | ||||
|   description: "Disk-space usage monitor; alerts when usage exceeds threshold." | ||||
|   company: | | ||||
|     Kevin Veen-Birkenbach   | ||||
|     Consulting & Coaching Solutions   | ||||
|     https://www.veen.world | ||||
|   license: "Infinito.Nexus NonCommercial License" | ||||
|   license_url: "https://s.infinito.nexus/license" | ||||
|   min_ansible_version: "2.9" | ||||
|   platforms: | ||||
|   - name: Archlinux | ||||
|     versions: ["rolling"] | ||||
|   galaxy_tags: | ||||
|   - monitor | ||||
|   - disk | ||||
|   - space | ||||
|   - health | ||||
|   - systemd | ||||
|   repository: "https://s.infinito.nexus/code" | ||||
|   documentation: "https://docs.infinito.nexus" | ||||
							
								
								
									
										34
									
								
								roles/sys-ctl-hlth-disc-space/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								roles/sys-ctl-hlth-disc-space/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| - block: | ||||
|   - name: Include dependency 'sys-ctl-alm-compose' | ||||
|     include_role: | ||||
|       name: sys-ctl-alm-compose | ||||
|     when: run_once_sys_ctl_alm_compose is not defined | ||||
|   - include_tasks: utils/run_once.yml | ||||
|   when: run_once_sys_ctl_hlth_disc_space is not defined | ||||
|  | ||||
| - name: "create {{health_disc_space_folder}}" | ||||
|   file: | ||||
|     path: "{{health_disc_space_folder}}" | ||||
|     state: directory | ||||
|     mode: "0755" | ||||
|  | ||||
| - name: create sys-ctl-hlth-disc-space.sh | ||||
|   copy: | ||||
|     src: sys-ctl-hlth-disc-space.sh | ||||
|     dest: "{{health_disc_space_folder}}sys-ctl-hlth-disc-space.sh" | ||||
|  | ||||
| - name: create sys-ctl-hlth-disc-space{{ SYS_SERVICE_SUFFIX }} | ||||
|   template: | ||||
|     src: sys-ctl-hlth-disc-space.service.j2 | ||||
|     dest: /etc/systemd/system/sys-ctl-hlth-disc-space{{ SYS_SERVICE_SUFFIX }} | ||||
|   notify: reload sys-ctl-hlth-disc-space service | ||||
|  | ||||
| - name: "set 'service_name' to '{{ role_name }}'" | ||||
|   set_fact: | ||||
|     service_name: "{{ role_name }}" | ||||
|  | ||||
| - name: "include role for sys-timer for {{ service_name }}" | ||||
|   include_role: | ||||
|     name: sys-timer | ||||
|   vars: | ||||
|     on_calendar: "{{SYS_SCHEDULE_HEALTH_DISC_SPACE}}" | ||||
| @@ -0,0 +1,7 @@ | ||||
| [Unit] | ||||
| Description=checking disc space | ||||
| OnFailure=sys-ctl-alm-compose.{{ SOFTWARE_NAME }}@%n.service | ||||
|  | ||||
| [Service] | ||||
| Type=oneshot | ||||
| ExecStart=/bin/bash {{health_disc_space_folder}}sys-ctl-hlth-disc-space.sh {{size_percent_disc_space_warning}} | ||||
							
								
								
									
										1
									
								
								roles/sys-ctl-hlth-disc-space/vars/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								roles/sys-ctl-hlth-disc-space/vars/main.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| health_disc_space_folder: '{{ PATH_ADMINISTRATOR_SCRIPTS }}sys-ctl-hlth-disc-space/' | ||||
		Reference in New Issue
	
	Block a user