You are not logged in.

#1 2013-07-08 12:46:54

TheSaint
Member
From: my computer
Registered: 2007-08-19
Posts: 1,523

[Solved] SystemD, aria2 as a daemon (not smartly)

Hello,
I started to setup a home server.
I'm studying to solve problem regarding systemD  to start aria2c as a daemon (it's a download manager). This would give a managed way to get files downloaded, avoid overcrowded situation.

I found a script for aria2@ service

[Unit]
Description=aria2 Service
After=network.target

[Service]
Type=forking
User=%i
WorkingDirectory=/home/%i
Environment=VAR=/var/%i
ExecStart=/usr/bin/aria2c --conf-path=/home/%i/.aria2/aria2.conf

[Install]
WantedBy=multi-user.target

If I start like # systemctl start aria2@aria2.service it will report

lug 08 16:00:02 Desktop systemd[1]: Starting aria2 Service...
lug 08 16:00:02 Desktop aria2c[680]: Configuration file /home/aria2/.aria2/aria2.conf is not found.
lug 08 16:00:02 Desktop systemd[1]: aria2.service: control process exited, code=exited status=1
lug 08 16:00:02 Desktop systemd[1]: Failed to start aria2 Service.
lug 08 16:00:02 Desktop systemd[1]: Unit aria2.service entered failed state.

The Configuration file /home/aria2/.aria2/aria2.conf is set as 644.

Maybe I should change the config file position or maybe I should assign the startup to nobody user.

Last edited by TheSaint (2013-07-15 03:06:55)


do it good first, it will be faster than do it twice the saint wink

Offline

#2 2013-07-08 13:02:47

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: [Solved] SystemD, aria2 as a daemon (not smartly)

Are owner and permissions set correctly for all components in the config path?

PS: When you get it working, I know a useful ui: https://github.com/ziahamza/webui-aria2


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#3 2013-07-08 13:08:22

TheSaint
Member
From: my computer
Registered: 2007-08-19
Posts: 1,523

Re: [Solved] SystemD, aria2 as a daemon (not smartly)

I'm already using it. So every family member can paste uri's to that point.


do it good first, it will be faster than do it twice the saint wink

Offline

#4 2013-07-08 20:54:08

Morrad
Member
Registered: 2012-01-18
Posts: 54

Re: [Solved] SystemD, aria2 as a daemon (not smartly)

Double check the permissions of the directories forming the path to the configuration file (/home, /home/aria2, /home/aria2/.aria2) and be sure that the 'aria2' user can navigate them (ie, has read and execute permissions).

Offline

#5 2013-07-09 08:51:45

TheSaint
Member
From: my computer
Registered: 2007-08-19
Posts: 1,523

Re: [Solved] SystemD, aria2 as a daemon (not smartly)

The initial concept I found it at this forum
Then I tried to implement the script, but I'm far away to make it work. Maybe the author should come and explain it.

For what  I made myself, I tried several configurations.
I removed aria2@, I can't imagine what is related to which user, therefore I don't need a daemon for only a particular user.
I check all the possible options regarding permissions, none is good.
Now I'm trying as root user and permissions set to that. still fail.
My suspects are about the command line ExecStart=/usr/bin/aria2c --conf-path=/home/%i/.aria2/aria2.conf. Maybe dashes are not interpreted correctly. I don't kwon how to set debug to higher level, in order to catch the error.
I read some page about systemD, I don't get what is Environment statement used for.
So my point should start aria2 daemon and allow some environment variable to change time to time in case the file destinations need to be changed, without changing the aria2.service file.
I'll try a different approaching method.

EDIT
Partially working as follow:

  • create user and group aria2 (necessary to let aria2 to write its own files)

  • $ sudo /usr/sbin/useradd -d /var/aria2 -m   -g aria2  -s /bin/bash aria2
  • write the service

  • [Unit]
    Description=aria2 Service
    Requires=network.target
    After=network.target
    
    [Service]
    Type=forking
    User=aria2
    Group=aria2
    EnvironmentFile=/etc/conf.d/aria2.conf
    WorkingDirectory=/var/aria2
    ExecStart=/usr/bin/aria2c $ARIACMD
    ExecReload=/usr/bin/kill -HUP $MAINPID
    
    [Install]
    WantedBy=multi-user.target
  • save it in /usr/lib/systemd/system/aria2.service

  • create /etc/conf.d/aria2.conf

    #aria2c command line options
    
    AHOME=/var/aria2
    ARIASESSION=$AHOME/aria2.session
    
    ARIACMD="--enable-rpc -D --rpc-allow-origin-all  --rpc-listen-all \
     --max-overall-download-limit=100k  --max-overall-upload-limit=5k \
     --min-split-size=1M --bt-min-crypto-level=arc4"

Adjust the setting for your own taste, but don't ad options which are mentioning file paths, because otherwise the launching will fail.
Last but not least, using XML-RP Calls, adjust the remaining options. It might be the web user interface as herein mentioned

EDIT2
The other options are probably loaded by adding them in /var/aria2/.aria2/aria2.conf
The obstacle now is that aria2 doesn't start a boot time. I suspect still miss something that is not ready during systemD boot.

Last edited by TheSaint (2013-07-12 18:59:02)


do it good first, it will be faster than do it twice the saint wink

Offline

#6 2013-07-15 03:05:02

TheSaint
Member
From: my computer
Registered: 2007-08-19
Posts: 1,523

Re: [Solved] SystemD, aria2 as a daemon (not smartly)

FINAL
I managed to get the daemons running. It's said daemons here, because also minidlna is on the same boat.

Once assigned a home to aria2 user, as herein mentioned, we need a service script like this:

[Unit]
Description=aria2 Service
Requires=network.target
After=dhcpcd.service

[Service]
Type=forking
User=aria2
Group=aria2
EnvironmentFile=/etc/conf.d/aria2.conf
WorkingDirectory=/var/aria2
ExecStart=/usr/bin/aria2c $ARIACMD
ExecReload=/usr/bin/kill -HUP $MAINPID
RestartSec=1min
Restart=on-failure

[Install]
WantedBy=multi-user.target

NOTE: the statements marked in bold face are those that makes the difference.

In the /etc/conf.d/aria2.conf I've put:

#!/bin/sh

AHOME=/var/aria2
ARIASESSION=$AHOME/aria2.session
ARIACMD="--enable-rpc -D"
EXTRA_ARGS="--max-overall-download-limit=100k  --max-overall-upload-limit=5k \
--rpc-allow-origin-all  --rpc-listen-all --min-split-size=1M \
--bt-min-crypto-level=arc4 --save-session-interval=180"

Those words marked here in bold face aren't used, just for future testing. Then, the last step is to put your liking in /var/aria2/.aria2/aria2.conf the setting statements that aria2 will read once started (see aria2 man page for details)

For minidlna daemon, I modified like this:

[Unit]
Description=minidlna server
After=dhcpcd.service

[Service]
Type=forking
User=nobody
ExecStart=/usr/bin/minidlnad -P /run/minidlna/minidlna.pid
PIDFile=/run/minidlna/minidlna.pid
RestartSec=2min
Restart=on-failure

[Install]
WantedBy=multi-user.target

NOTE: the statements marked in bold face are those that makes the difference.  None about After=dhcpcd.service above. Time maybe adjusted some little, but I don't have a rush to have daemons immediately after startup.


do it good first, it will be faster than do it twice the saint wink

Offline

Board footer

Powered by FluxBB