mirror of
https://github.com/casjaysdevdocker/aria2
synced 2025-09-18 15:57:44 -04:00
🗃️ Committing everything that changed 🗃️
This commit is contained in:
@@ -4,7 +4,6 @@ ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-/run/init.d/entrypoint.pid}"
|
||||
ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}"
|
||||
ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}"
|
||||
ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}"
|
||||
export ENTRYPOINT_PID_FILE ENTRYPOINT_INIT_FILE ENTRYPOINT_DATA_INIT_FILE ENTRYPOINT_CONFIG_INIT_FILE
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Startup variables
|
||||
INIT_DATE="${INIT_DATE:-$(date)}"
|
||||
@@ -20,4 +19,3 @@ CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-false}"
|
||||
[ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="true"
|
||||
[ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="true"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export DATA_DIR_INITIALIZED CONFIG_DIR_INITIALIZED START_SERVICES ENTRYPOINT_MESSAGE ENTRYPOINT_FIRST_RUN
|
||||
|
@@ -4,12 +4,13 @@
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__rm() { [ -f "$1" ] && rm -Rf "${1:?}"; }
|
||||
__cd() { [ -d "$1" ] && builtin cd "$1" || return 1; }
|
||||
__ps() { [ -f "$(type -P ps)" ] && ps "$@" || return 10; }
|
||||
__netstat() { [ -f "$(type -P netstat)" ] && netstat "$@" || return 10; }
|
||||
__curl() { curl -q -sfI --max-time 3 -k -o /dev/null "$@" &>/dev/null || return 10; }
|
||||
__find() { find "$1" -mindepth 1 -type ${2:-f,d} 2>/dev/null | grep '^' || return 10; }
|
||||
__pcheck() { [ -n "$(which pgrep 2>/dev/null)" ] && pgrep -x "$1" &>/dev/null || return 10; }
|
||||
__pgrep() { __pcheck "${1:-GEN_SCRIPT_REPLACE_APPNAME}" || __ps aux 2>/dev/null | grep -Fw " ${1:-$GEN_SCRIPT_REPLACE_APPNAME}" | grep -qv ' grep' || return 10; }
|
||||
__no_exit() { exec /bin/sh -c "trap : TERM INT; (while true; do sleep 1000; done) & wait"; }
|
||||
__pcheck() { [ -n "$(which pgrep 2>/dev/null)" ] && pgrep -o "$1" &>/dev/null || return 10; }
|
||||
__ps() { [ -f "$(type -P ps)" ] && ps "$@" 2>/dev/null | grep -Fw " ${1:-$GEN_SCRIPT_REPLACE_APPNAME}" || return 10; }
|
||||
__pgrep() { __pcheck "${1:-GEN_SCRIPT_REPLACE_APPNAME}" || __ps "${1:-$GEN_SCRIPT_REPLACE_APPNAME}" | grep -qv ' grep' || return 10; }
|
||||
__get_ip6() { ip a 2>/dev/null | grep -w 'inet6' | awk '{print $2}' | grep -vE '^::1|^fe' | sed 's|/.*||g' | head -n1 | grep '^' || echo ''; }
|
||||
__get_ip4() { ip a 2>/dev/null | grep -w 'inet' | awk '{print $2}' | grep -vE '^127.0.0' | sed 's|/.*||g' | head -n1 | grep '^' || echo '127.0.0.1'; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -39,26 +40,39 @@ __update_ssl_certs() {
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__certbot() {
|
||||
if [ -f "/config/bin/certbot.sh" ]; then
|
||||
"/config/bin/certbot.sh"
|
||||
local statusCode=0
|
||||
[ -n "$(type -P 'certbot')" ] || return 1
|
||||
if [ -f "/config/certbot/env.sh" ]; then
|
||||
. "/config/certbot/env.sh"
|
||||
fi
|
||||
if [ -f "/config/certbot/setup.sh" ]; then
|
||||
eval "/config/certbot/setup.sh"
|
||||
statusCode=$?
|
||||
elif [ -f "/etc/named/certbot.sh" ]; then
|
||||
"/etc/named/certbot.sh"
|
||||
eval "/etc/named/certbot.sh"
|
||||
statusCode=$?
|
||||
elif [ -f "/config/named/certbot-update.conf" ]; then
|
||||
if certbot renew -n --dry-run --agree-tos --expand --dns-rfc2136 --dns-rfc2136-credentials /config/named/certbot-update.conf; then
|
||||
certbot renew -n --agree-tos --expand --dns-rfc2136 --dns-rfc2136-credentials /config/named/certbot-update.conf
|
||||
fi
|
||||
statusCode=$?
|
||||
else
|
||||
local options="${1:-create}" && shift 1
|
||||
domain_list="$DOMAINNAME www.$DOMAINNAME mail.$DOMAINNAME $CERTBOT_DOMAINS"
|
||||
[ -f "/config/env/ssl.sh" ] && . "/config/env/ssl.sh"
|
||||
[ "$SSL_CERT_BOT" = "true" ] && [ -f "$(type -P certbot)" ] || { export SSL_CERT_BOT="" && return 10; }
|
||||
[ "$SSL_CERT_BOT" = "true" ] || { export SSL_CERT_BOT="" && return 10; }
|
||||
[ -n "$CERT_BOT_MAIL" ] || echo "The variable CERT_BOT_MAIL is not set" && return 1
|
||||
[ -n "$DOMAINNAME" ] || echo "The variable DOMAINNAME is not set" && return 1
|
||||
for domain in $$CERTBOT_DOMAINS; do
|
||||
[ -n "$domain" ] && ADD_CERTBOT_DOMAINS="-d $domain "
|
||||
done
|
||||
certbot $options --agree-tos -m $CERT_BOT_MAIL certonly --webroot \
|
||||
-w "${WWW_ROOT_DIR:-/data/htdocs/www}" \
|
||||
$ADD_CERTBOT_DOMAINS --put-all-related-files-into "$SSL_DIR" \
|
||||
-key-path "$SSL_KEY" -fullchain-path "$SSL_CERT" && __update_ssl_certs
|
||||
-w "${WWW_ROOT_DIR:-/data/htdocs/www}" $ADD_CERTBOT_DOMAINS \
|
||||
--put-all-related-files-into "$SSL_DIR" -key-path "$SSL_KEY" -fullchain-path "$SSL_CERT"
|
||||
statusCode=$?
|
||||
fi
|
||||
return $?
|
||||
[ $statusCode -eq 0 ] && __update_ssl_certs
|
||||
return $statusCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__create_ssl_cert() {
|
||||
@@ -92,19 +106,21 @@ __create_ssl_cert() {
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__init_apache() {
|
||||
local etc_dir="/etc/${1:-apache2}"
|
||||
local conf_dir="/config/${1:-apache2}"
|
||||
local www_dir="${WWW_ROOT_DIR:-/data/htdocs/www}"
|
||||
local apache_bin="$(type -P 'httpd' || type -P 'apache2')"
|
||||
local etc_dir="" conf_dir="" conf_dir="" www_dir="" apache_bin=""
|
||||
etc_dir="/etc/${1:-apache2}"
|
||||
conf_dir="/config/${1:-apache2}"
|
||||
www_dir="${WWW_ROOT_DIR:-/data/htdocs/www}"
|
||||
apache_bin="$(type -P 'httpd' || type -P 'apache2')"
|
||||
#
|
||||
return 0
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__init_nginx() {
|
||||
local etc_dir="/etc/${1:-nginx}"
|
||||
local conf_dir="/config/${1:-nginx}"
|
||||
local www_dir="${WWW_ROOT_DIR:-/data/htdocs}"
|
||||
local nginx_bin="$(type -P 'nginx')"
|
||||
local etc_dir="" conf_dir="" www_dir="" nginx_bin=""
|
||||
etc_dir="/etc/${1:-nginx}"
|
||||
conf_dir="/config/${1:-nginx}"
|
||||
www_dir="${WWW_ROOT_DIR:-/data/htdocs}"
|
||||
nginx_bin="$(type -P 'nginx')"
|
||||
#
|
||||
return 0
|
||||
}
|
||||
@@ -118,14 +134,15 @@ __init_php() {
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__init_mysql() {
|
||||
local db_dir="/data/db/mysql"
|
||||
local etc_dir="${home:-/etc/${1:-mysql}}"
|
||||
local db_user="${SERVICE_USER:-mysql}"
|
||||
local conf_dir="/config/${1:-mysql}"
|
||||
local user_pass="${MARIADB_PASSWORD:-$MARIADB_ROOT_PASSWORD}"
|
||||
local user_db="${MARIADB_DATABASE}" user_name="${MARIADB_USER:-root}"
|
||||
local root_pass="$MARIADB_ROOT_PASSWORD"
|
||||
local mysqld_bin="$(type -P 'mysqld')"
|
||||
local db_dir="" etc_dir="" db_user="" conf_dir="" user_pass="" user_db="" root_pass="" mysqld_bin=""
|
||||
db_dir="/data/db/mysql"
|
||||
etc_dir="${home:-/etc/${1:-mysql}}"
|
||||
db_user="${SERVICE_USER:-mysql}"
|
||||
conf_dir="/config/${1:-mysql}"
|
||||
user_pass="${MARIADB_PASSWORD:-$MARIADB_ROOT_PASSWORD}"
|
||||
user_db="${MARIADB_DATABASE}" user_name="${MARIADB_USER:-root}"
|
||||
root_pass="$MARIADB_ROOT_PASSWORD"
|
||||
mysqld_bin="$(type -P 'mysqld')"
|
||||
#
|
||||
return 0
|
||||
}
|
||||
@@ -172,13 +189,20 @@ __run_once() {
|
||||
fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run program ever n minutes
|
||||
__cron() {
|
||||
local interval="$1" && shift 1
|
||||
local command="$*"
|
||||
trap '[ -f "/run/cron/$cmd" ] && rm -Rf "/run/cron/$cmd";exit 0' SIGINT ERR EXIT
|
||||
test -n "$1" && test -z "${1//[0-9]/}" && interval=$(($1 * 60)) && shift 1 || interval="5"
|
||||
[ $# -eq 0 ] && echo "Usage: cron [interval] [command]" && exit 1
|
||||
command="$*"
|
||||
cmd="$(echo "$command" | awk -F' ' '{print $1}')"
|
||||
[ -d "/run/cron" ] || mkdir -p "/run/cron"
|
||||
echo "$command" >"/run/cron/$cmd"
|
||||
while :; do
|
||||
eval "$command"
|
||||
sleep $interval
|
||||
done
|
||||
[ -f "/run/cron/$cmd" ] || break
|
||||
done |& tee /var/log/entrypoint.log
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__replace() {
|
||||
@@ -253,6 +277,7 @@ __exec_command() {
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup the server init scripts
|
||||
__start_init_scripts() {
|
||||
{ [ "$1" = "" ] && shift 1; } || { [ "$1" = " " ] && shift 1; }
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS || set -o pipefail
|
||||
local basename=""
|
||||
local init_pids=""
|
||||
@@ -265,13 +290,13 @@ __start_init_scripts() {
|
||||
for init in "$init_dir"/*.sh; do
|
||||
if [ -f "$init" ]; then
|
||||
name="$(basename "$init")"
|
||||
(eval "$init" 2>/dev/stderr >/dev/stdout &)
|
||||
(eval "$init" &)
|
||||
initStatus=$(($? + initStatus))
|
||||
sleep 30
|
||||
sleep 10
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
fi
|
||||
return $initStatus
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__setup_mta() {
|
||||
@@ -283,11 +308,12 @@ __setup_mta() {
|
||||
local account_domain="${EMAIL_DOMAIN//*@/}"
|
||||
echo "$EMAIL_RELAY" | grep '[0-9][0-9]' || relay_port="465"
|
||||
|
||||
if [ -d "/etc/ssmtp" ] || [ -d "/config/ssmtp" ]; then
|
||||
# sSMTP relay setup
|
||||
[ -d "/etc/ssmtp" ] && rm -Rf "/etc/ssmtp" || return 0
|
||||
################# sSMTP relay setup
|
||||
if [ -n "$(type -P 'ssmtp')" ] || [ -d "/etc/ssmtp" ] || [ -d "/config/ssmtp" ]; then
|
||||
[ -d "/config/ssmtp" ] || mkdir -p "/config/ssmtp"
|
||||
cat <<EOF | tee "/config/ssmtp/ssmtp.conf" &>/dev/null
|
||||
[ -f "/etc/ssmtp/ssmtp.conf" ] && rm -Rf "/etc/ssmtp/ssmtp.conf"
|
||||
if [ ! -f "/config/ssmtp/ssmtp.conf" ]; then
|
||||
cat <<EOF | tee "/config/ssmtp/ssmtp.conf" &>/dev/null
|
||||
# ssmtp configuration.
|
||||
root=${account_user:-root}@${account_domain:-$HOSTNAME}
|
||||
mailhub=${relay_server:-172.17.0.1}:$relay_port
|
||||
@@ -302,20 +328,22 @@ FromLineOverride=yes
|
||||
#AuthPass=password
|
||||
|
||||
EOF
|
||||
# if [ -f "/config/ssmtp/ssmtp.conf" ] && [ ! -f "/run/init.d/ssmtp.pid" ]; then
|
||||
# SERVICES_LIST+="ssmtp "
|
||||
# cp -Rf "/config/ssmtp/." "/etc/ssmtp/"
|
||||
# __exec_command ssmtp "/etc/ssmtp/ssmtp.conf" &
|
||||
# [ $? -eq 0 ] && touch "/run/init.d/ssmtp.pid" || exitCode=1
|
||||
# fi
|
||||
# postfix relay setup
|
||||
elif [ -d "/config/postfix" ] || [ -d "/etc/postfix" ]; then
|
||||
cat <<EOF | tee "/config/postfix/main.cf" &>/dev/null
|
||||
fi
|
||||
if [ -f "/config/ssmtp/ssmtp.conf" ]; then
|
||||
cp -Rf "/config/ssmtp/." "/etc/ssmtp/"
|
||||
fi
|
||||
|
||||
################# postfix relay setup
|
||||
elif [ -n "$(type -P 'postfix')" ] || [ -d "/config/postfix" ] || [ -d "/etc/postfix" ]; then
|
||||
[ -d "/etc/postfix" ] || mkdir -p "/etc/postfix"
|
||||
[ -f "/etc/postfix/main.cf" ] && rm -Rf "/etc/postfix/main.cf"
|
||||
if [ ! -f "/config/postfix/main.cf" ]; then
|
||||
cat <<EOF | tee "/config/postfix/main.cf" &>/dev/null
|
||||
# postfix configuration.
|
||||
smtpd_banner = \$myhostname ESMTP CasjaysDev mail
|
||||
smtpd_banner = \$myhostname ESMTP email server
|
||||
compatibility_level = 2
|
||||
alias_maps = hash:/etc/aliases
|
||||
alias_database = hash:/etc/aliases
|
||||
alias_maps = hash:/etc/postfix/aliases
|
||||
alias_database = hash:/etc/postfix/aliases
|
||||
mynetworks = /etc/postfix/mynetworks
|
||||
transport_maps = hash:/etc/postfix/transport
|
||||
virtual_alias_maps = hash:/etc/postfix/virtual
|
||||
@@ -324,7 +352,6 @@ tls_random_source = dev:/dev/urandom
|
||||
smtp_use_tls = yes
|
||||
smtpd_use_tls = yes
|
||||
smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache
|
||||
smtpd_tls_dh1024_param_file = /etc/ssl/dhparam/1024.pem
|
||||
smtpd_tls_exclude_ciphers = aNULL, eNULL, EXPORT, DES, RC4, MD5, PSK, aECDH, EDH-DSS-DES-CBC3-SHA, EDH-RSA-DES-CBC3-SHA, KRB5-DES, CBC3-SHA
|
||||
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination
|
||||
mydestination =
|
||||
@@ -337,13 +364,14 @@ relayhost = [$relay_server]:$relay_port
|
||||
inet_protocols = ipv4
|
||||
|
||||
EOF
|
||||
touch "/etc/aliases" "/etc/postfix/mynetworks" "/etc/postfix/transport"
|
||||
touch "/etc/postfix/mydomains.pcre" "/etc/postfix/mydomains" "/etc/postfix/virtual"
|
||||
postmap "/etc/aliases" "/etc/postfix/mynetworks" "/etc/postfix/transport" &>/dev/null
|
||||
postmap "/etc/postfix/mydomains.pcre" "/etc/postfix/mydomains" "/etc/postfix/virtual" &>/dev/null
|
||||
fi
|
||||
touch "/config/postfix/aliases" "/config/postfix/mynetworks" "/config/postfix/transport"
|
||||
touch "/config/postfix/mydomains.pcre" "/config/postfix/mydomains" "/config/postfix/virtual"
|
||||
if [ -f "/config/postfix/main.cf" ] && [ ! -f "/run/init.d/postfix.pid" ]; then
|
||||
SERVICES_LIST+="postfix "
|
||||
cp -Rf "/config/postfix/." "/etc/postfix/"
|
||||
postmap "/etc/postfix/aliases" "/etc/postfix/mynetworks" "/etc/postfix/transport" &>/dev/null
|
||||
postmap "/etc/postfix/mydomains.pcre" "/etc/postfix/mydomains" "/etc/postfix/virtual" &>/dev/null
|
||||
__exec_command postfix "/etc/postfix/main.cf" &
|
||||
[ $? -eq 0 ] && touch "/run/init.d/postfix.pid" || exitCode=1
|
||||
fi
|
||||
@@ -365,13 +393,9 @@ MARIADB_CONFIG_FILE="${MARIADB_CONFIG_FILE:-$(__find_mysql_conf)}"
|
||||
POSTGRES_CONFIG_FILE="${POSTGRES_CONFIG_FILE:-$(__find_pgsql_conf)}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# export variables
|
||||
export CONTAINER_IP4_ADDRESS CONTAINER_IP6_ADDRESS
|
||||
export PHP_INI_DIR PHP_BIN_DIR HTTPD_CONFIG_FILE
|
||||
export NGINX_CONFIG_FILE MYSQL_CONFIG_FILE PGSQL_CONFIG_FILE
|
||||
export ENTRYPOINT_FIRST_RUN SET_RANDOM_PASS
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# export the functions
|
||||
export -f __update_ssl_certs __certbot __create_ssl_cert __init_apache __init_nginx
|
||||
export -f __init_php __init_mysql __init_mongodb __init_postgres __init_couchdb
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# end of functions
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
||||
SCRIPT_NAME="$(basename "$0" 2>/dev/null)"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS || set -o pipefail
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||
@@ -25,13 +26,13 @@ done
|
||||
WORKDIR="" # set working directory
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_USER="root" # execute command as another user
|
||||
SERVICE_PORT="" # port which service is listening on
|
||||
SERVICE_PORT="8000" # port which service is listening on
|
||||
EXEC_CMD_BIN="aria2c" # command to execute
|
||||
EXEC_CMD_ARGS="--conf-path=/etc/aria2/aria2.conf" # command arguments
|
||||
PRE_EXEC_MESSAGE="" # Show message before execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Other variables that are needed
|
||||
ARIA2RPCPORT="${ARIA2RPCPORT:-$SERVICE_PORT}"
|
||||
ARIA2RPCPORT="${ARIA2RPCPORT:-8000}"
|
||||
etc_dir="/etc/aria2"
|
||||
conf_dir="/config/aria2"
|
||||
www_dir="/usr/local/share/ariang"
|
||||
@@ -40,14 +41,23 @@ get_config="$(find "$www_dir/js" -name 'aria-ng-*.min.js' | grep -v 'f1dd57abb9.
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__update_conf_files() {
|
||||
local port="${SERVICE_PORT:-${ARIA2RPCPORT:-8000}}"
|
||||
[ -d "$etc_dir" ] || mkdir -p "$etc_dir"
|
||||
[ -d "$data_dir" ] || mkdir -p "$data_dir"
|
||||
[ -d "/var/log/aria2" ] || mkdir -p "/var/log/aria2"
|
||||
cp -Rf "$conf_dir/." "$etc_dir/"
|
||||
ln -sf "/dev/stdout" "/var/log/aria2/aria2.log"
|
||||
ln -sf "$conf_dir/aria2.session" "$etc_dir/aria2.session"
|
||||
__replace "ARIA_RPC_PORT" "$port" "$etc_dir/aria2.conf"
|
||||
if [ -f "/config/nginx/nginx.conf" ]; then
|
||||
__replace "127.0.0.1:.*/jsonrpc" "127.0.0.1:$port/jsonrpc" "/config/nginx/nginx.conf"
|
||||
fi
|
||||
if [ -f "$etc_dir/aria-ng.config.js" ]; then
|
||||
rm -Rf "$get_config"
|
||||
ln -sf "$etc_dir/aria-ng.config.js" "$get_config"
|
||||
ln -sf "$etc_dir/aria-ng.config.js" "$www_dir/js/aria-ng-f1dd57abb9.min.js"
|
||||
[ -n "$CONTAINER_IP_ADDRESS" ] && sed "s|127.0.0.1|0.0.0.0|g" "$etc_dir/aria-ng.config.js"
|
||||
__replace "127.0.0.1" "0.0.0.0" "$etc_dir/aria-ng.config.js"
|
||||
__replace "ARIA_RPC_PORT" "$port" "$etc_dir/aria-ng.config.js"
|
||||
fi
|
||||
if [ -n "$RPC_SECRET" ]; then
|
||||
echo "Changing rpc secret to $RPC_SECRET"
|
||||
@@ -58,6 +68,7 @@ __update_conf_files() {
|
||||
echo "rpc-secret=$RPC_SECRET" >>"$etc_dir/aria2.conf"
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -69,16 +80,21 @@ __update_ssl_conf() {
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run before executing
|
||||
__pre_execute() {
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && echo "$PRE_EXEC_MESSAGE"
|
||||
|
||||
return 0
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# script to start server
|
||||
__run_start_script() {
|
||||
local workdir="${WORKDIR:-$HOME}"
|
||||
local cmd="$EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
local user="${SERVICE_USER:-root}"
|
||||
local lc_type="${LC_ALL:-${LC_CTYPE:-$LANG}}"
|
||||
local home="${workdir//\/root/\/home\/docker}"
|
||||
local path="/usr/local/bin:/usr/bin:/bin:/usr/sbin"
|
||||
case "$1" in
|
||||
check) shift 1 && __pgrep $EXEC_CMD_BIN || return 5 ;;
|
||||
*) su_cmd $EXEC_CMD_BIN $EXEC_CMD_ARGS || return 10 ;;
|
||||
*) su_cmd env -i PWD="$home" HOME="$home" LC_CTYPE="$lc_type" PATH="$path" USER="$user" sh -c "$cmd" || return 10 ;;
|
||||
esac
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -122,46 +138,48 @@ fi
|
||||
# Change to working directory
|
||||
[ -n "$WORKDIR" ] && mkdir -p "$WORKDIR" && __cd "$WORKDIR" && echo "Changed to $PWD"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize ssl
|
||||
__update_ssl_conf
|
||||
__update_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run the pre execute commands
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && echo "$PRE_EXEC_MESSAGE"
|
||||
__pre_execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
WORKDIR="${WORKDIR:-}"
|
||||
if [ "$SERVICE_USER" = "root" ] || [ -z "$SERVICE_USER" ]; then
|
||||
su_cmd_bin="eval"
|
||||
su_cmd() { "$@" || return 1; }
|
||||
su_cmd() { eval "$@" || return 1; }
|
||||
elif [ "$(builtin type -P gosu)" ]; then
|
||||
su_cmd_bin="gosu $SERVICE_USER"
|
||||
su_cmd() { eval $su_cmd_bin "$@" || return 1; }
|
||||
su_cmd() { gosu $SERVICE_USER "$@" || return 1; }
|
||||
elif [ "$(builtin type -P runuser)" ]; then
|
||||
su_cmd_bin="runuser -u $SERVICE_USER"
|
||||
su_cmd() { eval $su_cmd_bin "$@" || return 1; }
|
||||
su_cmd() { runuser -u $SERVICE_USER "$@" || return 1; }
|
||||
elif [ "$(builtin type -P sudo)" ]; then
|
||||
su_cmd_bin="sudo -u $SERVICE_USER"
|
||||
su_cmd() { eval $su_cmd_bin "$@" || return 1; }
|
||||
su_cmd() { sudo -u $SERVICE_USER "$@" || return 1; }
|
||||
elif [ "$(builtin type -P su)" ]; then
|
||||
su_cmd_bin="su -s /bin/sh - $SERVICE_USER"
|
||||
su_cmd() { eval $su_cmd_bin -c "$@" || return 1; }
|
||||
su_cmd() { su -s /bin/sh - $SERVICE_USER -c "$@" || return 1; }
|
||||
else
|
||||
echo "Can not switch to $SERVICE_USER"
|
||||
exit 10
|
||||
echo "Can not switch to $SERVICE_USER: attempting to run as root"
|
||||
su_cmd() { eval "$@" || return 1; }
|
||||
fi
|
||||
if [ -n "$WORKDIR" ] && [ -n "$SERVICE_USER" ]; then
|
||||
if [ -n "$WORKDIR" ] && [ "${SERVICE_USER:-$USER}" != "root" ]; then
|
||||
echo "Fixing file permissions"
|
||||
su_cmd chown -Rf $SERVICE_USER $WORKDIR
|
||||
su_cmd chown -Rf $SERVICE_USER $WORKDIR $etc_dir $var_dir $log_dir
|
||||
fi
|
||||
if __pgrep $EXEC_CMD_BIN && [ -f "/run/init.d/$EXEC_CMD_BIN.pid" ]; then
|
||||
SERVICE_EXIT_CODE=1
|
||||
echo "$EXEC_CMD_BIN" is already running
|
||||
else
|
||||
echo "Starting service: $EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
su_cmd touch /run/init.d/$EXEC_CMD_BIN.pid
|
||||
__run_start_script "$@" |& tee -a "/tmp/entrypoint.log"
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "Failed to execute: $EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
SERVICE_EXIT_CODE=10 SERVICE_IS_RUNNING="false"
|
||||
su_cmd rm -Rf "/run/init.d/$EXEC_CMD_BIN.pid"
|
||||
fi
|
||||
fi
|
||||
echo "Starting service: $EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
export -f __run_start_script
|
||||
export SERVICE_IS_RUNNING="true"
|
||||
su_cmd "touch /run/init.d/$EXEC_CMD_BIN.pid"
|
||||
su_cmd __run_start_script "$@" || echo "Failed to execute: $EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
[ "$?" -ne 0 ] && SERVICE_IS_RUNNING="false" && SERVICE_EXIT_CODE=10 && rm -Rf "/run/init.d/$EXEC_CMD_BIN.pid"
|
||||
# su_cmd "$EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
||||
|
@@ -25,12 +25,13 @@ done
|
||||
WORKDIR="" # set working directory
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_USER="root" # execute command as another user
|
||||
SERVICE_PORT="${PORT:-6800}" # port which service is listening on
|
||||
SERVICE_PORT="${PORT:-80}" # port which service is listening on
|
||||
EXEC_CMD_BIN="nginx" # command to execute
|
||||
EXEC_CMD_ARGS="-c /etc/nginx/nginx.conf" # command arguments
|
||||
PRE_EXEC_MESSAGE="" # Show message before execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Other variables that are needed
|
||||
data_dir="/data"
|
||||
etc_dir="/etc/nginx"
|
||||
conf_dir="/config/nginx"
|
||||
www_dir="${WWW_ROOT_DIR:-/data/htdocs}"
|
||||
@@ -38,10 +39,13 @@ nginx_bin="$(type -P 'nginx')"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__update_conf_files() {
|
||||
[ -e "$etc_dir" ] && [ -n "$nginx_bin" ] || return 1
|
||||
echo "Initializing nginx web server in $conf_dir"
|
||||
mkdir -p "$data_dir/log/nginx"
|
||||
chmod -Rf 777 "$data_dir/log/nginx"
|
||||
[ -d "$etc_dir" ] || mkdir -p "$etc_dir"
|
||||
[ -d "$conf_dir" ] && cp -Rf "$conf_dir/." "$etc_dir/"
|
||||
ln -sf "/dev/stderr" "var/log/nginx/nginx.log"
|
||||
ln -sf "/dev/stdout" "/var/log/nginx/access.log"
|
||||
if [ "$SSL_ENABLED" = "true" ]; then
|
||||
__file_copy "$conf_dir/nginx.ssl.conf" "$etc_dir/nginx.conf"
|
||||
__file_copy "$conf_dir/vhosts.d/default.ssl.conf" "$etc_dir/vhosts.d/default.conf"
|
||||
@@ -50,20 +54,19 @@ __update_conf_files() {
|
||||
[ -f "$etc_dir/vhosts.d/default.ssl.conf" ] && rm -Rf "$etc_dir/vhosts.d/default.ssl.conf"
|
||||
#
|
||||
[ -d "$www_dir" ] || mkdir -p "$www_dir"
|
||||
[ -d "$www_dir/health" ] || mkdir -p "$www_dir/health"
|
||||
[ -f "$www_dir/health/index.txt" ] || echo 'ok' >"$www_dir/health/index.txt"
|
||||
[ -f "$www_dir/health/index.json" ] || echo '{ "status": "ok" }' >"$www_dir/health/index.json"
|
||||
[ -d "$www_dir/www/health" ] || mkdir -p "$www_dir/www/health"
|
||||
[ -f "$www_dir/www/health/index.txt" ] || echo 'ok' >"$www_dir/www/health/index.txt"
|
||||
[ -f "$www_dir/www/health/index.json" ] || echo '{ "status": "ok" }' >"$www_dir/www/health/index.json"
|
||||
#
|
||||
__replace "SERVER_PORT" "${SERVICE_PORT:-6800}" "$etc_dir/nginx.conf"
|
||||
[ -f "$www_dir/www/index.php" ] && __replace "SERVER_SOFTWARE" "nginx" "$www_dir/www/index.php"
|
||||
[ -f "$www_dir/www/index.html" ] && __replace "SERVER_SOFTWARE" "nginx" "$www_dir/www/index.html"
|
||||
__replace "SERVER_PORT" "${SERVICE_PORT:-80}" "$etc_dir/nginx.conf"
|
||||
__replace "SERVER_PORT" "${SERVICE_PORT:-80}" "$etc_dir/vhosts.d/nginx.conf"
|
||||
[ -f "$www_dir/www/index.php" ] && __replace "SERVER_SOFTWARE" "dns" "$www_dir/www/index.php"
|
||||
[ -f "$www_dir/www/index.html" ] && __replace "SERVER_SOFTWARE" "dns" "$www_dir/www/index.html"
|
||||
if [ -z "$PHP_BIN_DIR" ]; then
|
||||
[ -f "$www_dir/www/info.php" ] && echo "PHP support is not enabled" >"$www_dir/www/info.php"
|
||||
[ -f "$etc_dir/conf.d/php-fpm.conf" ] && echo "# PHP support is not enabled" >"$etc_dir/conf.d/php-fpm.conf"
|
||||
fi
|
||||
if grep -s -q "nginx:" "/etc/passwd"; then
|
||||
chown -Rf nginx:nginx "$etc_dir" "$www_dir"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -75,17 +78,22 @@ __update_ssl_conf() {
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run before executing
|
||||
__pre_execute() {
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && echo "$PRE_EXEC_MESSAGE"
|
||||
[ -d "/run/init.d" ] || { mkdir -p "/run/init.d" && chmod 777 "/run/init.d"; }
|
||||
grep -s -q "nginx:" "/etc/passwd" && chown -Rf nginx:nginx "$etc_dir" "$www_dir" "$data_dir/log/nginx"
|
||||
|
||||
return 0
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# script to start server
|
||||
__run_start_script() {
|
||||
local workdir="${WORKDIR:-$HOME}"
|
||||
local cmd="$EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
local user="${SERVICE_USER:-root}"
|
||||
local lc_type="${LC_ALL:-${LC_CTYPE:-$LANG}}"
|
||||
local home="${workdir//\/root/\/home\/docker}"
|
||||
local path="/usr/local/bin:/usr/bin:/bin:/usr/sbin"
|
||||
case "$1" in
|
||||
check) shift 1 && __pgrep $EXEC_CMD_BIN || return 5 ;;
|
||||
*) __pgrep $EXEC_CMD_BIN || su_cmd $EXEC_CMD_BIN $EXEC_CMD_ARGS || return 10 ;;
|
||||
*) su_cmd env -i PWD="$home" HOME="$home" LC_CTYPE="$lc_type" PATH="$path" USER="$user" sh -c "$cmd" || return 10 ;;
|
||||
esac
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -129,45 +137,48 @@ fi
|
||||
# Change to working directory
|
||||
[ -n "$WORKDIR" ] && mkdir -p "$WORKDIR" && __cd "$WORKDIR" && echo "Changed to $PWD"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize ssl
|
||||
__update_ssl_conf
|
||||
__update_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Updating config files
|
||||
__update_conf_files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run the pre execute commands
|
||||
[ -n "$PRE_EXEC_MESSAGE" ] && echo "$PRE_EXEC_MESSAGE"
|
||||
__pre_execute
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
WORKDIR="${WORKDIR:-}"
|
||||
if [ "$SERVICE_USER" = "root" ] || [ -z "$SERVICE_USER" ]; then
|
||||
su_cmd_bin="eval"
|
||||
su_cmd() { "$@" || return 1; }
|
||||
su_cmd() { eval "$@" || return 1; }
|
||||
elif [ "$(builtin type -P gosu)" ]; then
|
||||
su_cmd_bin="gosu $SERVICE_USER"
|
||||
su_cmd() { eval $su_cmd_bin "$@" || return 1; }
|
||||
su_cmd() { gosu $SERVICE_USER "$@" || return 1; }
|
||||
elif [ "$(builtin type -P runuser)" ]; then
|
||||
su_cmd_bin="runuser -u $SERVICE_USER"
|
||||
su_cmd() { eval $su_cmd_bin "$@" || return 1; }
|
||||
su_cmd() { runuser -u $SERVICE_USER "$@" || return 1; }
|
||||
elif [ "$(builtin type -P sudo)" ]; then
|
||||
su_cmd_bin="sudo -u $SERVICE_USER"
|
||||
su_cmd() { eval $su_cmd_bin "$@" || return 1; }
|
||||
su_cmd() { sudo -u $SERVICE_USER "$@" || return 1; }
|
||||
elif [ "$(builtin type -P su)" ]; then
|
||||
su_cmd_bin="su -s /bin/sh - $SERVICE_USER"
|
||||
su_cmd() { eval $su_cmd_bin -c "$@" || return 1; }
|
||||
su_cmd() { su -s /bin/sh - $SERVICE_USER -c "$@" || return 1; }
|
||||
else
|
||||
echo "Can not switch to $SERVICE_USER"
|
||||
exit 10
|
||||
echo "Can not switch to $SERVICE_USER: attempting to run as root"
|
||||
su_cmd() { eval "$@" || return 1; }
|
||||
fi
|
||||
if [ -n "$WORKDIR" ] && [ -n "$SERVICE_USER" ]; then
|
||||
if [ -n "$WORKDIR" ] && [ "${SERVICE_USER:-$USER}" != "root" ]; then
|
||||
echo "Fixing file permissions"
|
||||
su_cmd chown -Rf $SERVICE_USER $WORKDIR
|
||||
su_cmd chown -Rf $SERVICE_USER $WORKDIR $etc_dir $var_dir $log_dir
|
||||
fi
|
||||
if __pgrep $EXEC_CMD_BIN && [ -f "/run/init.d/$EXEC_CMD_BIN.pid" ]; then
|
||||
SERVICE_EXIT_CODE=1
|
||||
echo "$EXEC_CMD_BIN" is already running
|
||||
else
|
||||
echo "Starting service: $EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
su_cmd touch /run/init.d/$EXEC_CMD_BIN.pid
|
||||
__run_start_script "$@" |& tee -a "/tmp/entrypoint.log"
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "Failed to execute: $EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
SERVICE_EXIT_CODE=10 SERVICE_IS_RUNNING="false"
|
||||
su_cmd rm -Rf "/run/init.d/$EXEC_CMD_BIN.pid"
|
||||
fi
|
||||
fi
|
||||
echo "Starting service: $EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
export SERVICE_IS_RUNNING="true"
|
||||
su_cmd touch /run/init.d/$EXEC_CMD_BIN.pid
|
||||
__run_start_script "$@" || echo "Failed to execute: $EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
[ "$?" -ne 0 ] && SERVICE_IS_RUNNING="false" && SERVICE_EXIT_CODE=10 && rm -Rf "/run/init.d/$EXEC_CMD_BIN.pid"
|
||||
# su_cmd "$EXEC_CMD_BIN $EXEC_CMD_ARGS"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
||||
|
Reference in New Issue
Block a user