#!/bin/ash
if ! [ -z $NGINX_LISTEN_SOCKET ]; then
sed -i 's#listen 80#listen unix:/var/run/nginx.sock#' /etc/nginx/conf.d/default.conf
rm -f /var/run/nginx.sock
fi
nginx
ARIA2_URL=http://localhost:6800 su-exec $UID /aria2_exporter &
touch /data/torrents
chown $UID /data/torrents
su-exec $UID aria2c \
--show-console-readout false \
--summary-interval=0 \
--enable-rpc \
--bt-save-metadata \
--bt-load-saved-metadata \
--force-save \
--listen-port=${LISTEN_PORT:-6881-6889} \
--dht-listen-port=${DHT_LISTEN_PORT:-6881-6889} \
--dht-file-path=/data/dht.dat \
--dht-file-path6=/data/dht6.dat \
--max-overall-download-limit=${MAX_OVERALL_DOWNLOAD_LIMIT:-0} \
--max-overall-upload-limit=${MAX_OVERALL_UPLOAD_LIMIT:-0} \
--max-concurrent-downloads 65536 \
--seed-ratio=0 \
--dir /data \
--save-session /data/torrents \
--save-session-interval 900 \
-i /data/torrents