Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Last active February 27, 2025 10:16
Show Gist options
  • Save h0tw1r3/ccf7668552fae5d14148 to your computer and use it in GitHub Desktop.
Save h0tw1r3/ccf7668552fae5d14148 to your computer and use it in GitHub Desktop.
Aria2c systemd service
continue
dir=/var/www/downloads
file-allocation=falloc
max-connection-per-server=4
max-concurrent-downloads=2
max-overall-download-limit=0
min-split-size=25M
rpc-allow-origin-all=true
rpc-secret=YouShouldChangeThis
input-file=/var/tmp/aria2c.session
save-session=/var/tmp/aria2c.session
# Override or Change User and Group per your local environment
[Unit]
Description=Aria2c download manager
After=network.target
[Service]
Type=simple
User=www-data
Group=www-data
ExecStartPre=/usr/bin/env touch /var/tmp/aria2c.session
ExecStart=/usr/bin/aria2c --console-log-level=warn --enable-rpc --rpc-listen-all --conf-path=/etc/aria2.daemon
TimeoutStopSec=20
Restart=on-failure
[Install]
WantedBy=multi-user.target
@minherc
Copy link

minherc commented Jan 29, 2021

it's worked !
)

more to aria2.daemon:

##files
dir=/user/downloads
file-allocation=falloc
continue=true
daemon=true
disk-cache=32M

##logging
log=/user/aria2/aria2.log
console-log-level=warn
log-level=notice

##downloads
max-concurrent-downloads=5
max-connection-per-server=5
min-split-size=20M
split=4
disable-ipv6=true

##sessions
force-save=true
input-file=/user/aria2/ses/aria2.session
save-session=/user/aria2/ses/aria2.session
save-session-interval=10

##security
http-auth-challenge=true
check-certificate=false
enable-rpc=true
rpc-listen-all=true
rpc-secret=*YOUR TOKEN*

#rpc-secure=true	
#rpc-allow-origin-all=true
#rpc-certificate=/user/aria2/cet/aria2.pfx

##ports
rpc-listen-port=6800

##others
summary-interval=120
enable-dht=true

##times
timeout=600
retry-wait=30
max-tries=50
```

@bound-variable
Copy link

Thanks guys.

I couldn't set User=www-data. It wouldn't work with this user, and if I omitted the setting, then all the saved files were owned by root. So I changed this to User={myusername}. There's also no need to run the arguments after the aria2c binary since the daemon can pass those same arguments anyhow (i.e., --console-log-level=warn --enable-rpc --rpc-listen-all). Lastly, the documentation states that file-allocation=falloc is best for newer file systems, e.g., ext4. I think that's what most Linux users have, especially newbies.

@h0tw1r3
Copy link
Author

h0tw1r3 commented Aug 25, 2022

Added to config:

  • rpc-secret (example, you should change!)
  • rpc-allow-origin-all (easy for new users to use a web front-end like AriaNg)
  • input-file and save-session to auto resume downloads on service start
  • changed file-allocation to falloc for performance

Added to unit:

  • ensure session file exists otherwise aria2c will fail to start
  • add Group, note User and Group should be changed per your local environment
  • added restart on failure
  • added stop timeout

@tazihad
Copy link

tazihad commented May 25, 2023

where do I put the .daemon file as user?
I know .service goes to ~/.config/systemd/user/

@h0tw1r3
Copy link
Author

h0tw1r3 commented May 28, 2023

@tazihad if you're going to use it as a user service, change --conf-path in ExecStart to the path where aria2.daemon will be.

@RuofengX
Copy link

@tazihad if you're going to use it as a user service, change --conf-path in ExecStart to the path where aria2.daemon will be.

Systemd User Service cannot contain neither User= or Group= line,
otherwise it could result error like
"aria2.service: Failed to determine supplementary groups: Operation not permitted"

I just google this bug for hours, before realizing that user service cannot use any group (even user itselves' group).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment