2

I want that aria2 starts when the system is booting. I found different init.d scripts but non of them is working for me...

Can you tell me whats wrong with that init.d script?

#!/bin/sh
### BEGIN INIT INFO
# Provides: Aria2
# Required-Start: $network $local_fs $remote_fs
# Required-Stop:: $network $local_fs $remote_fs
# Should-Start: $all
# Should-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Aria2 - Download Manager
### END INIT INFO
NAME=aria2c
ARIA2C=/usr/local/bin/$NAME
PIDFILE=/var/run/$NAME.pid
CONF=/etc/aria2/aria2.conf
ARGS="--conf-path=${CONF} --enable-rpc --rpc-listen-all --daemon"
USER="aria2"
test -f $ARIA2C || exit 0
. /lib/lsb/init-functions

case "$1" in
start) log_daemon_msg "Starting aria2c" "aria2c"
start-stop-daemon --start --quiet -b -m --pidfile $PIDFILE --chuid $USER     --startas $ARIA2C -- $ARGS
log_end_msg $?
;;
stop) log_daemon_msg "Stopping aria2c" "aria2c"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
log_end_msg $?
;;
restart|reload|force-reload)
log_daemon_msg "Restarting aria2c" "aria2c"
start-stop-daemon --stop --retry 5 --quiet --pidfile $PIDFILE
start-stop-daemon --start --quiet -b -m --pidfile $PIDFILE --chuid $USER     --startas $ARIA2C -- $ARGS
log_end_msg $?
;;
status)
status_of_proc -p $PIDFILE $ARIA2C aria2c && exit 0 || exit $?
;;
*) log_action_msg "Usage: /etc/init.d/aria2c     {start|stop|restart|reload|force-reload|status}"
exit 2
;;
esac
exit 0

When I start, it says

[ ok ] Starting aria2c: aria2c.

But when i take a look with

/etc/init.d/aria2c status

it says

[FAIL] aria2c is not running ... failed!

Appreciate your help!

mjx649
  • 81
  • 2
  • 9

2 Answers2

2

Try this:

#!/bin/sh
### BEGIN INIT INFO
# Provides: aria2
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: aria2c init script.
# Description: Starts and stops aria2 daemon.
### END INIT INFO

USER="root"
DAEMON=/usr/bin/aria2c
CONF=/etc/aria2/aria2.conf


start() {
if [ -f $CONF ]; then
logger -st ARIA2C "Starting aria2c daemon..."
nohup start-stop-daemon -S -c $USER -x $DAEMON -- -D --enable-rpc --conf-path=$CONF
else
logger -st ARIA2C "Couldn't start aria2 daemon (no $CONF found)"
fi
}

stop() {
logger -st ARIA2C "Stoping aria2c daemon..."
start-stop-daemon -o -c $USER -K -u $USER -x $DAEMON
}

status() {
dbpid=`pgrep -fu $USER $DAEMON`
if [ -z "$dbpid" ]; then
logger -st ARIA2C "aria2c daemon not running."
else
logger -st ARIA2C "aria2c daemon running..."
fi
}

case "$1" in
start)
start
sleep 1
;;
stop)
stop
sleep 1
;;
restart)
stop
sleep 2
start
;;
status)
status
;;
*)
echo "Usage: {start|stop|restart|status}"
exit 1
esac

exit 0
dawid
  • 31
  • 3
1

You must edit your config file in /etc/aria2/aria2.conf

In this file paste this:

daemon=true
enable-rpc=true
rpc-listen-port=6800
rpc-listen-all=true
####### your download folder, ensure that this folder exist! ##########
dir=/tmp
where is your logfile located
log=/var/log/aria2.log
log-level=warn
dht-listen-port=6801
auto-save-interval=30
#seed ratio and seed time in minutes
seed-ratio=1.0
seed-time=1460
max-upload-limit=20K
event-poll=select

With these files (/etc/init.d/aria2d and /etc/aria2/aria2.conf) aria work, when i run manually -> sudo /etc/init.d/aria2d start

Unfortunately aria don't start automatically when i reboot system.

dawid
  • 31
  • 3
  • See https://askubuntu.com/questions/335242/how-to-install-an-init-d-script for details on how to make an init.d script react to service start/stop/autostart – Quamis Dec 13 '17 at 07:45