autoface commited on
Commit
5934ab9
·
1 Parent(s): 0ded981

Adding aria2 profile templates and associated startup and installation scripts

Browse files

- Added aria2 profile template with basic options, RPC options, download options, and more.
- Added prepare-aria2-config.sh script for preparing and generating aria2 configuration.
- A new start-aria2.sh script has been added to start the aria2 service and check port availability.
- A new aria2-install.sh script has been added to install aria2 and its dependencies, and to download the AriaNg Web UI.
- All scripts include logging for debugging and monitoring service status.

configs/aria2.conf.template ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # aria2 配置文件模板
2
+ # 基础选项
3
+ dir=${ARIA2_DOWNLOAD_DIR:-/home/user/downloads}
4
+ input-file=${ARIA2_SESSION_FILE:-/home/user/config/aria2.session}
5
+ save-session=${ARIA2_SESSION_FILE:-/home/user/config/aria2.session}
6
+ save-session-interval=60
7
+ force-save=true
8
+ log=${ARIA2_LOG_FILE:-/home/user/logs/aria2.log}
9
+ log-level=info
10
+
11
+ # RPC 选项
12
+ enable-rpc=true
13
+ rpc-listen-all=true
14
+ rpc-listen-port=${ARIA2_PORT:-6800}
15
+ rpc-secret=${ARIA2_SECRET:-aria2}
16
+ rpc-allow-origin-all=true
17
+
18
+ # 下载选项
19
+ max-concurrent-downloads=${ARIA2_MAX_CONCURRENT:-5}
20
+ max-connection-per-server=${ARIA2_MAX_CONN_PER_SERVER:-16}
21
+ split=${ARIA2_SPLIT:-16}
22
+ min-split-size=1M
23
+ continue=true
24
+ max-overall-download-limit=${ARIA2_MAX_OVERALL_DOWNLOAD_LIMIT:-0}
25
+ max-download-limit=${ARIA2_MAX_DOWNLOAD_LIMIT:-0}
26
+ max-overall-upload-limit=${ARIA2_MAX_OVERALL_UPLOAD_LIMIT:-0}
27
+ max-upload-limit=${ARIA2_MAX_UPLOAD_LIMIT:-0}
28
+
29
+ # HTTP/HTTPS/FTP 选项
30
+ connect-timeout=60
31
+ timeout=60
32
+ max-tries=5
33
+ retry-wait=0
34
+ user-agent=aria2/${ARIA2_VERSION}
35
+
36
+ # BitTorrent 选项
37
+ bt-enable-lpd=true
38
+ bt-lpd-interface=0.0.0.0
39
+ follow-torrent=true
40
+ bt-max-open-files=16
41
+ bt-max-peers=${ARIA2_BT_MAX_PEERS:-55}
42
+ bt-request-peer-speed-limit=50K
43
+ bt-stop-timeout=0
44
+ bt-tracker-connect-timeout=10
45
+ bt-tracker-timeout=10
46
+ seed-time=0
47
+ max-upload-limit=100K
48
+
49
+ # DHT 相关选项
50
+ enable-dht=true
51
+ enable-peer-exchange=true
52
+
53
+ # Metalink 选项
54
+ follow-metalink=true
55
+ metalink-preferred-protocol=https
56
+
57
+ # 高级选项
58
+ disable-ipv6=false
59
+ disk-cache=${ARIA2_DISK_CACHE:-64M}
60
+ file-allocation=prealloc
61
+ no-file-allocation-limit=32M
62
+
63
+ # 错误处理
64
+ max-file-not-found=0
65
+ max-tries=5
66
+
67
+ # 其他选项
68
+ check-integrity=true
69
+ realtime-chunk-checksum=true
configs/prepare-aria2-config.sh.template ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ # Function for logging
6
+ log() {
7
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] [ARIA2-CONFIG] $*"
8
+ }
9
+
10
+ log "Preparing aria2 configuration..."
11
+
12
+ # Set default values
13
+ ARIA2_PORT="${ARIA2_PORT:-6800}"
14
+ ARIA2_SECRET="${ARIA2_SECRET:-$(openssl rand -base64 32)}"
15
+ ARIA2_DOWNLOAD_DIR="${ARIA2_DOWNLOAD_DIR:-/home/user/downloads}"
16
+ ARIA2_SESSION_FILE="${ARIA2_SESSION_FILE:-/home/user/config/aria2.session}"
17
+ ARIA2_LOG_FILE="${ARIA2_LOG_FILE:-/home/user/logs/aria2.log}"
18
+ ARIA2_MAX_CONCURRENT="${ARIA2_MAX_CONCURRENT:-5}"
19
+ ARIA2_MAX_CONN_PER_SERVER="${ARIA2_MAX_CONN_PER_SERVER:-16}"
20
+ ARIA2_SPLIT="${ARIA2_SPLIT:-16}"
21
+ ARIA2_DISK_CACHE="${ARIA2_DISK_CACHE:-64M}"
22
+ ARIA2_BT_MAX_PEERS="${ARIA2_BT_MAX_PEERS:-55}"
23
+
24
+ # Export variables for envsubst
25
+ export ARIA2_PORT ARIA2_SECRET ARIA2_DOWNLOAD_DIR ARIA2_SESSION_FILE ARIA2_LOG_FILE
26
+ export ARIA2_MAX_CONCURRENT ARIA2_MAX_CONN_PER_SERVER ARIA2_SPLIT ARIA2_DISK_CACHE ARIA2_BT_MAX_PEERS
27
+ export ARIA2_MAX_OVERALL_DOWNLOAD_LIMIT="${ARIA2_MAX_OVERALL_DOWNLOAD_LIMIT:-0}"
28
+ export ARIA2_MAX_DOWNLOAD_LIMIT="${ARIA2_MAX_DOWNLOAD_LIMIT:-0}"
29
+ export ARIA2_MAX_OVERALL_UPLOAD_LIMIT="${ARIA2_MAX_OVERALL_UPLOAD_LIMIT:-0}"
30
+ export ARIA2_MAX_UPLOAD_LIMIT="${ARIA2_MAX_UPLOAD_LIMIT:-0}"
31
+ export ARIA2_VERSION="$(aria2c --version 2>/dev/null | head -1 | awk '{print $3}' || echo '1.36.0')"
32
+
33
+ # Create required directories
34
+ log "Creating required directories..."
35
+ mkdir -p "$(dirname "$ARIA2_SESSION_FILE")" \
36
+ "$(dirname "$ARIA2_LOG_FILE")" \
37
+ "$ARIA2_DOWNLOAD_DIR"
38
+
39
+ # Create session file if it doesn't exist
40
+ touch "$ARIA2_SESSION_FILE"
41
+
42
+ # Process configuration template
43
+ log "Generating aria2.conf from template..."
44
+ if [ -f "/home/user/config/aria2.conf.template" ]; then
45
+ envsubst < /home/user/config/aria2.conf.template > /home/user/config/aria2.conf
46
+ log "Configuration generated: /home/user/config/aria2.conf"
47
+ else
48
+ log "Template not found, creating basic configuration..."
49
+ cat > /home/user/config/aria2.conf << EOF
50
+ # aria2 基础配置
51
+ dir=$ARIA2_DOWNLOAD_DIR
52
+ input-file=$ARIA2_SESSION_FILE
53
+ save-session=$ARIA2_SESSION_FILE
54
+ save-session-interval=60
55
+ force-save=true
56
+ log=$ARIA2_LOG_FILE
57
+ log-level=info
58
+
59
+ # RPC 选项
60
+ enable-rpc=true
61
+ rpc-listen-all=true
62
+ rpc-listen-port=$ARIA2_PORT
63
+ rpc-secret=$ARIA2_SECRET
64
+ rpc-allow-origin-all=true
65
+
66
+ # 下载选项
67
+ max-concurrent-downloads=$ARIA2_MAX_CONCURRENT
68
+ max-connection-per-server=$ARIA2_MAX_CONN_PER_SERVER
69
+ split=$ARIA2_SPLIT
70
+ min-split-size=1M
71
+ continue=true
72
+
73
+ # 高级选项
74
+ disk-cache=$ARIA2_DISK_CACHE
75
+ file-allocation=prealloc
76
+ EOF
77
+ fi
78
+
79
+ # Set proper permissions
80
+ chmod 644 /home/user/config/aria2.conf
81
+ chmod 600 "$ARIA2_SESSION_FILE"
82
+
83
+ log "aria2 configuration prepared successfully"
84
+ log "RPC Port: $ARIA2_PORT"
85
+ log "RPC Secret: ${ARIA2_SECRET:0:8}..."
86
+ log "Download Directory: $ARIA2_DOWNLOAD_DIR"
configs/start-aria2.sh.template ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ # Function for logging
6
+ log() {
7
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] [ARIA2-START] $*"
8
+ }
9
+
10
+ # Function to check if port is available
11
+ check_port() {
12
+ local port=$1
13
+ if nc -z localhost "$port" 2>/dev/null; then
14
+ return 1 # Port is in use
15
+ else
16
+ return 0 # Port is available
17
+ fi
18
+ }
19
+
20
+ # Function to wait for aria2 to start
21
+ wait_for_aria2() {
22
+ local port=$1
23
+ local max_attempts=30
24
+ local attempt=1
25
+
26
+ log "Waiting for aria2 to start on port $port..."
27
+
28
+ while [ $attempt -le $max_attempts ]; do
29
+ if nc -z localhost "$port" 2>/dev/null; then
30
+ log "aria2 is running on port $port"
31
+ return 0
32
+ fi
33
+
34
+ sleep 1
35
+ attempt=$((attempt + 1))
36
+ done
37
+
38
+ log "ERROR: aria2 failed to start after $max_attempts seconds"
39
+ return 1
40
+ }
41
+
42
+ log "Starting aria2 service..."
43
+
44
+ # Prepare configuration using the config script
45
+ if [ -f "/home/user/config/prepare-aria2-config.sh" ]; then
46
+ log "Running configuration preparation script..."
47
+ bash /home/user/config/prepare-aria2-config.sh
48
+ elif [ -f "${CONFIG_PREPARE_SCRIPT:-/configs/prepare-aria2-config.sh.template}" ]; then
49
+ log "Running system configuration preparation script..."
50
+ bash "${CONFIG_PREPARE_SCRIPT:-/configs/prepare-aria2-config.sh.template}"
51
+ else
52
+ log "No configuration preparation script found, using defaults..."
53
+ # Set basic defaults
54
+ ARIA2_PORT="${ARIA2_PORT:-6800}"
55
+ mkdir -p /home/user/config /home/user/logs /home/user/downloads
56
+ touch /home/user/config/aria2.session
57
+ fi
58
+
59
+ # Check if aria2 port is available
60
+ ARIA2_PORT="${ARIA2_PORT:-6800}"
61
+ if ! check_port "$ARIA2_PORT"; then
62
+ log "ERROR: Port $ARIA2_PORT is already in use"
63
+ exit 1
64
+ fi
65
+
66
+ # Start aria2 daemon
67
+ log "Starting aria2 daemon..."
68
+ if [ -f "/home/user/config/aria2.conf" ]; then
69
+ aria2c --conf-path=/home/user/config/aria2.conf --daemon=true
70
+ else
71
+ log "ERROR: aria2 configuration file not found"
72
+ exit 1
73
+ fi
74
+
75
+ # Wait for aria2 to start
76
+ if wait_for_aria2 "$ARIA2_PORT"; then
77
+ log "aria2 daemon started successfully"
78
+ log "RPC endpoint: http://localhost:$ARIA2_PORT/jsonrpc"
79
+
80
+ # Start web UI if available
81
+ ARIA2_WEBUI_PORT="${ARIA2_WEBUI_PORT:-6880}"
82
+ if [ -d "/usr/local/share/aria2" ] && check_port "$ARIA2_WEBUI_PORT"; then
83
+ log "Starting aria2 web UI on port $ARIA2_WEBUI_PORT..."
84
+ cd /usr/local/share/aria2
85
+ python3 -m http.server "$ARIA2_WEBUI_PORT" --bind 0.0.0.0 &
86
+ WEBUI_PID=$!
87
+ log "Web UI started with PID: $WEBUI_PID"
88
+ log "Web UI URL: http://localhost:$ARIA2_WEBUI_PORT"
89
+
90
+ # Verify web UI is actually running
91
+ sleep 2
92
+ if ! kill -0 "$WEBUI_PID" 2>/dev/null; then
93
+ log "WARNING: Web UI failed to start"
94
+ fi
95
+ elif [ ! -d "/usr/local/share/aria2" ]; then
96
+ log "WARNING: AriaNg web UI not found in /usr/local/share/aria2"
97
+ else
98
+ log "WARNING: Port $ARIA2_WEBUI_PORT is already in use, skipping web UI startup"
99
+ fi
100
+
101
+ # Keep the script running
102
+ while true; do
103
+ if ! nc -z localhost "$ARIA2_PORT" 2>/dev/null; then
104
+ log "ERROR: aria2 daemon stopped unexpectedly"
105
+ exit 1
106
+ fi
107
+ sleep 30
108
+ done
109
+ else
110
+ log "ERROR: Failed to start aria2 daemon"
111
+ exit 1
112
+ fi
scripts/install/aria2-install.sh ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ # Function for logging
6
+ log() {
7
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] [ARIA2] $*"
8
+ }
9
+
10
+ # Function for cleanup
11
+ cleanup() {
12
+ log "Performing aria2 installation cleanup..."
13
+ rm -rf \
14
+ /var/lib/apt/lists/* \
15
+ /tmp/aria2* \
16
+ /var/tmp/aria2*
17
+ }
18
+
19
+ # Trap to ensure cleanup on exit
20
+ trap cleanup EXIT
21
+
22
+ log "Starting aria2 installation..."
23
+
24
+ log "Updating package lists..."
25
+ apt-get update
26
+
27
+ log "Installing aria2 and required dependencies..."
28
+ apt-get install -y --no-install-recommends \
29
+ aria2 \
30
+ netcat-openbsd \
31
+ jq \
32
+ openssl \
33
+ curl \
34
+ unzip
35
+
36
+ # Create aria2 directories
37
+ log "Creating aria2 directories..."
38
+ mkdir -p /usr/local/share/aria2 \
39
+ /var/log/aria2
40
+
41
+ # Download aria2 web UI (AriaNg)
42
+ log "Downloading AriaNg web interface..."
43
+ ARIANG_VERSION="1.3.10"
44
+ ARIANG_URL="https://github.com/mayswind/AriaNg/releases/download/${ARIANG_VERSION}/AriaNg-${ARIANG_VERSION}.zip"
45
+
46
+ cd /tmp
47
+ curl -L -o "ariang.zip" "$ARIANG_URL"
48
+ unzip -q ariang.zip -d ariang
49
+ cp -r ariang/* /usr/local/share/aria2/
50
+ rm -rf ariang ariang.zip
51
+
52
+ log "Setting permissions..."
53
+ chown -R 1000:1000 /usr/local/share/aria2 /var/log/aria2
54
+
55
+ log "aria2 installation completed successfully"
56
+ log "AriaNg version: $ARIANG_VERSION"
scripts/start/aria2-start.sh ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ # Function for logging
6
+ log() {
7
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] [ARIA2] $*"
8
+ }
9
+
10
+ # Function to check if port is available
11
+ check_port() {
12
+ local port=$1
13
+ if nc -z localhost "$port" 2>/dev/null; then
14
+ return 1 # Port is in use
15
+ else
16
+ return 0 # Port is available
17
+ fi
18
+ }
19
+
20
+ # Function to wait for aria2 to start
21
+ wait_for_aria2() {
22
+ local port=$1
23
+ local max_attempts=30
24
+ local attempt=1
25
+
26
+ log "Waiting for aria2 to start on port $port..."
27
+
28
+ while [ $attempt -le $max_attempts ]; do
29
+ if nc -z localhost "$port" 2>/dev/null; then
30
+ log "aria2 is running on port $port"
31
+ return 0
32
+ fi
33
+
34
+ sleep 1
35
+ attempt=$((attempt + 1))
36
+ done
37
+
38
+ log "ERROR: aria2 failed to start after $max_attempts seconds"
39
+ return 1
40
+ }
41
+
42
+ log "Starting aria2 service..."
43
+
44
+ # Set default values
45
+ ARIA2_PORT="${ARIA2_PORT:-6800}"
46
+ ARIA2_WEBUI_PORT="${ARIA2_WEBUI_PORT:-6880}"
47
+ ARIA2_SECRET="${ARIA2_SECRET:-$(openssl rand -base64 32)}"
48
+ ARIA2_DOWNLOAD_DIR="${ARIA2_DOWNLOAD_DIR:-/home/user/downloads}"
49
+ ARIA2_SESSION_FILE="${ARIA2_SESSION_FILE:-/home/user/config/aria2.session}"
50
+ ARIA2_LOG_FILE="${ARIA2_LOG_FILE:-/home/user/logs/aria2.log}"
51
+
52
+ # Create required directories
53
+ mkdir -p "$(dirname "$ARIA2_SESSION_FILE")" \
54
+ "$(dirname "$ARIA2_LOG_FILE")" \
55
+ "$ARIA2_DOWNLOAD_DIR"
56
+
57
+ # Create session file if it doesn't exist
58
+ touch "$ARIA2_SESSION_FILE"
59
+
60
+ # Check if aria2 port is available
61
+ if ! check_port "$ARIA2_PORT"; then
62
+ log "ERROR: Port $ARIA2_PORT is already in use"
63
+ exit 1
64
+ fi
65
+
66
+ # Generate aria2 configuration
67
+ log "Generating aria2 configuration..."
68
+ cat > /home/user/config/aria2.conf << EOF
69
+ # aria2 configuration file
70
+ # Basic Options
71
+ dir=$ARIA2_DOWNLOAD_DIR
72
+ input-file=$ARIA2_SESSION_FILE
73
+ save-session=$ARIA2_SESSION_FILE
74
+ save-session-interval=60
75
+ force-save=true
76
+ log=$ARIA2_LOG_FILE
77
+ log-level=info
78
+
79
+ # RPC Options
80
+ enable-rpc=true
81
+ rpc-listen-all=true
82
+ rpc-listen-port=$ARIA2_PORT
83
+ rpc-secret=$ARIA2_SECRET
84
+ rpc-allow-origin-all=true
85
+
86
+ # Download Options
87
+ max-concurrent-downloads=5
88
+ max-connection-per-server=16
89
+ split=16
90
+ min-split-size=1M
91
+ continue=true
92
+ max-overall-download-limit=0
93
+ max-download-limit=0
94
+ max-overall-upload-limit=0
95
+ max-upload-limit=0
96
+
97
+ # BitTorrent Options
98
+ bt-enable-lpd=true
99
+ bt-lpd-interface=0.0.0.0
100
+ follow-torrent=true
101
+ bt-max-open-files=16
102
+ bt-max-peers=55
103
+ bt-request-peer-speed-limit=50K
104
+ bt-stop-timeout=0
105
+ bt-tracker-connect-timeout=10
106
+ bt-tracker-timeout=10
107
+ seed-time=0
108
+ max-upload-limit=100K
109
+
110
+ # Metalink Options
111
+ follow-metalink=true
112
+ metalink-preferred-protocol=https
113
+
114
+ # Advanced Options
115
+ disable-ipv6=false
116
+ disk-cache=64M
117
+ file-allocation=prealloc
118
+ no-file-allocation-limit=32M
119
+ EOF
120
+
121
+ log "Starting aria2 daemon..."
122
+ aria2c --conf-path=/home/user/config/aria2.conf --daemon=true
123
+
124
+ # Wait for aria2 to start
125
+ if wait_for_aria2 "$ARIA2_PORT"; then
126
+ log "aria2 daemon started successfully"
127
+ log "RPC endpoint: http://localhost:$ARIA2_PORT/jsonrpc"
128
+ log "RPC secret: $ARIA2_SECRET"
129
+ log "Download directory: $ARIA2_DOWNLOAD_DIR"
130
+
131
+ # Start web UI if available
132
+ if [ -d "/usr/local/share/aria2" ]; then
133
+ if check_port "$ARIA2_WEBUI_PORT"; then
134
+ log "Starting aria2 web UI on port $ARIA2_WEBUI_PORT..."
135
+ cd /usr/local/share/aria2
136
+ python3 -m http.server "$ARIA2_WEBUI_PORT" --bind 0.0.0.0 &
137
+ WEBUI_PID=$!
138
+ log "Web UI started with PID: $WEBUI_PID"
139
+ log "Web UI URL: http://localhost:$ARIA2_WEBUI_PORT"
140
+ else
141
+ log "WARNING: Port $ARIA2_WEBUI_PORT is already in use, skipping web UI startup"
142
+ fi
143
+ else
144
+ log "WARNING: AriaNg web UI not found in /usr/local/share/aria2"
145
+ fi
146
+
147
+ # Keep the script running
148
+ while true; do
149
+ if ! nc -z localhost "$ARIA2_PORT" 2>/dev/null; then
150
+ log "ERROR: aria2 daemon stopped unexpectedly"
151
+ exit 1
152
+ fi
153
+ sleep 30
154
+ done
155
+ else
156
+ log "ERROR: Failed to start aria2 daemon"
157
+ exit 1
158
+ fi