Migrate services part
This commit is contained in:
		
							parent
							
								
									7c59e4ae57
								
							
						
					
					
						commit
						73bce8f6e5
					
				
					 157 changed files with 3883 additions and 9 deletions
				
			
		
							
								
								
									
										11
									
								
								roles/backup/templates/backup.service.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								roles/backup/templates/backup.service.j2
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| [Unit] | ||||
| Description=Autostart several tools and services | ||||
| StartLimitIntervalSec=7200 | ||||
| StartLimitBurst=5 | ||||
| 
 | ||||
| [Service] | ||||
| Type=oneshot | ||||
| ExecStart={{ service_path }}/backup.sh | ||||
| WorkingDirectory={{ service_path }} | ||||
| Restart=on-failure | ||||
| RestartSec=15min | ||||
							
								
								
									
										68
									
								
								roles/backup/templates/backup.sh.j2
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										68
									
								
								roles/backup/templates/backup.sh.j2
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,68 @@ | |||
| #!/usr/bin/env bash | ||||
| 
 | ||||
| set -e | ||||
| 
 | ||||
| set -a | ||||
| . "{{ service_path }}/service.env" | ||||
| set +a | ||||
| 
 | ||||
| duration_start=$(date +%s) | ||||
| _duration_get () { | ||||
| 	duration_end=$(date +%s) | ||||
| 	echo "$((duration_end - duration_start))" | ||||
| } | ||||
| 
 | ||||
| hc_url="https://hc-ping.com/$HC_UID" | ||||
| uptime_kuma_url="https://status.serguzim.me/api/push/$UPTIME_KUMA_TOKEN" | ||||
| _hc_ping () { | ||||
| 	curl -fsSL --retry 3 "$hc_url$1" >/dev/null | ||||
| } | ||||
| _uptime_kuma_ping () { | ||||
| 	duration=$(_duration_get) | ||||
| 	curl -fsSL --retry 3 \ | ||||
| 		--url-query "status=$1" \ | ||||
| 		--url-query "msg=$2" \ | ||||
| 		--url-query "ping=${duration}000" \ | ||||
| 		"$uptime_kuma_url" >/dev/null | ||||
| } | ||||
| 
 | ||||
| _fail () { | ||||
| 	_hc_ping "/fail" | ||||
| 	_uptime_kuma_ping "down" "$1" | ||||
| 	rm -rf "$BACKUP_LOCATION" | ||||
| 	exit 1 | ||||
| } | ||||
| _success () { | ||||
| 	_hc_ping | ||||
| 	_uptime_kuma_ping "up" "backup successful" | ||||
| } | ||||
| 
 | ||||
| _hc_ping "/start" | ||||
| 
 | ||||
| BACKUP_LOCATION="$(mktemp -d --suffix=-backup)" | ||||
| export BACKUP_LOCATION | ||||
| cd "$BACKUP_LOCATION" || _fail "failed to cd to $BACKUP_LOCATION" | ||||
| 
 | ||||
| shopt -s nullglob | ||||
| for file in "{{ service_path }}/backup.d/"* | ||||
| do | ||||
| 	file_name="$(basename "$file")" | ||||
| 	echo "" | ||||
| 	echo "running $file_name" | ||||
| 	time "$file" >"/tmp/$file_name.log" || _fail "error while running $file_name" | ||||
| done || true | ||||
| 
 | ||||
| cd "{{ service_path }}" | ||||
| docker compose run --rm -v "$BACKUP_LOCATION:/backup/misc" app backup /backup || _fail "error during restic backup" | ||||
| 
 | ||||
| _success | ||||
| 
 | ||||
| rm -rf "$BACKUP_LOCATION" | ||||
| 
 | ||||
| echo "forgetting old backups for {{ ansible_facts.hostname }}" | ||||
| docker compose run --rm app forget --host "{{ ansible_facts.hostname }}" --prune \ | ||||
| 	--keep-last 7 \ | ||||
| 	--keep-daily 14 \ | ||||
| 	--keep-weekly 16 \ | ||||
| 	--keep-monthly 12 \ | ||||
| 	--keep-yearly 2  | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue