Skip to content

Commit

Permalink
✨ Add aria2 (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
anarion80 authored May 31, 2024
1 parent fd08460 commit bda58db
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ If you have a spare domain name you can configure applications to be accessible
* [Affine](https://github.com/toeverything/AFFiNE) - a next-gen knowledge base that brings planning, sorting and creating all together
* [Airsonic](https://airsonic.github.io/) - catalog and stream music
* [Appsmith](https://www.appsmith.com/) - low-code application platform to quickly build, deploy, and manage effective software
* [Aria2](https://github.com/aria2/aria2) - a lightweight multi-protocol & multi-source, cross platform download utility operated in command-line
* [Authelia](https://www.authelia.com/) - The Single Sign-On Multi-Factor portal for web apps
* [Authentik](https://goauthentik.io/) - an open-source Identity Provider focused on flexibility and versatility
* [Barcode Buddy](https://github.com/Forceu/barcodebuddy/) - Barcode system for Grocy
Expand Down
4 changes: 4 additions & 0 deletions nas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
tags:
- appsmith

- role: aria2
tags:
- aria2

- role: authelia
tags:
- authelia
Expand Down
36 changes: 36 additions & 0 deletions roles/aria2/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
aria2_enabled: false
aria2_available_externally: false

# directories
aria2_data_directory: "{{ docker_home }}/aria2"
aria2_download_directory: "{{ downloads_root }}"

# network
aria2_port: "6800"
aria2_listen_port: "6888"
aria2_ui_port: "6880"
aria2_hostname: "aria2"
aria2_network_name: "aria2"

# specs
aria2_memory: 1g
aria2_ui_memory: 1g

# docker
aria2_container_name: aria2
aria2_image_name: "p3terx/aria2-pro"
aria2_image_version: latest
aria2_ui_container_name: aria2-ui
aria2_ui_image_name: "p3terx/ariang"
aria2_ui_image_version: latest

# aria2
aria2_user_id: "65534"
aria2_group_id: "65534"
aria2_umask: "022"
aria2_secret: "P3TERX"
aria2_disk_cache: "64M"
aria2_ipv6_mode: "false"
aria2_update_trackers: "true"
aria2_custom_tracker_url: ""
11 changes: 11 additions & 0 deletions roles/aria2/docs/aria2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# aria2

Homepage: [https://github.com/aria2/aria2](https://github.com/aria2/aria2)

aria2 is a lightweight multi-protocol & multi-source, cross platform download utility operated in command-line. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink.

## Usage

Set `aria2_enabled: true` in your `inventories/<your_inventory>/group_vars/nas.yml` file.

aria2 web interface can be found at [http://ansible_nas_host_or_ip:6880](http://ansible_nas_host_or_ip:6880).
6 changes: 6 additions & 0 deletions roles/aria2/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
provisioner:
inventory:
group_vars:
all:
aria2_enabled: true
10 changes: 10 additions & 0 deletions roles/aria2/molecule/default/side_effect.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Stop
hosts: all
become: true
tasks:
- name: "Include {{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }} role"
ansible.builtin.include_role:
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
vars:
aria2_enabled: false
26 changes: 26 additions & 0 deletions roles/aria2/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Include vars
ansible.builtin.include_vars:
file: ../../defaults/main.yml

- name: Get aria2 container state
community.docker.docker_container:
name: "{{ aria2_container_name }}"
register: result

- name: Get aria2 ui container state
community.docker.docker_container:
name: "{{ aria2_ui_container_name }}"
register: result_ui

- name: Check if aria2 containers are running
ansible.builtin.assert:
that:
- result.container['State']['Status'] == "running"
- result.container['State']['Restarting'] == false
- result_ui.container['State']['Status'] == "running"
- result_ui.container['State']['Restarting'] == false
26 changes: 26 additions & 0 deletions roles/aria2/molecule/default/verify_stopped.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Include vars
ansible.builtin.include_vars:
file: ../../defaults/main.yml

- name: Try and stop and remove aria2
community.docker.docker_container:
name: "{{ aria2_container_name }}"
state: absent
register: result

- name: Try and stop and remove aria2 ui
community.docker.docker_container:
name: "{{ aria2_ui_container_name }}"
state: absent
register: result_ui

- name: Check if aria2 is stopped
ansible.builtin.assert:
that:
- not result.changed
- not result_ui.changed
1 change: 1 addition & 0 deletions roles/aria2/requirements.yml
86 changes: 86 additions & 0 deletions roles/aria2/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
- name: Start aria2
block:
- name: Create aria2 Directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ aria2_user_id }}"
group: "{{ aria2_group_id }}"
with_items:
- "{{ aria2_data_directory }}"

- name: Create aria2 network
community.docker.docker_network:
name: "{{ aria2_network_name }}"

- name: Create aria2 Docker Container
community.docker.docker_container:
name: "{{ aria2_container_name }}"
image: "{{ aria2_image_name }}:{{ aria2_image_version }}"
pull: true
ports:
- "{{ aria2_port }}:6800"
- "{{ aria2_listen_port }}:6888"
volumes:
- "{{ aria2_data_directory }}/config:/config"
- "{{ aria2_download_directory }}:/downloads"
networks:
- name: "{{ aria2_network_name }}"
network_mode: "{{ aria2_network_name }}"
container_default_behavior: no_defaults
env:
PUID: "{{ aria2_user_id }}"
PGID: "{{ aria2_group_id }}"
UMASK_SET: "{{ aria2_umask }}"
RPC_SECRET: "{{ aria2_secret }}"
RPC_PORT: "{{ aria2_port }}"
LISTEN_PORT: "{{ aria2_listen_port }}"
DISK_CACHE: "{{ aria2_disk_cache }}"
IPV6_MODE: "{{ aria2_ipv6_mode }}"
UPDATE_TRACKERS: "{{ aria2_update_trackers }}"
CUSTOM_TRACKER_URL: "{{ aria2_custom_tracker_url }}"
TZ: "{{ ansible_nas_timezone }}"
labels:
traefik.enable: "false"
log_driver: json-file
log_options:
max-size: 1m
restart_policy: always
memory: "{{ aria2_memory }}"

- name: Create aria2 UI Docker Container
community.docker.docker_container:
name: "{{ aria2_ui_container_name }}"
image: "{{ aria2_ui_image_name }}:{{ aria2_ui_image_version }}"
pull: true
ports:
- "{{ aria2_ui_port }}:6880"
networks:
- name: "{{ aria2_network_name }}"
network_mode: "{{ aria2_network_name }}"
container_default_behavior: no_defaults
command: --port 6880 --ipv6
labels:
traefik.enable: "{{ aria2_available_externally | string }}"
traefik.http.routers.aria2.rule: "Host(`{{ aria2_hostname }}.{{ ansible_nas_domain }}`)"
traefik.http.routers.aria2.tls.certresolver: "letsencrypt"
traefik.http.routers.aria2.tls.domains[0].main: "{{ ansible_nas_domain }}"
traefik.http.routers.aria2.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
traefik.http.services.aria2.loadbalancer.server.port: "6880"
restart_policy: always
memory: "{{ aria2_ui_memory }}"
when: aria2_enabled is true

- name: Stop aria2
block:
- name: Stop aria2
community.docker.docker_container:
name: "{{ aria2_redis_container_name }}"
state: absent

- name: Stop aria2 ui
community.docker.docker_container:
name: "{{ aria2_db_container_name }}"
state: absent
when: aria2_enabled is false
14 changes: 14 additions & 0 deletions website/docs/applications/download-tools/aria2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "aria2"
description: "A lightweight multi-protocol & multi-source, cross platform download utility operated in command-line"
---

Homepage: [https://github.com/aria2/aria2](https://github.com/aria2/aria2)

aria2 is a lightweight multi-protocol & multi-source, cross platform download utility operated in command-line. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink.

## Usage

Set `aria2_enabled: true` in your `inventories/<your_inventory>/group_vars/nas.yml` file.

aria2 web interface can be found at [http://ansible_nas_host_or_ip:6880](http://ansible_nas_host_or_ip:6880).

0 comments on commit bda58db

Please sign in to comment.