Skip to content

Commit 667911c

Browse files
committed
add option to limit bandwidth
1 parent 3259d44 commit 667911c

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ COPY files/create-folders.sh files/encoder-worker.sh files/entrypoint.sh /usr/lo
7070
ENV CREATE_FOLDERS=true
7171
ENV ENCODER_CPU=false
7272
ENV EXIT_ON_FINISH=false
73+
ENV MAX_BANDWIDTH=0
7374
ENV NICENESS_ADJUSTMENT=19
7475
ENV SCHED_POLICY="idle"
7576
ENV SERVER_IDENTITY=""

Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ contains some special folder which corresponds to arguments for the encode scrip
2121
- Set to `true` to enable cpu encoding.
2222
- `EXIT_ON_FINISH`
2323
- Set to `true` to exit if no more files to encode are present.
24+
- `MAX_BANDWIDTH`
25+
- Limit the upload and download bandwidth, for example `10M` for 10 MB/s.
2426
- `NICENESS_ADJUSTMENT`
2527
- Set a custom niceness adjustment, default `19`.
2628
- `SCHED_POLICY`

Version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.1.0
1+
v2.2.0

files/create-folders.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ for FOLDER in "${FOLDER_TO_CREATE[@]}"; do
2828
if [[ -z "$SERVER_URL" ]]; then
2929
mkdir --parents "/media/encoder/$FOLDER"
3030
else
31-
rclone --config "" mkdir ":sftp:$FOLDER"
31+
rclone mkdir ":sftp:$FOLDER"
3232
fi
3333
done

files/encoder-worker.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ cleanup () {
3636
rm --force --recursive "${LOCAL_BASE_DIR:?}/${WORKER_INPUT_DIR:?}" \
3737
"${LOCAL_BASE_DIR:?}/${WORKER_OUTPUT_DIR:?}"
3838
else
39-
rclone --config "" moveto ":sftp:${WORKER_INPUT_DIR}/" \
39+
rclone moveto ":sftp:${WORKER_INPUT_DIR}/" \
4040
":sftp:$FAILED_DIR" > /dev/null 2>&1 || true
41-
rclone --config "" purge ":sftp:$WORKER_INPUT_DIR" > /dev/null 2>&1 || true
42-
rclone --config "" purge ":sftp:$WORKER_OUTPUT_DIR" > /dev/null 2>&1 || true
41+
rclone purge ":sftp:$WORKER_INPUT_DIR" > /dev/null 2>&1 || true
42+
rclone purge ":sftp:$WORKER_OUTPUT_DIR" > /dev/null 2>&1 || true
4343
fi
4444
}
4545

4646
trap cleanup SIGINT SIGTERM
4747

