import
This commit is contained in:
commit
1de72fca33
66
Dockerfile
Normal file
66
Dockerfile
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
FROM debian:stretch
|
||||||
|
MAINTAINER Julien Cabillot <jcabillot@gmail.com>
|
||||||
|
|
||||||
|
RUN groupadd -r -g 666 sabnzbd && \
|
||||||
|
useradd -l -r -u 666 -g 666 -d /sabnzbd sabnzbd
|
||||||
|
|
||||||
|
#
|
||||||
|
# Add SABnzbd init script.
|
||||||
|
#
|
||||||
|
|
||||||
|
COPY sabnzbd.sh /sabnzbd.sh
|
||||||
|
RUN chmod 755 /sabnzbd.sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Fix locales to handle UTF-8 characters.
|
||||||
|
#
|
||||||
|
|
||||||
|
ENV LANG C.UTF-8
|
||||||
|
|
||||||
|
#
|
||||||
|
# Install SABnzbd and all required dependencies.
|
||||||
|
#
|
||||||
|
|
||||||
|
RUN export SABNZBD_VERSION=2.3.0 PAR2CMDLINE_VERSION=v0.6.14-mt1 && \
|
||||||
|
export DEBIAN_FRONTEND=noninteractive && \
|
||||||
|
export BUILD_PACKAGES="automake build-essential curl python-dev python-pip" && \
|
||||||
|
export RUNTIME_PACKAGES="ca-certificates p7zip-full python-cheetah python-yenc unrar unzip libgomp1 openssl python-cryptography python-openssl" && \
|
||||||
|
export PIP_PACKAGES="sabyenc" && \
|
||||||
|
sed -i "s/ main$/ main contrib non-free/" /etc/apt/sources.list && \
|
||||||
|
apt-get -q update && \
|
||||||
|
apt-get install -qqy $BUILD_PACKAGES $RUNTIME_PACKAGES && \
|
||||||
|
pip install $PIP_PACKAGES && \
|
||||||
|
curl -SL -o /tmp/sabnzbd.tar.gz https://github.com/sabnzbd/sabnzbd/releases/download/${SABNZBD_VERSION}/SABnzbd-${SABNZBD_VERSION}-src.tar.gz && \
|
||||||
|
tar xzf /tmp/sabnzbd.tar.gz && \
|
||||||
|
mv SABnzbd-* sabnzbd && \
|
||||||
|
chown -R sabnzbd: sabnzbd && \
|
||||||
|
curl -o /tmp/par2cmdline-mt.tar.gz https://codeload.github.com/jkansanen/par2cmdline-mt/tar.gz/${PAR2CMDLINE_VERSION} && \
|
||||||
|
tar xzf /tmp/par2cmdline-mt.tar.gz -C /tmp && \
|
||||||
|
cd /tmp/par2cmdline-* && \
|
||||||
|
aclocal && \
|
||||||
|
automake --add-missing && \
|
||||||
|
autoconf && \
|
||||||
|
./configure && \
|
||||||
|
make && \
|
||||||
|
make install && \
|
||||||
|
apt-get -y remove --purge $BUILD_PACKAGES && \
|
||||||
|
apt-get -y autoremove --purge && \
|
||||||
|
apt-get -y clean all && \
|
||||||
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
rm -rf /tmp/*
|
||||||
|
|
||||||
|
#
|
||||||
|
# Define container settings.
|
||||||
|
#
|
||||||
|
|
||||||
|
VOLUME ["/datadir", "/media"]
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start SABnzbd.
|
||||||
|
#
|
||||||
|
|
||||||
|
WORKDIR /sabnzbd
|
||||||
|
|
||||||
|
CMD ["/sabnzbd.sh"]
|
||||||
60
sabnzbd.sh
Normal file
60
sabnzbd.sh
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
#
|
||||||
|
# Display settings on standard out.
|
||||||
|
#
|
||||||
|
|
||||||
|
USER="sabnzbd"
|
||||||
|
|
||||||
|
echo "SABnzbd settings"
|
||||||
|
echo "================"
|
||||||
|
echo
|
||||||
|
echo " User: ${USER}"
|
||||||
|
echo " UID: ${SABNZBD_UID:=666}"
|
||||||
|
echo " GID: ${SABNZBD_GID:=666}"
|
||||||
|
echo
|
||||||
|
echo " Config: ${CONFIG:=/datadir/config.ini}"
|
||||||
|
echo
|
||||||
|
|
||||||
|
#
|
||||||
|
# Change UID / GID of SABnzbd user.
|
||||||
|
#
|
||||||
|
|
||||||
|
printf "Updating UID / GID... "
|
||||||
|
[[ $(id -u ${USER}) == ${SABNZBD_UID} ]] || usermod -o -u ${SABNZBD_UID} ${USER}
|
||||||
|
[[ $(id -g ${USER}) == ${SABNZBD_GID} ]] || groupmod -o -g ${SABNZBD_GID} ${USER}
|
||||||
|
echo "[DONE]"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Set directory permissions.
|
||||||
|
#
|
||||||
|
|
||||||
|
printf "Set permissions... "
|
||||||
|
touch ${CONFIG}
|
||||||
|
chown -R ${USER}: /sabnzbd
|
||||||
|
function check_dir {
|
||||||
|
[ "$(stat -c '%u %g' $1)" == "${SABNZBD_UID} ${SABNZBD_GID}" ] || chown ${USER}: $1
|
||||||
|
}
|
||||||
|
check_dir /datadir
|
||||||
|
check_dir /media
|
||||||
|
check_dir $(dirname ${CONFIG})
|
||||||
|
echo "[DONE]"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Because SABnzbd runs in a container we've to make sure we've a proper
|
||||||
|
# listener on 0.0.0.0. We also have to deal with the port which by default is
|
||||||
|
# 8080 but can be changed by the user.
|
||||||
|
#
|
||||||
|
|
||||||
|
printf "Get listener port... "
|
||||||
|
PORT=$(sed -n '/^port *=/{s/port *= *//p;q}' ${CONFIG})
|
||||||
|
LISTENER="-s 0.0.0.0:${PORT:=8080}"
|
||||||
|
echo "[${PORT}]"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Finally, start SABnzbd.
|
||||||
|
#
|
||||||
|
|
||||||
|
echo "Starting SABnzbd..."
|
||||||
|
exec su -pc "./SABnzbd.py -b 0 -f ${CONFIG} ${LISTENER}" ${USER}
|
||||||
28
test.sh
Normal file
28
test.sh
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Simple test script that sees if the SABnzbd server is up within a certain number
|
||||||
|
# of seconds (TOTAL_ATTEMPTS * SLEEP_TIME). If it isn't up in time or the HTTP
|
||||||
|
# code returned is not 200, then it exits out with an error code.
|
||||||
|
|
||||||
|
TOTAL_ATTEMPTS=10
|
||||||
|
SLEEP_TIME=6
|
||||||
|
|
||||||
|
function connect_server {
|
||||||
|
http_code=$(curl -sL -w "%{http_code}\\n" "http://localhost:8080/" -o /dev/null)
|
||||||
|
curl_exit=$?
|
||||||
|
}
|
||||||
|
|
||||||
|
attempts=0
|
||||||
|
until [ $attempts -ge $TOTAL_ATTEMPTS ]
|
||||||
|
do
|
||||||
|
connect_server
|
||||||
|
[ "$curl_exit" == "0" ] && break
|
||||||
|
attempts=$[$attempts+1]
|
||||||
|
sleep $SLEEP_TIME
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$http_code" != "200" ]
|
||||||
|
then
|
||||||
|
echo "Received HTTP $http_code from SABnzbd port (last curl exit code: $curl_exit)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Loading…
x
Reference in New Issue
Block a user