4848
if [[ -z "$SERVER_URL" ]] && [[ -d "${LOCAL_BASE_DIR:?}/$WORKER_INPUT_DIR" ]] \
49-
|| rclone --config "" lsd ":sftp:$WORKER_INPUT_DIR" > /dev/null 2>&1; then
49+
|| rclone lsd ":sftp:$WORKER_INPUT_DIR" > /dev/null 2>&1; then
5050
echo "Worker directory already exists." >&2
5151
cleanup
5252
fi
@@ -58,7 +58,7 @@ while true; do
5858
-path "${LOCAL_BASE_DIR}/${INPUT_DIR}/.working" -prune | shuf --head-count 1)"
5959
WORKER_FILE="${WORKER_FILE#"${LOCAL_BASE_DIR}/"}"
6060
else
61-
WORKER_FILE="$(rclone --config "" lsf --exclude '.working/' --files-only \
61+
WORKER_FILE="$(rclone lsf --exclude '.working/' --files-only \
6262
--recursive ":sftp:$INPUT_DIR" | shuf --head-count 1 | sed "s|^|${INPUT_DIR}/|")"
6363
fi
6464
if [[ -z "$WORKER_FILE" ]]; then
@@ -130,10 +130,10 @@ while true; do
130130
cp "${LOCAL_BASE_DIR}/${WORKER_INPUT_DIR}/${WORKER_FILE_BASENAME}" \
131131
"${WORKDIR}/${WORKER_FILE_BASENAME}"
132132
else
133-
rclone --config "" mkdir ":sftp:$WORKER_INPUT_DIR"
134-
rclone --config "" moveto ":sftp:$WORKER_FILE" \
133+
rclone mkdir ":sftp:$WORKER_INPUT_DIR"
134+
rclone moveto ":sftp:$WORKER_FILE" \
135135
":sftp:${WORKER_INPUT_DIR}/${WORKER_FILE_BASENAME}"
136-
rclone --config "" copyto \
136+
rclone copyto \
137137
":sftp:${WORKER_INPUT_DIR}/${WORKER_FILE_BASENAME}" \
138138
"${WORKDIR}/${WORKER_FILE_BASENAME}"
139139
fi
@@ -148,14 +148,14 @@ while true; do
148148
"${LOCAL_BASE_DIR}/${OUTPUT_DIR}/${WORKER_FILE_RELATIVE_FOLDER}"
149149
rm "${LOCAL_BASE_DIR}/${WORKER_INPUT_DIR}/${OUTPUT_FILE_BASENAME}"
150150
else
151-
rclone --config "" mkdir ":sftp:$WORKER_OUTPUT_DIR"
152-
rclone --config "" moveto "${WORKDIR}/${OUTPUT_FILE_BASENAME}" \
151+
rclone mkdir ":sftp:$WORKER_OUTPUT_DIR"
152+
rclone moveto "${WORKDIR}/${OUTPUT_FILE_BASENAME}" \
153153
":sftp:${WORKER_OUTPUT_DIR}/${OUTPUT_FILE_BASENAME}"
154-
rclone --config "" mkdir ":sftp:${OUTPUT_DIR}/$WORKER_FILE_RELATIVE_FOLDER"
155-
rclone --config "" moveto \
154+
rclone mkdir ":sftp:${OUTPUT_DIR}/$WORKER_FILE_RELATIVE_FOLDER"
155+
rclone moveto \
156156
":sftp:${WORKER_OUTPUT_DIR}/${OUTPUT_FILE_BASENAME}" \
157157
":sftp:${OUTPUT_DIR}/${WORKER_FILE_RELATIVE_FOLDER}/${OUTPUT_FILE_BASENAME}"
158-
rclone --config "" delete \
158+
rclone delete \
159159
":sftp:${WORKER_INPUT_DIR}/${OUTPUT_FILE_BASENAME}"
160160
fi
161161
cleanup

files/entrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ if [[ -z "$WORKER_ID" ]]; then
66
fi
77

88
if [[ -n "$SERVER_URL" ]]; then
9+
RCLONE_BWLIMIT="$MAX_BANDWIDTH"
10+
RCLONE_CONFIG=""
911
RCLONE_SFTP_USER=${SERVER_URL#sftp://}
1012
RCLONE_SFTP_USER=${RCLONE_SFTP_USER%@*}
1113
RCLONE_SFTP_HOST=${SERVER_URL#*@}
@@ -24,8 +26,8 @@ if [[ -n "$SERVER_URL" ]]; then
2426
chmod 600 /dev/shm/ssh-known-hosts
2527
RCLONE_SFTP_KNOWN_HOSTS_FILE="/dev/shm/ssh-known-hosts"
2628
fi
27-
export RCLONE_SFTP_HOST RCLONE_SFTP_KEY_FILE RCLONE_SFTP_KNOWN_HOSTS_FILE \
28-
RCLONE_SFTP_PORT RCLONE_SFTP_USER
29+
export RCLONE_BWLIMIT RCLONE_CONFIG RCLONE_SFTP_HOST RCLONE_SFTP_KEY_FILE \
30+
RCLONE_SFTP_KNOWN_HOSTS_FILE RCLONE_SFTP_PORT RCLONE_SFTP_USER
2931
fi
3032

3133
exec "$@"

0 commit comments

Comments
 (0)