🗃️ Removed the .claude/settings.local.json 🗃️
Some checks failed
apprise / release-apprise (push) Has been cancelled

CLAUDE.md
Dockerfile
.env.scripts
.gitattributes
.gitea/workflows/docker.yaml
.gitignore
LICENSE.md
PLAN.md
README.md
rootfs/root/docker/setup/04-users.sh
rootfs/root/docker/setup/05-custom.sh
rootfs/tmp/
rootfs/usr/local/bin/entrypoint.sh
rootfs/usr/local/bin/pkmgr
rootfs/usr/local/etc/docker/bin/
rootfs/usr/local/etc/docker/init.d/99-apprise.sh
rootfs/usr/local/etc/docker/init.d/zz-default.sh
This commit is contained in:
casjay
2026-05-12 20:05:26 -04:00
parent ede71f9df1
commit 2c82e90b6f
19 changed files with 1720 additions and 887 deletions

View File

@@ -28,6 +28,15 @@ exitCode=0
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Predefined actions
# Defensive: the nginx Alpine package creates the nginx user. Apprise itself
# has no daemon user — we run as root and let gunicorn handle worker-level
# privilege drops via PUID/PGID env if the user wants. Add an apprise system
# user/group for /config/secure ownership.
if command -v addgroup >/dev/null 2>&1 && command -v adduser >/dev/null 2>&1; then
addgroup -S apprise 2>/dev/null || true
adduser -S -G apprise -H -h /var/lib/apprise -s /sbin/nologin apprise 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main script

View File

@@ -1,38 +1,124 @@
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202509161144-git
# @@Author : CasjaysDev
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
# @@License : MIT
# @@ReadME :
# @@Copyright : Copyright 2023 CasjaysDev
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
# @@File : 05-custom.sh
# @@Description : script to run custom
# casjaysdevdocker/apprise - 05-custom.sh
# 1. Wipe distro defaults under /etc/{nginx,apprise}/* and drop in our
# optimized configs from /tmp/etc/.
# 2. Clone the upstream apprise-api Django app to /usr/local/share/apprise-api.
# 3. pip install the Python deps Alpine doesn't ship.
# 4. Stage runtime dirs that the init.d scripts will need.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck shell=bash
# shellcheck disable=SC2016
# shellcheck disable=SC2031
# shellcheck disable=SC2120
# shellcheck disable=SC2155
# shellcheck disable=SC2199
# shellcheck disable=SC2317
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set bash options
set -o pipefail
set -e -o pipefail
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set env variables
exitCode=0
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Predefined actions
APPRISE_API_VERSION="${APPRISE_API_VERSION:-master}"
APPRISE_API_REPO="${APPRISE_API_REPO:-https://github.com/caronc/apprise-api}"
APPRISE_API_INSTALL_DIR="/usr/local/share/apprise-api"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main script
echo "Wiping distro defaults and installing optimized configs"
for svc in nginx apprise; do
src="/tmp/etc/$svc"
dst="/etc/$svc"
[ -d "$src" ] || continue
if [ "$svc" = "nginx" ]; then
# Preserve mime.types + fastcgi_params from the package; we don't ship them.
[ -f "$dst/mime.types" ] && cp -f "$dst/mime.types" "/tmp/${svc}_mime.types.preserve" || true
[ -f "$dst/fastcgi_params" ] && cp -f "$dst/fastcgi_params" "/tmp/${svc}_fastcgi_params.preserve" || true
[ -f "$dst/scgi_params" ] && cp -f "$dst/scgi_params" "/tmp/${svc}_scgi_params.preserve" || true
[ -f "$dst/uwsgi_params" ] && cp -f "$dst/uwsgi_params" "/tmp/${svc}_uwsgi_params.preserve" || true
[ -d "$dst/modules" ] && cp -Rf "$dst/modules" "/tmp/${svc}_modules.preserve" || true
fi
rm -Rf "$dst"/*
mkdir -p "$dst"
cp -Rf "$src/." "$dst/"
if [ "$svc" = "nginx" ]; then
[ -f "/tmp/${svc}_mime.types.preserve" ] && mv -f "/tmp/${svc}_mime.types.preserve" "$dst/mime.types"
[ -f "/tmp/${svc}_fastcgi_params.preserve" ] && mv -f "/tmp/${svc}_fastcgi_params.preserve" "$dst/fastcgi_params"
[ -f "/tmp/${svc}_scgi_params.preserve" ] && mv -f "/tmp/${svc}_scgi_params.preserve" "$dst/scgi_params"
[ -f "/tmp/${svc}_uwsgi_params.preserve" ] && mv -f "/tmp/${svc}_uwsgi_params.preserve" "$dst/uwsgi_params"
[ -d "/tmp/${svc}_modules.preserve" ] && cp -Rf "/tmp/${svc}_modules.preserve" "$dst/modules" && rm -Rf "/tmp/${svc}_modules.preserve"
fi
mkdir -p "/usr/local/share/template-files/config/$svc"
cp -Rf "$dst/." "/usr/local/share/template-files/config/$svc/"
done
echo "Installing apprise-api from prebundled source tarball"
# Tarball is shipped in rootfs/tmp/apprise-src/ (downloaded on host pre-build)
# because the buildx build environment intermittently fails SSL validation
# against github.com. The host download is in .gitignore.
APPRISE_API_TARBALL="/tmp/apprise-src/apprise-api.tar.gz"
if [ ! -f "$APPRISE_API_TARBALL" ]; then
echo "Apprise-api source tarball missing at $APPRISE_API_TARBALL" >&2
echo "Run 'curl -fsSL -o rootfs/tmp/apprise-src/apprise-api.tar.gz \\" >&2
echo " https://github.com/caronc/apprise-api/archive/refs/heads/master.tar.gz' on the host first." >&2
exit 12
fi
mkdir -p "$(dirname "$APPRISE_API_INSTALL_DIR")"
rm -Rf "$APPRISE_API_INSTALL_DIR" /tmp/apprise-api-extract
mkdir -p /tmp/apprise-api-extract
tar -xzf "$APPRISE_API_TARBALL" -C /tmp/apprise-api-extract/
SRC_DIR="$(find /tmp/apprise-api-extract -mindepth 1 -maxdepth 1 -type d -name 'apprise-api-*' | head -1)"
if [ -z "$SRC_DIR" ] || [ ! -d "$SRC_DIR" ]; then
echo "Tarball extracted but no apprise-api-* dir found" >&2
ls -la /tmp/apprise-api-extract >&2
exit 13
fi
mv "$SRC_DIR" "$APPRISE_API_INSTALL_DIR"
rm -Rf /tmp/apprise-api-extract
# Upstream layout (verified at master):
# repo-root/
# manage.py (launcher; adds apprise_api/ to sys.path)
# apprise_api/ <-- the actual Django app: core/, api/, static/, etc/, gunicorn.conf.py
# Upstream Dockerfile does `COPY apprise_api/ webapp` — i.e. the *inner* dir
# becomes "webapp". We mirror that by symlinking apprise_api -> webapp so
# /usr/local/share/apprise-api/webapp/{core,static,gunicorn.conf.py,etc} all
# resolve correctly.
if [ -d "$APPRISE_API_INSTALL_DIR/apprise_api" ] && [ ! -e "$APPRISE_API_INSTALL_DIR/webapp" ]; then
ln -sf "apprise_api" "$APPRISE_API_INSTALL_DIR/webapp"
fi
# Sanity check
if [ ! -f "$APPRISE_API_INSTALL_DIR/webapp/manage.py" ] && [ ! -f "$APPRISE_API_INSTALL_DIR/webapp/gunicorn.conf.py" ]; then
echo "Apprise-API layout unexpected: webapp/gunicorn.conf.py missing after symlink" >&2
ls -la "$APPRISE_API_INSTALL_DIR" "$APPRISE_API_INSTALL_DIR/webapp" 2>&1 | head -40 >&2
exit 11
fi
# Patch gunicorn.conf.py: change socket path to our /run/apprise location, and
# fix the hard-coded pythonpath that upstream points at /opt/apprise/webapp.
GUNICORN_CONF="$APPRISE_API_INSTALL_DIR/webapp/gunicorn.conf.py"
if [ -f "$GUNICORN_CONF" ]; then
sed -i 's|/tmp/apprise/gunicorn.sock|/run/apprise/gunicorn.sock|g' "$GUNICORN_CONF"
sed -i 's|/opt/apprise/webapp|/usr/local/share/apprise-api/webapp|g' "$GUNICORN_CONF"
echo "Patched gunicorn.conf.py: $GUNICORN_CONF"
fi
echo "Installing Python deps not in Alpine"
pip3 install --no-cache-dir --break-system-packages \
apprise PGPy slixmpp smpplib gntp || \
pip3 install --no-cache-dir \
apprise PGPy slixmpp smpplib gntp
# Install the rest of upstream's requirements.txt (defensive; most are already
# satisfied by our Alpine packages or the explicit pip list above).
if [ -f "$APPRISE_API_INSTALL_DIR/requirements.txt" ]; then
pip3 install --no-cache-dir --break-system-packages \
-r "$APPRISE_API_INSTALL_DIR/requirements.txt" 2>/dev/null || \
pip3 install --no-cache-dir \
-r "$APPRISE_API_INSTALL_DIR/requirements.txt" 2>/dev/null || true
fi
echo "Creating runtime dirs"
mkdir -p /run/apprise /tmp/apprise /var/log/nginx \
/usr/local/share/template-files/config/apprise \
/usr/local/share/template-files/config/nginx
chmod 1777 /tmp/apprise
# Drop a sample apprise YAML into the template-files seed dir so first-run lands one.
if [ -f /tmp/etc/apprise/apprise.yml.sample ]; then
cp -f /tmp/etc/apprise/apprise.yml.sample /usr/local/share/template-files/config/apprise/
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the exit code
#exitCode=$?
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exit $exitCode

View File

@@ -0,0 +1,17 @@
# Sample apprise YAML configuration.
# Copy/rename to /config/apprise/store/<key>.yml then POST to
# http://<container-host>:8000/notify/<key> -d 'body=hello&title=test'
#
# Two equivalent formats are supported:
# - TEXT: one URL per line in /config/apprise/store/<key>.cfg
# - YAML: structured (this file)
#
# See https://github.com/caronc/apprise/wiki for the full URL syntax.
urls:
# - mailto://user:password@gmail.com
# - tgram://botid/chatid
# - discord://webhook_id/webhook_token
# - slack://TokenA/TokenB/TokenC
# - pover://user@token
# - json://localhost

View File

@@ -0,0 +1,2 @@
# Placeholder for distro-style /etc/nginx/conf.d.
# Apprise itself includes /config/apprise/conf.d/*.conf for user overrides.

View File

@@ -0,0 +1,263 @@
# casjaysdevdocker/apprise - nginx.conf
# Based on upstream caronc/apprise-api/webapp/etc/nginx.conf, adapted to our paths.
# Runs in foreground (daemon off) under the start-apprise wrapper.
daemon off;
worker_processes auto;
pid /run/apprise/nginx.pid;
error_log /data/logs/apprise/nginx-error.log error;
events {
worker_connections 4096;
}
http {
# Upstream gunicorn (started by start-apprise)
upstream apprise_upstream {
server unix:/run/apprise/gunicorn.sock max_fails=0;
keepalive 16;
}
# Basic Settings
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
# Upload Restriction
client_max_body_size 500M;
# Logging
access_log /data/logs/apprise/nginx-access.log;
# Centralize tmp paths so a tmpfs mount on /tmp works cleanly
client_body_temp_path /tmp/apprise/nginx_client_temp 1 2;
proxy_temp_path /tmp/apprise/nginx_proxy_temp 1 2;
fastcgi_temp_path /tmp/apprise/nginx_fastcgi_temp 1 2;
uwsgi_temp_path /tmp/apprise/nginx_uwsgi_temp 1 2;
scgi_temp_path /tmp/apprise/nginx_scgi_temp 1 2;
# Gzip
gzip on;
gzip_proxied any;
gzip_vary on;
gzip_min_length 1024;
gzip_types application/json text/plain text/css application/javascript text/xml application/xml;
# Host config
client_body_buffer_size 256k;
client_body_in_file_only off;
# Retry cushions
proxy_next_upstream error timeout http_502 http_503 http_504;
proxy_next_upstream_tries 2;
# Rate limits for /status and /metrics
limit_req_zone $binary_remote_addr zone=status:10m rate=5r/s;
server {
listen 8000;
listen [::]:8000;
# Error handling
proxy_intercept_errors on;
error_page 404 = /_/404/;
error_page 500 = /_/50x/;
error_page 502 503 504 /50x.html;
#
# 1. Welcome page
#
location = / {
proxy_pass http://apprise_upstream;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Transfer-Encoding "";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s;
}
#
# 2. Stateless notify
#
location = /notify {
proxy_pass http://apprise_upstream;
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Transfer-Encoding "";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Expect $http_expect;
client_max_body_size 500M;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
}
#
# 3. Stateful notify with key
#
location ~ "^/notify/[\w_-]{1,128}/?$" {
proxy_pass http://apprise_upstream;
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Transfer-Encoding "";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Expect $http_expect;
client_max_body_size 500M;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
}
#
# 4. Health check / metrics
#
location ~ "^/(status|metrics)/?$" {
rewrite ^/status/?$ /status/ break;
rewrite ^/metrics/$ /metrics break;
proxy_pass http://apprise_upstream;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Transfer-Encoding "";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 1s;
proxy_send_timeout 2s;
proxy_read_timeout 2s;
proxy_buffering off;
access_log off;
limit_req zone=status burst=10 nodelay;
add_header Cache-Control "no-store" always;
}
#
# 5. Service discovery and metadata
#
location ~ "^/(details|json/urls/[\w_-]{1,128})/?$" {
proxy_pass http://apprise_upstream;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Transfer-Encoding "";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s;
}
#
# 6. Config list view: GET /cfg
#
location = /cfg {
proxy_pass http://apprise_upstream;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Transfer-Encoding "";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s;
}
#
# 7. Django Error pages
#
location /_/ {
proxy_intercept_errors off;
proxy_pass http://apprise_upstream;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Transfer-Encoding "";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s;
access_log off;
}
#
# 8. Config management (HTML UI + API)
#
location ~ "^/(cfg|add|del|get)/[\w_-]{1,128}/?$" {
proxy_pass http://apprise_upstream;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Transfer-Encoding "";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 300s;
}
#
# 9. Static content (apprise-api ships static files under webapp/static/)
# Serve /s/ from the bundled static dir.
#
location /s/ {
alias /usr/local/share/apprise-api/webapp/static/;
index index.html;
}
#
# 10. favicon
#
location = /favicon.ico {
alias /usr/local/share/apprise-api/webapp/static/favicon.ico;
access_log off;
log_not_found off;
}
#
# 11. robots.txt
#
location = /robots.txt {
access_log off;
log_not_found off;
default_type text/plain;
return 200 "User-agent: *\nDisallow: /\n";
}
#
# 12. Catch-all
#
location / {
proxy_pass http://apprise_upstream;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Transfer-Encoding "";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Optional user-supplied location overrides
include /config/apprise/conf.d/*.conf;
}
}

View File

@@ -1,13 +1,13 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202511301623-git
##@Version : 202602061352-git
# @@Author : Jason Hempstead
# @@Contact : jason@casjaysdev.pro
# @@License : WTFPL
# @@ReadME : entrypoint.sh --help
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
# @@Created : Sunday, Nov 30, 2025 16:23 EST
# @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments
# @@Created : Tuesday, May 05, 2026 14:38 EDT
# @@File : entrypoint.sh
# @@Description : Entrypoint file for apprise
# @@Changelog : New script
@@ -32,7 +32,7 @@ PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
# Set bash options
SCRIPT_FILE="$0"
CONTAINER_NAME="apprise"
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
SCRIPT_NAME="${SCRIPT_FILE##*/}"
CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}"
# - - - - - - - - - - - - - - - - - - - - - - - - -
# remove whitespaces from beginning argument
@@ -73,30 +73,38 @@ done
unset set_env
# - - - - - - - - - - - - - - - - - - - - - - - - -
# User to use to launch service - IE: postgres
RUNAS_USER="root" # normally root
# normally root
RUNAS_USER="root"
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Set user and group from env
SERVICE_USER="${PUID:-$SERVICE_USER}"
SERVICE_GROUP="${PGID:-$SERVICE_GROUP}"
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Set user and group ID
SERVICE_UID="${SERVICE_UID:-0}" # set the user id
SERVICE_GID="${SERVICE_GID:-0}" # set the group id
# set the user id
SERVICE_UID="${SERVICE_UID:-0}"
# set the group id
SERVICE_GID="${SERVICE_GID:-0}"
# - - - - - - - - - - - - - - - - - - - - - - - - -
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
#SERVICE_USER="${SERVICE_USER:-apprise}" # execute command as another user
#SERVICE_GROUP="${SERVICE_GROUP:-apprise}" # Set the service group
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Secondary ports
SERVER_PORTS="" # specifiy other ports
# specifiy other ports
SERVER_PORTS=""
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Primary server port- will be added to server ports
WEB_SERVER_PORT="" # port : 80,443
# port : 80,443
WEB_SERVER_PORT=""
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Healthcheck variables
HEALTH_ENABLED="yes" # enable healthcheck [yes/no]
SERVICES_LIST="tini" # comma separated list of processes for the healthcheck
HEALTH_ENDPOINTS="" # url endpoints: [http://localhost/health,http://localhost/test]
# enable healthcheck [yes/no]
HEALTH_ENABLED="yes"
# comma separated list of processes for the healthcheck
SERVICES_LIST="tini"
# url endpoints: [http://localhost/health,http://localhost/test]
HEALTH_ENDPOINTS=""
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Update path var
export PATH RUNAS_USER SERVICE_USER SERVICE_GROUP SERVICE_UID SERVICE_GID WWW_ROOT_DIR DATABASE_DIR
@@ -162,28 +170,40 @@ export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has
export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}"
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then
www_temp_dir="/tmp/git/$(basename -- "$CONTAINER_WEB_SERVER_WWW_REPO")"
rm -Rf "${WWW_ROOT_DIR:?}"/* "${www_temp_dir:?}"/*
mkdir -p "$WWW_ROOT_DIR" "$www_temp_dir"
git clone -q "$CONTAINER_WEB_SERVER_WWW_REPO" "$www_temp_dir" 2>/dev/null
rm -Rf "$www_temp_dir/.git" "$www_temp_dir"/.git*
rsync -ra "$www_temp_dir/" "$WWW_ROOT_DIR" --delete >/dev/null 2>&1
rm -Rf "$www_temp_dir"
www_temp_dir="/tmp/git/${CONTAINER_WEB_SERVER_WWW_REPO##*/}"
rm -Rf "${WWW_ROOT_DIR:?}"/* "${www_temp_dir:?}"/* 2>/dev/null || true
mkdir -p "$WWW_ROOT_DIR" "$www_temp_dir" 2>/dev/null || true
git clone -q "$CONTAINER_WEB_SERVER_WWW_REPO" "$www_temp_dir" 2>/dev/null || true
rm -Rf "$www_temp_dir/.git" "$www_temp_dir"/.git* 2>/dev/null || true
rsync -ra "$www_temp_dir/" "$WWW_ROOT_DIR" --delete 2>/dev/null || true
rm -Rf "$www_temp_dir" 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# variables based on env/files
[ -f "/config/enable/ssl" ] && SSL_ENABLED="yes"
[ -f "/config/enable/ssh" ] && SSH_ENABLED="yes"
[ "$WEB_SERVER_PORT" = "443" ] && SSL_ENABLED="yes"
[ "$CONTAINER_WEB_SERVER_PROTOCOL" = "https" ] && SSL_ENABLED="yes"
if [ -f "/config/enable/ssl" ]; then SSL_ENABLED="yes"; fi
if [ -f "/config/enable/ssh" ]; then SSH_ENABLED="yes"; fi
if [ "$WEB_SERVER_PORT" = "443" ]; then SSL_ENABLED="yes"; fi
if [ "$CONTAINER_WEB_SERVER_PROTOCOL" = "https" ]; then SSL_ENABLED="yes"; fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# export variables
# - - - - - - - - - - - - - - - - - - - - - - - - -
# is already Initialized
[ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="yes" || DATA_DIR_INITIALIZED="no"
[ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="yes" || CONFIG_DIR_INITIALIZED="no"
{ [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; } && ENTRYPOINT_FIRST_RUN="no" || ENTRYPOINT_FIRST_RUN="yes"
if [ -f "$ENTRYPOINT_DATA_INIT_FILE" ]; then
DATA_DIR_INITIALIZED="yes"
else
DATA_DIR_INITIALIZED="no"
fi
if [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ]; then
CONFIG_DIR_INITIALIZED="yes"
else
CONFIG_DIR_INITIALIZED="no"
fi
if [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; then
ENTRYPOINT_FIRST_RUN="no"
else
ENTRYPOINT_FIRST_RUN="yes"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# clean ENV_PORTS variables
ENV_PORTS="${ENV_PORTS//,/ }" #
@@ -207,168 +227,236 @@ ENV_PORTS="$(__format_variables "$SERVER_PORTS" "$WEB_SERVER_PORTS" "$ENV_PORTS"
HEALTH_ENDPOINTS="${HEALTH_ENDPOINTS//,/ }"
# - - - - - - - - - - - - - - - - - - - - - - - - -
# create required directories
mkdir -p "/run"
mkdir -p "/tmp"
mkdir -p "/root"
mkdir -p "/var/run"
mkdir -p "/var/tmp"
mkdir -p "/run/cron"
mkdir -p "/data/logs"
mkdir -p "/run/init.d"
mkdir -p "/config/enable"
mkdir -p "/config/secure"
mkdir -p "/usr/local/etc/docker/exec"
mkdir -p "/run" 2>/dev/null || true
mkdir -p "/tmp" 2>/dev/null || true
mkdir -p "/root" 2>/dev/null || true
mkdir -p "/var/run" 2>/dev/null || true
mkdir -p "/var/tmp" 2>/dev/null || true
mkdir -p "/run/cron" 2>/dev/null || true
mkdir -p "/data/logs" 2>/dev/null || true
mkdir -p "/run/init.d" 2>/dev/null || true
mkdir -p "/config/enable" 2>/dev/null || true
mkdir -p "/config/secure" 2>/dev/null || true
mkdir -p "/usr/local/etc/docker/exec" 2>/dev/null || true
# - - - - - - - - - - - - - - - - - - - - - - - - -
# create required files
touch "/data/logs/start.log"
touch "/data/logs/entrypoint.log"
touch "/data/logs/start.log" 2>/dev/null || true
touch "/data/logs/entrypoint.log" 2>/dev/null || true
# - - - - - - - - - - - - - - - - - - - - - - - - -
# fix permissions
chmod -f 777 "/run"
chmod -f 777 "/tmp"
chmod -f 700 "/root"
chmod -f 777 "/var/run"
chmod -f 777 "/var/tmp"
chmod -f 777 "/run/cron"
chmod -f 777 "/data/logs"
chmod -f 777 "/run/init.d"
chmod -f 777 "/config/enable"
chmod -f 777 "/config/secure"
chmod -f 777 "/data/logs/entrypoint.log"
chmod -f 777 "/usr/local/etc/docker/exec"
chmod -f 777 "/run" 2>/dev/null || true
chmod -f 777 "/tmp" 2>/dev/null || true
chmod -f 700 "/root" 2>/dev/null || true
chmod -f 777 "/var/run" 2>/dev/null || true
chmod -f 777 "/var/tmp" 2>/dev/null || true
chmod -f 777 "/run/cron" 2>/dev/null || true
chmod -f 777 "/data/logs" 2>/dev/null || true
chmod -f 777 "/run/init.d" 2>/dev/null || true
chmod -f 777 "/config/enable" 2>/dev/null || true
chmod -f 777 "/config/secure" 2>/dev/null || true
chmod -f 777 "/data/logs/entrypoint.log" 2>/dev/null || true
chmod -f 777 "/usr/local/etc/docker/exec" 2>/dev/null || true
# - - - - - - - - - - - - - - - - - - - - - - - - -
# lets ensure everyone can write to std*
[ -f "/dev/stdin" ] && chmod -f 777 "/dev/stdin"
[ -f "/dev/stderr" ] && chmod -f 777 "/dev/stderr"
[ -f "/dev/stdout" ] && chmod -f 777 "/dev/stdout"
if [ -f "/dev/stdin" ]; then
chmod -f 777 "/dev/stdin" 2>/dev/null || true
fi
if [ -f "/dev/stderr" ]; then
chmod -f 777 "/dev/stderr" 2>/dev/null || true
fi
if [ -f "/dev/stdout" ]; then
chmod -f 777 "/dev/stdout" 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
cat <<EOF | tee /etc/profile.d/locales.shadow /etc/profile.d/locales.sh >/dev/null
cat <<EOF 2>/dev/null | tee /etc/profile.d/locales.shadow /etc/profile.d/locales.sh >/dev/null 2>&1 || true
export LANG="\${LANG:-C.UTF-8}"
export LC_ALL="\${LANG:-C.UTF-8}"
export TZ="\${TZ:-\${TIMEZONE:-America/New_York}}"
EOF
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Create the backup dir
[ -n "$BACKUP_DIR" ] && { [ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"; }
if [ -n "$BACKUP_DIR" ]; then
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p "$BACKUP_DIR" 2>/dev/null || true
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$ENTRYPOINT_INIT_FILE" ]; then
ENTRYPOINT_MESSAGE="no" ENTRYPOINT_FIRST_RUN="no"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
# Show start message
if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then
[ "$ENTRYPOINT_MESSAGE" = "yes" ] && echo "Executing entrypoint script for apprise"
if [ "$ENTRYPOINT_MESSAGE" = "yes" ]; then
echo "Executing entrypoint script for apprise"
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Set reusable variables
{ { [ -w "/etc" ] && [ ! -f "/etc/hosts" ]; } || [ -w "/etc/hosts" ]; } && UPDATE_FILE_HOSTS="yes" && touch "/etc/hosts"
{ { [ -w "/etc" ] && [ ! -f "/etc/timezone" ]; } || [ -w "/etc/timezone" ]; } && UPDATE_FILE_TZ="yes" && touch "/etc/timezone"
{ { [ -w "/etc" ] && [ ! -f "/etc/resolv.conf" ]; } || [ -w "/etc/resolv.conf" ]; } && UPDATE_FILE_RESOLV="yes" && touch "/etc/resolv.conf"
if [ -w "/etc" ] && [ ! -f "/etc/hosts" ]; then
UPDATE_FILE_HOSTS="yes"
touch "/etc/hosts"
elif [ -w "/etc/hosts" ]; then
UPDATE_FILE_HOSTS="yes"
touch "/etc/hosts"
fi
if [ -w "/etc" ] && [ ! -f "/etc/timezone" ]; then
UPDATE_FILE_TZ="yes"
touch "/etc/timezone"
elif [ -w "/etc/timezone" ]; then
UPDATE_FILE_TZ="yes"
touch "/etc/timezone"
fi
if [ -w "/etc" ] && [ ! -f "/etc/resolv.conf" ]; then
UPDATE_FILE_RESOLV="yes"
touch "/etc/resolv.conf"
elif [ -w "/etc/resolv.conf" ]; then
UPDATE_FILE_RESOLV="yes"
touch "/etc/resolv.conf"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Set timezone
[ -n "$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && echo "$TZ" >"/etc/timezone"
[ -f "/usr/share/zoneinfo/$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && ln -sf "/usr/share/zoneinfo/$TZ" "/etc/localtime"
if [ -n "$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ]; then
echo "$TZ" >"/etc/timezone" 2>/dev/null || true
fi
if [ -f "/usr/share/zoneinfo/$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ]; then
ln -sf "/usr/share/zoneinfo/$TZ" "/etc/localtime" 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# if ipv6 add it to /etc/hosts
if [ "$UPDATE_FILE_HOSTS" = "yes" ]; then
echo "# known hostname mappings" >"/etc/hosts"
echo "# known hostname mappings" >"/etc/hosts" 2>/dev/null || true
if [ -n "$(ip a 2>/dev/null | grep 'inet6.*::' || ifconfig 2>/dev/null | grep 'inet6.*::')" ]; then
__printf_space "40" "::1" "localhost" >>"/etc/hosts"
__printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts"
__printf_space "40" "::1" "localhost" >>"/etc/hosts" 2>/dev/null || true
__printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts" 2>/dev/null || true
else
__printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts"
__printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts" 2>/dev/null || true
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# add .internal domain
if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ -n "$HOSTNAME" ]; then
__grep_test " $HOSTNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "$HOSTNAME" >>"/etc/hosts"
__grep_test " ${HOSTNAME%%.*}.internal" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.internal" >>"/etc/hosts"
if ! __grep_test " $HOSTNAME" "/etc/hosts"; then
__printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "$HOSTNAME" >>"/etc/hosts" 2>/dev/null || true
fi
if ! __grep_test " ${HOSTNAME%%.*}.internal" "/etc/hosts"; then
__printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.internal" >>"/etc/hosts" 2>/dev/null || true
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# add domainname
if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ "$DOMAINNAME" != "internal" ] && [ -n "$DOMAINNAME" ] && [ "$HOSTNAME.$DOMAINNAME" != "$DOMAINNAME" ]; then
__grep_test " ${HOSTNAME%%.*}.$DOMAINNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.$DOMAINNAME" >>"/etc/hosts"
if ! __grep_test " ${HOSTNAME%%.*}.$DOMAINNAME" "/etc/hosts"; then
__printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.$DOMAINNAME" >>"/etc/hosts" 2>/dev/null || true
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Set containers hostname
[ -n "$HOSTNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME" >"/etc/hostname"
if [ -n "$HOSTNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ]; then
echo "$HOSTNAME" >"/etc/hostname" 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "/etc/hostname" ]; then
[ -n "$(type -P hostname)" ] && hostname -F "/etc/hostname" &>/dev/null || HOSTNAME="$(<"/etc/hostname")"
if [ -n "$(type -P hostname 2>/dev/null)" ]; then
hostname -F "/etc/hostname" 2>/dev/null || true
else
HOSTNAME="$(<"/etc/hostname")" 2>/dev/null || true
fi
export HOSTNAME
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# import hosts file into container
[ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && cat "/usr/local/etc/hosts" | grep -vF "$HOSTNAME" >>"/etc/hosts"
if [ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ]; then
grep -vF "$HOSTNAME" "/usr/local/etc/hosts" 2>/dev/null >>"/etc/hosts" 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# import resolv.conf file into container
[ "$CUSTOM_DNS" != "yes" ] && [ -f "/usr/local/etc/resolv.conf" ] && [ "$UPDATE_FILE_RESOLV" = "yes" ] && cat "/usr/local/etc/resolv.conf" >"/etc/resolv.conf"
if [ "$CUSTOM_DNS" != "yes" ] && [ -f "/usr/local/etc/resolv.conf" ] && [ "$UPDATE_FILE_RESOLV" = "yes" ]; then
cat "/usr/local/etc/resolv.conf" >"/etc/resolv.conf" 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -n "$HOME" ] && [ -d "/usr/local/etc/skel" ]; then
[ -d "$HOME" ] && cp -Rf "/usr/local/etc/skel/." "$HOME/"
if [ -d "$HOME" ]; then
cp -Rf "/usr/local/etc/skel/." "$HOME/" 2>/dev/null || true
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Delete any .gitkeep files
[ -d "/data" ] && rm -Rf "/data/.gitkeep" "/data"/*/*.gitkeep
[ -d "/config" ] && rm -Rf "/config/.gitkeep" "/config"/*/*.gitkeep
[ -f "/usr/local/bin/.gitkeep" ] && rm -Rf "/usr/local/bin/.gitkeep"
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup bin directory - /config/bin > /usr/local/bin
__initialize_custom_bin_dir
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy default system configs - /usr/local/share/template-files/defaults > /config/
__initialize_default_templates
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy custom config files - /usr/local/share/template-files/config > /config/
__initialize_config_dir
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy custom data files - /usr/local/share/template-files/data > /data/
__initialize_data_dir
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_ssl_certs
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$ENTRYPOINT_INIT_FILE" ]; then
ENTRYPOINT_FIRST_RUN="no"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/config" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if this is a new container
if [ -f "$ENTRYPOINT_DATA_INIT_FILE" ]; then
DATA_DIR_INITIALIZED="yes"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/data" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE"
rm -Rf "/data/.gitkeep" "/data"/*/*.gitkeep 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ]; then
CONFIG_DIR_INITIALIZED="yes"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/config" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE"
rm -Rf "/config/.gitkeep" "/config"/*/*.gitkeep 2>/dev/null || true
fi
if [ -f "/usr/local/bin/.gitkeep" ]; then
rm -Rf "/usr/local/bin/.gitkeep" 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
# Only run initialization on first run or when directories are not initialized
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ] || [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup bin directory - /config/bin > /usr/local/bin
__initialize_custom_bin_dir
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy default system configs - /usr/local/share/template-files/defaults > /config/
if [ "$CONFIG_DIR_INITIALIZED" = "no" ]; then
__initialize_default_templates
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy custom config files - /usr/local/share/template-files/config > /config/
if [ "$CONFIG_DIR_INITIALIZED" = "no" ]; then
__initialize_config_dir
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy custom data files - /usr/local/share/template-files/data > /data/
if [ "$DATA_DIR_INITIALIZED" = "no" ]; then
__initialize_data_dir
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Initialize SSL certificates
__initialize_ssl_certs
# - - - - - - - - - - - - - - - - - - - - - - - - -
# Mark directories as initialized (only write if not already initialized)
if [ -d "/config" ] && [ "$CONFIG_DIR_INITIALIZED" = "no" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE" 2>/dev/null || true
CONFIG_DIR_INITIALIZED="yes"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/data" ] && [ "$DATA_DIR_INITIALIZED" = "no" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE" 2>/dev/null || true
DATA_DIR_INITIALIZED="yes"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/config" ] && [ ! -f "$ENTRYPOINT_INIT_FILE" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE" 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# setup the smtp server
__setup_mta
# - - - - - - - - - - - - - - - - - - - - - - - - -
ENTRYPOINT_FIRST_RUN="no"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
# if no pid assume container restart - clean stale files on restart
if [ -f "$ENTRYPOINT_PID_FILE" ]; then
START_SERVICES="no"
touch "$ENTRYPOINT_PID_FILE"
# Check if the PID in the file is still running
entrypoint_pid=$(cat "$ENTRYPOINT_PID_FILE" 2>/dev/null || echo "")
if [ -n "$entrypoint_pid" ] && kill -0 "$entrypoint_pid" 2>/dev/null; then
# Process is still running, don't restart services
START_SERVICES="no"
touch "$ENTRYPOINT_PID_FILE"
else
# PID file exists but process is dead - this is a restart
START_SERVICES="yes"
# Clean any stale PID files on restart
rm -f /run/__start_init_scripts.pid /run/init.d/*.pid /run/*.pid 2>/dev/null || true
fi
else
START_SERVICES=yes
# Clean any stale PID files on first run
rm -f /run/.start_init_scripts.pid /run/init.d/*.pid /run/*.pid 2>/dev/null || true
rm -f /run/__start_init_scripts.pid /run/init.d/*.pid /run/*.pid 2>/dev/null || true
fi
# - - - - - - - - - - - - - - - - - - - - - - - - -
[ "$ENTRYPOINT_MESSAGE" = "yes" ] && __printf_space "40" "The containers ip address is:" "$CONTAINER_IP4_ADDRESS"
@@ -411,6 +499,9 @@ if [ "$START_SERVICES" = "yes" ] || [ -z "$1" ]; then
echo "$$" >"$ENTRYPOINT_PID_FILE"
__start_init_scripts "/usr/local/etc/docker/init.d"
CONTAINER_INIT="${CONTAINER_INIT:-no}"
# Services started successfully - enter monitoring mode
__no_exit
exit $?
fi
START_SERVICES="no"
fi
@@ -420,7 +511,7 @@ export START_SERVICES CONTAINER_INIT ENTRYPOINT_PID_FILE
case "$1" in
init)
shift 1
echo "Container has been Initialized"
__log_info "Container has been initialized"
exit 0
;;
tail)
@@ -451,7 +542,7 @@ logs)
clean)
log_files="$(find "/data/logs" -type f)"
for log in "${log_files[@]}"; do
echo "clearing $log"
__log_info "Clearing log file: $log"
printf '' >$log
done
;;
@@ -464,7 +555,7 @@ logs)
cron)
shift 1
__cron "$@" &
echo "cron script is running with pid: $!"
__log_info "Cron script is running with PID: $!"
exit
;;
# backup data and config dirs
@@ -492,7 +583,7 @@ healthcheck)
[ "$healthEnabled" = "yes" ] || exit 0
if [ -d "/run/healthcheck" ] && [ "$(ls -A "/run/healthcheck" | wc -l)" -ne 0 ]; then
for service in /run/healthcheck/*; do
name=$(basename -- $service)
name="${service##*/}"
services+="$name "
done
fi

View File

@@ -1,10 +1,10 @@
#!/usr/bin/env sh
# shellcheck shell=sh
# shellcheck disable=SC2016
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
USER_UID="$(id -u)"
USER_GID="$(id -g)"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -x "$(command -v apt 2>/dev/null)" ]; then
export DEBIAN_FRONTEND=noninteractive
pkmgr_cmd="apt"
@@ -58,7 +58,7 @@ else
pkmgr_update_cmd="$pkmgr_cmd"
pkmgr_install_cmd="$pkmgr_cmd"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "/config/pkmgr/settings.conf" ]; then
. "/config/pkmgr/settings.conf"
elif [ -f "/etc/pkmgr/settings.conf" ]; then
@@ -73,9 +73,9 @@ pkmgr_install_cmd="$pkmgr_install_cmd"
pkmgr_mkcache_cmd="$pkmgr_mkcache_cmd"
EEOF
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
[ -n "$pkmgr_cmd" ] || { echo "Can not determine the package manager" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
case "$1" in
pip)
shift 1
@@ -103,7 +103,7 @@ install)
[ -n "$1" ] || exit 0
[ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_install_cmd="sudo $pkmgr_install_cmd"
if [ -f "$1" ]; then
install_list="$(cat "$1")"
install_list="$(tr '\n' ' ' < "$1")"
else
install_list="$*"
fi
@@ -138,5 +138,6 @@ clean)
exit $?
;;
esac
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - -
# end

View File

@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# casjaysdevdocker/apprise - launches gunicorn (background) then nginx (foreground).
#
# Single command for the framework's EXEC_CMD_BIN slot.
set -e
# Runtime dirs
mkdir -p /run/apprise /tmp/apprise /data/logs/apprise \
/config/apprise/store /config/apprise/attach /config/apprise/plugin
chmod 1777 /tmp/apprise
# Apprise-API env knobs (defaults; overridable via /config/env/apprise.sh)
export APPRISE_CONFIG_DIR="${APPRISE_CONFIG_DIR:-/config/apprise/store}"
export APPRISE_ATTACH_DIR="${APPRISE_ATTACH_DIR:-/config/apprise/attach}"
export APPRISE_PLUGIN_PATHS="${APPRISE_PLUGIN_PATHS:-/config/apprise/plugin}"
export PYTHONPATH="${PYTHONPATH:-/usr/local/share/apprise-api/webapp}"
export DJANGO_SETTINGS_MODULE="${DJANGO_SETTINGS_MODULE:-core.settings}"
# Resolve the gunicorn binary; Alpine's py3-gunicorn installs to /usr/bin/gunicorn
GUNICORN_BIN="$(command -v gunicorn || true)"
if [ -z "$GUNICORN_BIN" ]; then
echo "gunicorn not found in PATH" >&2
exit 2
fi
# Start gunicorn in background (only if not already running)
if ! pgrep -f 'gunicorn.*core.wsgi' >/dev/null 2>&1; then
cd /usr/local/share/apprise-api/webapp
"$GUNICORN_BIN" \
--bind unix:/run/apprise/gunicorn.sock \
--workers "${GUNICORN_WORKERS:-4}" \
--timeout "${GUNICORN_TIMEOUT:-120}" \
--worker-tmp-dir /dev/shm \
--access-logfile /data/logs/apprise/gunicorn-access.log \
--error-logfile /data/logs/apprise/gunicorn-err.log \
core.wsgi:application \
>>/data/logs/apprise/gunicorn.log 2>>/data/logs/apprise/gunicorn-err.log &
# wait up to 30s for the unix socket
i=0
while [ ! -S /run/apprise/gunicorn.sock ] && [ $i -lt 30 ]; do
sleep 1
i=$((i + 1))
done
if [ ! -S /run/apprise/gunicorn.sock ]; then
echo "gunicorn failed to create socket /run/apprise/gunicorn.sock after 30s" >&2
cat /data/logs/apprise/gunicorn-err.log >&2 || true
exit 3
fi
# Allow nginx (running as 'nginx' user) to connect to the gunicorn socket
# (gunicorn creates it owned by the launching user, default mode 660).
chmod 666 /run/apprise/gunicorn.sock
fi
# nginx in foreground (nginx.conf has daemon off;)
exec /usr/sbin/nginx -c /etc/nginx/nginx.conf

View File

@@ -0,0 +1,263 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# casjaysdevdocker/apprise - nginx + gunicorn + apprise-api init.d
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM EXIT
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
SCRIPT_FILE="$0"
SERVICE_NAME="apprise"
__script_exit() {
local exit_code="${1:-0}"
if [ "${BASH_SOURCE[0]}" != "${0}" ]; then return "$exit_code"; else exit "$exit_code"; fi
}
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
if [ ! -f "/run/.start_init_scripts.pid" ]; then
echo "__start_init_scripts function hasn't been Initialized" >&2
SERVICE_IS_RUNNING="no"
__script_exit 1
fi
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
. "/usr/local/etc/docker/functions/entrypoint.sh"
fi
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
[ -f "$set_env" ] && . "$set_env"
done
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
START_SCRIPT="/usr/local/etc/docker/exec/$SERVICE_NAME"
RESET_ENV="no"
WWW_ROOT_DIR="/usr/local/share/apprise-api/webapp"
DATA_DIR="/data/apprise"
CONF_DIR="/config/nginx"
ETC_DIR="/etc/nginx"
VAR_DIR=""
TMP_DIR="/tmp/apprise"
RUN_DIR="/run/apprise"
LOG_DIR="/data/logs/apprise"
WORK_DIR=""
SERVICE_PORT="8000"
RUNAS_USER="root"
SERVICE_USER="root"
SERVICE_GROUP="root"
RANDOM_PASS_USER=""
RANDOM_PASS_ROOT=""
SERVICE_UID="0"
SERVICE_GID="0"
EXEC_CMD_BIN='/usr/local/etc/docker/bin/start-apprise'
EXEC_CMD_ARGS=''
EXEC_PRE_SCRIPT=''
IS_WEB_SERVER="yes"
IS_DATABASE_SERVICE="no"
USES_DATABASE_SERVICE="no"
DATABASE_SERVICE_TYPE=""
PRE_EXEC_MESSAGE="Apprise REST API listening on http://localhost:${SERVICE_PORT:-8000}/"
POST_EXECUTE_WAIT_TIME="1"
PATH="$PATH:."
IP4_ADDRESS="$(__get_ip4)"
IP6_ADDRESS="$(__get_ip6)"
ROOT_FILE_PREFIX="/config/secure/auth/root"
USER_FILE_PREFIX="/config/secure/auth/user"
root_user_name="${APPRISE_ROOT_USER_NAME:-}"
root_user_pass="${APPRISE_ROOT_PASS_WORD:-}"
user_name="${APPRISE_USER_NAME:-}"
user_pass="${APPRISE_USER_PASS_WORD:-}"
[ -f "/config/env/apprise.script.sh" ] && . "/config/env/apprise.script.sh"
[ -f "/config/env/apprise.sh" ] && . "/config/env/apprise.sh"
ADD_APPLICATION_FILES=""
ADD_APPLICATION_DIRS="/usr/local/share/apprise-api /run/apprise /tmp/apprise /config/apprise/store /config/apprise/attach /config/apprise/plugin"
APPLICATION_FILES="$LOG_DIR/$SERVICE_NAME.log"
APPLICATION_DIRS="$ETC_DIR $CONF_DIR $LOG_DIR $TMP_DIR $RUN_DIR $VAR_DIR"
ADDITIONAL_CONFIG_DIRS="/config/apprise"
CMD_ENV="APPRISE_CONFIG_DIR=/config/apprise/store,APPRISE_ATTACH_DIR=/config/apprise/attach,APPRISE_PLUGIN_PATHS=/config/apprise/plugin"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__run_precopy() {
local hostname=${HOSTNAME}
if builtin type -t __run_precopy_local | grep -q 'function'; then __run_precopy_local; fi
}
__execute_prerun() {
local hostname=${HOSTNAME}
mkdir -p /run/apprise /tmp/apprise /data/logs/apprise \
/config/apprise/store /config/apprise/attach /config/apprise/plugin \
/config/apprise/conf.d
chmod 1777 /tmp/apprise 2>/dev/null || true
if builtin type -t __execute_prerun_local | grep -q 'function'; then __execute_prerun_local; fi
}
__run_pre_execute_checks() {
local exitStatus=0
__banner "Running preexecute check for $SERVICE_NAME"
# Validate nginx config syntax
nginx -t -c /etc/nginx/nginx.conf 2>&1 | head -20 || exitStatus=$?
__banner "Finished preexecute check for $SERVICE_NAME: Status $exitStatus"
if [ $exitStatus -ne 0 ]; then
echo "The pre-execution check has failed" >&2
[ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE"
__script_exit 1
fi
if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi
return $exitStatus
}
__update_conf_files() {
local exitCode=0
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
__replace "REPLACE_TZ" "${TZ:-UTC}" "/etc/nginx/nginx.conf" 2>/dev/null || true
if builtin type -t __update_conf_files_local | grep -q 'function'; then __update_conf_files_local; fi
return $exitCode
}
__pre_execute() {
local exitCode=0
sleep 2
if builtin type -t __pre_execute_local | grep -q 'function'; then __pre_execute_local; fi
return $exitCode
}
__post_execute() {
local pid=""
local retVal=0
local ctime=${POST_EXECUTE_WAIT_TIME:-1}
local waitTime=$((ctime * 60))
sleep $waitTime
(
__banner "Running post commands for $SERVICE_NAME"
# Drop the sample yaml into /config/apprise/ if not already present
if [ -f /usr/local/share/template-files/config/apprise/apprise.yml.sample ] && \
[ ! -f /config/apprise/apprise.yml.sample ]; then
cp -f /usr/local/share/template-files/config/apprise/apprise.yml.sample /config/apprise/ 2>/dev/null || true
fi
__banner "Finished post commands for $SERVICE_NAME: Status $retVal"
) 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
pid=$!
if builtin type -t __post_execute_local | grep -q 'function'; then __post_execute_local; fi
return $retVal
}
__pre_message() {
local exitCode=0
[ -n "$PRE_EXEC_MESSAGE" ] && eval echo "$PRE_EXEC_MESSAGE"
if builtin type -t __pre_message_local | grep -q 'function'; then __pre_message_local; fi
return $exitCode
}
__update_ssl_conf() {
local exitCode=0
if builtin type -t __update_ssl_conf_local | grep -q 'function'; then __update_ssl_conf_local; fi
return $exitCode
}
__create_service_env() {
local exitCode=0
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then
cat <<EOF | tee -p "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" &>/dev/null
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Generated by 99-apprise.sh - edit to override defaults
#APPRISE_WORKER_COUNT=""
#APPRISE_WORKER_TIMEOUT="300"
#APPRISE_BASE_URL=""
#APPRISE_STATEFUL_MODE="simple"
EOF
fi
if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" ]; then
__run_precopy_local() { true; }
__execute_prerun_local() { true; }
__run_pre_execute_checks_local() { true; }
__update_conf_files_local() { true; }
__pre_execute_local() { true; }
__post_execute_local() { true; }
__pre_message_local() { true; }
__update_ssl_conf_local() { true; }
fi
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || exitCode=$((exitCode + 1))
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" || exitCode=$((exitCode + 1))
return $exitCode
}
__run_start_script() {
local runExitCode=0
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")"
local args="$(eval echo "${EXEC_CMD_ARGS:-}")"
local name="$(eval echo "${EXEC_CMD_NAME:-}")"
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
[ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh"
if [ ! -x "$cmd" ]; then echo "$cmd is not executable" >&2; return 2; fi
if __proc_check "nginx"; then echo "nginx already running" >&2; return 0; fi
echo "Starting $cmd $args" | tee -a -p "/data/logs/init.txt"
su_cmd touch "$SERVICE_PID_FILE"
if [ ! -f "$START_SCRIPT" ]; then
cat <<EOF >"$START_SCRIPT"
#!/usr/bin/env bash
trap 'exitCode=\$?;if [ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ]; then rm -Rf "\$SERVICE_PID_FILE"; fi; exit \$exitCode' EXIT
set -Eeo pipefail
retVal=10
cmd="$cmd"
SERVICE_NAME="$SERVICE_NAME"
SERVICE_PID_FILE="$SERVICE_PID_FILE"
$cmd $args 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &
execPid=\$!
sleep 3
checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)"
[ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10
[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "Failed to start $cmd $args" >&2
exit \$retVal
EOF
fi
[ -x "$START_SCRIPT" ] || chmod 755 -Rf "$START_SCRIPT"
[ "$CONTAINER_INIT" = "yes" ] || eval sh -c "$START_SCRIPT"
runExitCode=$?
return $runExitCode
}
__run_secure_function() {
local filesperms
for filesperms in "${USER_FILE_PREFIX}"/* "${ROOT_FILE_PREFIX}"/*; do
[ -e "$filesperms" ] && { chmod -Rf 600 "$filesperms"; chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null; }
done 2>/dev/null
unset filesperms
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh"
SERVICE_EXIT_CODE=0
EXEC_CMD_NAME="$(basename -- "$EXEC_CMD_BIN")"
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid"
SERVICE_PID_NUMBER="$(__pgrep)"
__check_service "$1" && SERVICE_IS_RUNNING=yes
[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR"
[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR"
[ -n "$USER_FILE_PREFIX" ] && { [ -d "$USER_FILE_PREFIX" ] || mkdir -p "$USER_FILE_PREFIX"; }
[ -n "$ROOT_FILE_PREFIX" ] && { [ -d "$ROOT_FILE_PREFIX" ] || mkdir -p "$ROOT_FILE_PREFIX"; }
[ -n "$RUNAS_USER" ] || RUNAS_USER="root"
[ -n "$SERVICE_USER" ] || SERVICE_USER="$RUNAS_USER"
[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${SERVICE_USER:-$RUNAS_USER}"
[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes" && __is_htdocs_mounted
[ "$IS_WEB_SERVER" = "yes" ] && [ -z "$SERVICE_PORT" ] && SERVICE_PORT="8000"
[ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ] && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
__create_service_env
__init_config_etc
__execute_prerun
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}"
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-}
__setup_directories
__switch_to_user
__init_working_dir
__pre_message
__update_ssl_conf
__update_ssl_certs
__run_secure_function
__run_precopy
for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do
__initialize_system_etc "$config_2_etc" 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
done
__initialize_replace_variables "$ETC_DIR" "$CONF_DIR" "$ADDITIONAL_CONFIG_DIRS" "$WWW_ROOT_DIR"
__update_conf_files
__pre_execute
__fix_permissions "$SERVICE_USER" "$SERVICE_GROUP"
__run_pre_execute_checks 2>/dev/stderr | tee -a -p "/data/logs/entrypoint.log" "/data/logs/init.txt" || return 20
__run_start_script 2>>/dev/stderr | tee -p -a "/data/logs/entrypoint.log"
errorCode=$?
if [ -n "$EXEC_CMD_BIN" ]; then
if [ "$errorCode" -eq 0 ]; then SERVICE_EXIT_CODE=0; SERVICE_IS_RUNNING="yes"; else SERVICE_EXIT_CODE=$errorCode; SERVICE_IS_RUNNING="${SERVICE_IS_RUNNING:-no}"; [ -s "$SERVICE_PID_FILE" ] || rm -Rf "$SERVICE_PID_FILE"; fi
SERVICE_EXIT_CODE=0
fi
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "/data/logs/init.txt"
__script_exit $SERVICE_EXIT_CODE

View File

@@ -1,631 +0,0 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202308281848-git
# @@Author : Jason Hempstead
# @@Contact : jason@casjaysdev.pro
# @@License : WTFPL
# @@ReadME : zz-default.sh --help
# @@Copyright : Copyright: (c) 2023 Jason Hempstead, Casjays Developments
# @@Created : Monday, Aug 28, 2023 18:48 EDT
# @@File : zz-default.sh
# @@Description :
# @@Changelog : New script
# @@TODO : Better documentation
# @@Other :
# @@Resource :
# @@Terminal App : no
# @@sudo/root : no
# @@Template : other/start-service
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck disable=SC2016
# shellcheck disable=SC2031
# shellcheck disable=SC2120
# shellcheck disable=SC2155
# shellcheck disable=SC2199
# shellcheck disable=SC2317
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS || set -o pipefail
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf '%s\n' "# - - - Initializing apprise - - - #"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SERVICE_NAME="apprise"
# Function to exit appropriately based on context
__script_exit() {
local exit_code="${1:-0}"
if [ "${BASH_SOURCE[0]}" != "${0}" ]; then
# Script is being sourced - use return
return "$exit_code"
else
# Script is being executed - use exit
exit "$exit_code"
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SCRIPT_NAME="$(basename "$0" 2>/dev/null)"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# run trap command on exit
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "true" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM EXIT
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# import the functions file
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
. "/usr/local/etc/docker/functions/entrypoint.sh"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# import variables
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
[ -f "$set_env" ] && . "$set_env"
done
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Run any pre-execution checks
__run_pre_execute_checks() {
local exitStatus=0
true
exitStatus=$?
if [ $exitStatus -ne 0 ]; then
echo "The pre-execution check has failed"
exit ${exitStatus:-20}
fi
return $exitStatus
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Custom functions
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Reset environment before executing service
RESET_ENV="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Show message before execute
PRE_EXEC_MESSAGE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set the database directory
DATABASE_DIR="${DATABASE_DIR_APPRISE:-/data/db/sqlite}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set webroot
WWW_ROOT_DIR="/usr/local/share/httpd/default"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Default predefined variables
DATA_DIR="/data/apprise" # set data directory
CONF_DIR="/config/apprise" # set config directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set the containers etc directory
ETC_DIR="/etc/apprise"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TMP_DIR="/tmp/apprise"
RUN_DIR="/run/apprise" # set scripts pid dir
LOG_DIR="/data/logs/apprise" # set log directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the working dir
WORK_DIR="" # set working directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Where to save passwords to
ROOT_FILE_PREFIX="/config/secure/auth/root" # directory to save username/password for root user
USER_FILE_PREFIX="/config/secure/auth/user" # directory to save username/password for normal user
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# root/admin user info password/random]
root_user_name="${APPRISE_ROOT_USER_NAME:-}" # root user name
root_user_pass="${APPRISE_ROOT_PASS_WORD:-}" # root user password
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Normal user info [password/random]
user_name="${APPRISE_USER_NAME:-}" # normal user name
user_pass="${APPRISE_USER_PASS_WORD:-}" # normal user password
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Overwrite variables from files
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_name" && user_name="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_name")"
__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && user_pass="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass")"
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" && root_user_name="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name")"
__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && root_user_pass="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# port which service is listening on
SERVICE_PORT=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# User to use to launch service - IE: postgres
RUNAS_USER="root" # normally root
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
SERVICE_USER="apprise" # execute command as another user
SERVICE_GROUP="apprise" # Set the service group
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set user and group ID
SERVICE_UID="0" # set the user id
SERVICE_GID="0" # set the group id
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# execute command variables - keep single quotes variables will be expanded later
EXEC_CMD_BIN='apprise' # command to execute
EXEC_CMD_ARGS='' # command arguments
EXEC_PRE_SCRIPT='' # execute script before
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Is this service a web server
IS_WEB_SERVER="no"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Is this service a database server
IS_DATABASE_SERVICE="no"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Load variables from config
[ -f "$CONF_DIR/env/apprise.sh" ] && . "$CONF_DIR/env/apprise.sh"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Additional predefined variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Additional variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Specifiy custom directories to be created
ADD_APPLICATION_FILES=""
ADD_APPLICATION_DIRS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
APPLICATION_FILES="$LOG_DIR/apprise.log"
APPLICATION_DIRS="$RUN_DIR $ETC_DIR $CONF_DIR $LOG_DIR $TMP_DIR"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Additional config dirs - will be Copied to /etc/$name
ADDITIONAL_CONFIG_DIRS=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# define variables that need to be loaded into the service - escape quotes - var=\"value\",other=\"test\"
CMD_ENV=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Overwrite based on file/directory
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# use this function to update config files - IE: change port
__update_conf_files() {
local exitCode=0 # default exit code
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
# CD into temp to bybass any permission errors
cd /tmp || false # lets keep shellcheck happy by adding false
# delete files
#__rm ""
# Initialize templates
if [ -e "$DEFAULT_DATA_DIR/$SERVICE_NAME" ]; then
if [ -d "$DEFAULT_DATA_DIR/$SERVICE_NAME" ]; then
mkdir -p "$DATA_DIR"
__copy_templates "$DEFAULT_DATA_DIR/$SERVICE_NAME/." "$DATA_DIR/"
else
__copy_templates "$DEFAULT_DATA_DIR/$SERVICE_NAME" "$DATA_DIR"
fi
fi
if [ -e "$DEFAULT_CONF_DIR/$SERVICE_NAME" ]; then
if [ -d "$DEFAULT_CONF_DIR/$SERVICE_NAME" ]; then
mkdir -p "$CONF_DIR"
__copy_templates "$DEFAULT_CONF_DIR/$SERVICE_NAME/." "$CONF_DIR/"
else
__copy_templates "$DEFAULT_CONF_DIR/$SERVICE_NAME" "$CONF_DIR"
fi
elif [ -e "$ETC_DIR" ]; then
if [ -d "$ETC_DIR" ]; then
mkdir -p "$CONF_DIR"
__copy_templates "$ETC_DIR/." "$CONF_DIR/"
else
__copy_templates "$ETC_DIR" "$CONF_DIR"
fi
fi
# define actions
# create default directories
for filedirs in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do
if [ -n "$filedirs" ] && [ ! -d "$filedirs" ]; then
(
echo "Creating directory $filedirs with permissions 777"
mkdir -p "$filedirs" && chmod -Rf 777 "$filedirs"
) |& tee -a "$LOG_DIR/init.txt" &>/dev/null
fi
done
# create default files
for application_files in $ADD_APPLICATION_FILES $APPLICATION_FILES; do
if [ -n "$application_files" ] && [ ! -e "$application_files" ]; then
(
echo "Creating file $application_files with permissions 777"
touch "$application_files" && chmod -Rf 777 "$application_files"
) |& tee -a "$LOG_DIR/init.txt" &>/dev/null
fi
done
# create directories if variable is yes"
if [ "$IS_WEB_SERVER" = "yes" ]; then
APPLICATION_DIRS="$APPLICATION_DIRS $WWW_ROOT_DIR"
if __is_dir_empty "$WWW_ROOT_DIR" || [ ! -d "$WWW_ROOT_DIR" ]; then
(echo "Creating directory $WWW_ROOT_DIR with permissions 777" && mkdir -p "$WWW_ROOT_DIR" && chmod -f 777 "$WWW_ROOT_DIR") |& tee -a "$LOG_DIR/init.txt" &>/dev/null
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy html files
__initialize_www_root
__initialize_web_health "$WWW_ROOT_DIR"
fi
if [ "$IS_DATABASE_SERVICE" = "yes" ]; then
APPLICATION_DIRS="$APPLICATION_DIRS $DATABASE_DIR"
if __is_dir_empty "$DATABASE_DIR" || [ ! -d "$DATABASE_DIR" ]; then
(echo "Creating directory $DATABASE_DIR with permissions 777" && mkdir -p "$DATABASE_DIR" && chmod -f 777 "$DATABASE_DIR") |& tee -a "$LOG_DIR/init.txt" &>/dev/null
fi
fi
# replace variables
# __replace "" "" "$CONF_DIR/apprise.conf"
# replace variables recursively
# __find_replace "" "" "$CONF_DIR"
# execute if directory is empty
#__is_dir_empty "" && true || false
# custom commands
# unset unneeded variables
unset application_files filedirs
return $exitCode
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# function to run before executing
__pre_execute() {
local exitCode=0 # default exit code
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
# define commands
# execute if directories is empty
#__is_dir_empty "" && true || false
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# create user if needed
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-3000}" "${SERVICE_GID:-3000}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Modify user if needed
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-3000} ${SERVICE_GID:-3000}
# Run Custom command
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy /config to /etc
for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do
__initialize_system_etc "$config_2_etc" |& tee -a "$LOG_DIR/init.txt" &>/dev/null |& tee -a "$LOG_DIR/init.txt" &>/dev/null
done
unset config_2_etc ADDITIONAL_CONFIG_DIRS
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set user on files/folders
if [ -n "$SERVICE_USER" ] && [ "$SERVICE_USER" != "root" ]; then
if grep -sq "^$SERVICE_USER:" "/etc/passwd"; then
for permissions in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do
if [ -n "$permissions" ] && [ -e "$permissions" ]; then
(chown -Rf $SERVICE_USER:${SERVICE_GROUP:-$SERVICE_USER} "$permissions" && echo "changed ownership on $permissions to user:$SERVICE_USER and group:${SERVICE_GROUP:-$SERVICE_USER}") |& tee -a "$LOG_DIR/init.txt" &>/dev/null
fi
done
fi
fi
if [ -n "$SERVICE_GROUP" ] && [ "$SERVICE_GROUP" != "root" ]; then
if grep -sq "^$SERVICE_GROUP:" "/etc/group"; then
for permissions in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do
if [ -n "$permissions" ] && [ -e "$permissions" ]; then
(chgrp -Rf $SERVICE_GROUP "$permissions" && echo "changed group ownership on $permissions to group $SERVICE_GROUP") |& tee -a "$LOG_DIR/init.txt" &>/dev/null
fi
done
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Replace the applications user and group
__find_replace "REPLACE_WWW_USER" "${SERVICE_USER:-root}" "$ETC_DIR"
__find_replace "REPLACE_WWW_GROUP" "${SERVICE_GROUP:-${SERVICE_USER:-root}}" "$ETC_DIR"
__find_replace "REPLACE_APP_USER" "${SERVICE_USER:-root}" "$ETC_DIR"
__find_replace "REPLACE_APP_GROUP" "${SERVICE_GROUP:-${SERVICE_USER:-root}}" "$ETC_DIR"
# Replace variables
__initialize_replace_variables "$ETC_DIR"
__initialize_replace_variables "$CONF_DIR"
__initialize_replace_variables "$WWW_ROOT_DIR"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Run checks
__run_pre_execute_checks
# unset unneeded variables
unset filesperms filename
# Lets wait a few seconds before continuing
sleep 10
return $exitCode
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# function to run after executing
__post_execute() {
local exitCode=0 # default exit code
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
sleep 60 # how long to wait before executing
echo "Running post commands" # message
# execute commands
(
sleep 20
true
) |& tee -a "$LOG_DIR/init.txt" &>/dev/null &
return $exitCode
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# use this function to update config files - IE: change port
__pre_message() {
local exitCode=0
[ -n "$user_name" ] && echo "username: $user_name" && echo "$user_name" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_name"
[ -n "$user_pass" ] && __printf_space "40" "password:" "saved to ${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && echo "$user_pass" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass"
[ -n "$root_user_name" ] && echo "root username: $root_user_name" && echo "$root_user_name" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name"
[ -n "$root_user_pass" ] && __printf_space "40" "root password:" "saved to ${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass"
return $exitCode
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# use this function to setup ssl support
__update_ssl_conf() {
local exitCode=0
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
return $exitCode
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__create_service_env() {
cat <<EOF | tee "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" &>/dev/null
#ENV_SERVICE_UID="${ENV_UID:-${ENV_SERVICE_UID:-$SERVICE_UID}}" # Set UID
#ENV_SERVICE_GID="${ENV_GID:-${ENV_SERVICE_GID:-$SERVICE_GID}}" # Set GID
#ENV_RUNAS_USER="${ENV_RUNAS_USER:-$RUNAS_USER}" # normally root
#ENV_WORKDIR="${ENV_WORK_DIR:-$WORK_DIR}" # change to directory
#ENV_WWW_DIR="${ENV_WWW_ROOT_DIR:-$WWW_ROOT_DIR}" # set default web dir
#ENV_ETC_DIR="${ENV_ETC_DIR:-$ETC_DIR}" # set default etc dir
#ENV_DATA_DIR="${ENV_DATA_DIR:-$DATA_DIR}" # set default data dir
#ENV_CONF_DIR="${ENV_CONF_DIR:-$CONF_DIR}" # set default config dir
#ENV_DATABASE_DIR="${ENV_DATABASE_DIR:-$DATABASE_DIR}" # set database dir
#ENV_SERVICE_USER="${ENV_SERVICE_USER:-$SERVICE_USER}" # execute command as another user
#ENV_SERVICE_PORT="${ENV_SERVICE_PORT:-$SERVICE_PORT}" # port which service is listening on
#ENV_EXEC_PRE_SCRIPT="${ENV_EXEC_PRE_SCRIPT:-$EXEC_PRE_SCRIPT}" # execute before commands
#ENV_EXEC_CMD_BIN="${ENV_EXEC_CMD_BIN:-$EXEC_CMD_BIN}" # command to execute
#ENV_EXEC_CMD_ARGS="${ENV_EXEC_CMD_ARGS:-$EXEC_CMD_ARGS}" # command arguments
#ENV_EXEC_CMD_NAME="$(basename "$EXEC_CMD_BIN")" # set the binary name
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# root/admin user info [password/random]
#ENV_ROOT_USER_NAME="${ENV_ROOT_USER_NAME:-$APPRISE_ROOT_USER_NAME}" # root user name
#ENV_ROOT_USER_PASS="${ENV_ROOT_USER_NAME:-$APPRISE_ROOT_PASS_WORD}" # root user password
#root_user_name="${ENV_ROOT_USER_NAME:-$root_user_name}" #
#root_user_pass="${ENV_ROOT_USER_PASS:-$root_user_pass}" #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#Normal user info [password/random]
#ENV_USER_NAME="${ENV_USER_NAME:-$APPRISE_USER_NAME}" #
#ENV_USER_PASS="${ENV_USER_PASS:-$APPRISE_USER_PASS_WORD}" #
#user_name="${ENV_USER_NAME:-$user_name}" # normal user name
#user_pass="${ENV_USER_PASS:-$user_pass}" # normal user password
EOF
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || return 1
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# script to start server
__run_start_script() {
local runExitCode=0
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")" # expand variables
local args="$(eval echo "${EXEC_CMD_ARGS:-}")" # expand variables
local name="$(eval echo "${EXEC_CMD_NAME:-}")" # expand variables
local pre="$(eval echo "${EXEC_PRE_SCRIPT:-}")" # expand variables
local extra_env="$(eval echo "${CMD_ENV//,/ }")" # expand variables
local lc_type="$(eval echo "${LANG:-${LC_ALL:-$LC_CTYPE}}")" # expand variables
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")" # expand variables
local path="$(eval echo "$PATH")" # expand variables
local message="$(eval echo "")" # expand variables
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
[ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh"
if [ -z "$cmd" ]; then
__post_execute 2>"/dev/stderr" |& tee -a "$LOG_DIR/init.txt" &>/dev/null
echo "Initializing $SCRIPT_NAME has completed"
else
# ensure the command exists
if [ ! -x "$cmd" ]; then
echo "$name is not a valid executable"
exit 2
fi
# set working directories
[ -z "$home" ] && home="${workdir:-/tmp/docker}"
[ "$home" = "/root" ] && home="/tmp/docker"
[ "$home" = "$workdir" ] && workdir=""
# create needed directories
[ -n "$home" ] && { [ -d "$home" ] || { mkdir -p "$home" && chown -Rf $SERVICE_USER:$SERVICE_GROUP "$home"; }; }
[ -n "$workdir" ] && { [ -d "$workdir" ] || { mkdir -p "$workdir" && chown -Rf $SERVICE_USER:$SERVICE_GROUP "$workdir"; }; }
[ "$user" != "root " ] && [ -d "$home" ] && chmod -f 777 "$home"
[ "$user" != "root " ] && [ -d "$workdir" ] && chmod -f 777 "$workdir"
# check and exit if already running
if __proc_check "$name" || __proc_check "$cmd"; then
echo "$name is already running" >&2
exit 0
else
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# show message if env exists
if [ -n "$cmd_exec" ]; then
[ -n "$SERVICE_USER" ] && echo "Setting up $cmd_exec to run as $SERVICE_USER" || SERVICE_USER="root"
[ -n "$SERVICE_PORT" ] && echo "$name will be running on $SERVICE_PORT" || SERVICE_PORT=""
fi
if [ -n "$pre" ] && [ -n "$(command -v "$pre" 2>/dev/null)" ]; then
export cmd_exec="$pre $cmd $args"
message="Starting service: $name $args through $pre"
else
export cmd_exec="$cmd $args"
message="Starting service: $name $args"
fi
__cd "${workdir:-$home}"
echo "$message"
su_cmd touch "$SERVICE_PID_FILE"
__post_execute |& tee -a "$LOG_DIR/init.txt" &>/dev/null &
if [ "$RESET_ENV" = "yes" ]; then
su_cmd env -i HOME="$home" LC_CTYPE="$lc_type" PATH="$path" HOSTNAME="$sysname" USER="${SERVICE_USER:-$RUNAS_USER}" $extra_env sh -c "$cmd_exec" ||
eval env -i HOME="$home" LC_CTYPE="$lc_type" PATH="$path" HOSTNAME="$sysname" USER="${SERVICE_USER:-$RUNAS_USER}" $extra_env sh -c "$cmd_exec" ||
return 10
else
eval "$cmd_exec" || return 10
fi
fi
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# username and password actions
__run_secure_function() {
if [ -n "$user_name" ] || [ -n "$user_pass" ]; then
for filesperms in "${USER_FILE_PREFIX}"/*; do
if [ -e "$filesperms" ]; then
chmod -Rf 600 "$filesperms"
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms"
fi
done |& tee -a "$LOG_DIR/init.txt" &>/dev/null
fi
if [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then
for filesperms in "${ROOT_FILE_PREFIX}"/*; do
if [ -e "$filesperms" ]; then
chmod -Rf 600 "$filesperms"
chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms"
fi
done |& tee -a "$LOG_DIR/init.txt" &>/dev/null
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# simple cd function
__cd() { mkdir -p "$1" && builtin cd "$1" || exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# process check functions
__pcheck() { [ -n "$(type -P pgrep 2>/dev/null)" ] && pgrep -x "$1" &>/dev/null && return 0 || return 10; }
__pgrep() { __pcheck "${1:-$EXEC_CMD_BIN}" || __ps aux 2>/dev/null | grep -Fw " ${1:-$EXEC_CMD_BIN}" | grep -qv ' grep' | grep '^' && return 0 || return 10; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check if process is already running
__proc_check() {
cmd_bin="$(type -P "${1:-$EXEC_CMD_BIN}")"
cmd_name="$(basename "${cmd_bin:-$EXEC_CMD_NAME}")"
if __pgrep "$cmd_bin" || __pgrep "$cmd_name"; then
SERVICE_IS_RUNNING="true"
touch "$SERVICE_PID_FILE"
echo "$cmd_name is already running"
return 0
else
return 1
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Allow ENV_ variable - Import env file
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SERVICE_EXIT_CODE=0 # default exit code
SERVICE_USER="${ENV_SERVICE_USER:-$SERVICE_USER}" # execute command as another user
SERVICE_UID="${ENV_UID:-${ENV_SERVICE_UID:-$SERVICE_UID}}" # Set UID
SERVICE_GID="${ENV_GID:-${ENV_SERVICE_GID:-$SERVICE_GID}}" # Set GID
SERVICE_PORT="${ENV_SERVICE_PORT:-$SERVICE_PORT}" # port which service is listening on
RUNAS_USER="${ENV_RUNAS_USER:-$RUNAS_USER}" # normally root
WORK_DIR="${ENV_WORK_DIR:-$WORK_DIR}" # change to directory
WWW_ROOT_DIR="${ENV_WWW_ROOT_DIR:-$WWW_ROOT_DIR}" # set default web dir
ETC_DIR="${ENV_ETC_DIR:-$ETC_DIR}" # set default etc dir
DATA_DIR="${ENV_DATA_DIR:-$DATA_DIR}" # set default data dir
CONF_DIR="${ENV_CONF_DIR:-$CONF_DIR}" # set default config dir
DATABASE_DIR="${ENV_DATABASE_DIR:-$DATABASE_DIR}" # set database dir
PRE_EXEC_MESSAGE="${ENV_PRE_EXEC_MESSAGE:-$PRE_EXEC_MESSAGE}" # Show message before execute
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# application specific
EXEC_PRE_SCRIPT="${ENV_EXEC_PRE_SCRIPT:-$EXEC_PRE_SCRIPT}" # Pre
EXEC_CMD_BIN="${ENV_EXEC_CMD_BIN:-$EXEC_CMD_BIN}" # command to execute
EXEC_CMD_NAME="$(basename "$EXEC_CMD_BIN")" # set the binary name
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" # set the pid file location
EXEC_CMD_ARGS="${ENV_EXEC_CMD_ARGS:-$EXEC_CMD_ARGS}" # command arguments
SERVICE_PID_NUMBER="$(__pgrep)" # check if running
EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")" # set full path
EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")" # set full path
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# create auth directories
[ -n "$USER_FILE_PREFIX" ] && { [ -d "$USER_FILE_PREFIX" ] || mkdir -p "$USER_FILE_PREFIX"; }
[ -n "$ROOT_FILE_PREFIX" ] && { [ -d "$ROOT_FILE_PREFIX" ] || mkdir -p "$ROOT_FILE_PREFIX"; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes"
[ "$IS_DATABASE_SERVICE" = "yes" ] && RESET_ENV="no"
[ -n "$RUNAS_USER" ] || RUNAS_USER="root"
[ -n "$SERVICE_USER" ] || SERVICE_USER="${RUNAS_USER:-root}"
[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${RUNAS_USER:-root}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Allow per init script usernames and passwords
__file_exists_with_content "$ETC_DIR/auth/user/name" && user_name="$(<"$ETC_DIR/auth/user/name")"
__file_exists_with_content "$ETC_DIR/auth/user/pass" && user_pass="$(<"$ETC_DIR/auth/user/pass")"
__file_exists_with_content "$ETC_DIR/auth/root/name" && root_user_name="$(<"$ETC_DIR/auth/root/name")"
__file_exists_with_content "$ETC_DIR/auth/root/pass" && root_user_pass="$(<"$ETC_DIR/auth/root/pass")"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Allow setting initial users and passwords via environment
user_name="${ENV_USER_NAME:-$user_name}"
user_pass="${ENV_USER_PASS:-$user_pass}"
root_user_name="${ENV_ROOT_USER_NAME:-$root_user_name}"
root_user_pass="${ENV_ROOT_USER_PASS:-$root_user_pass}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Env vars from dockermgr script
SERVICE_UID="${ENV_PUID:-${PUID:-$SERVICE_UID}}"
SERVICE_GID="${ENV_PGID:-${PGID:-$SERVICE_GID}}"
EMAIL_RELAY="${ENV_EMAIL_RELAY:-$EMAIL_RELAY}"
EMAIL_ADMIN="${ENV_EMAIL_ADMIN:-$EMAIL_ADMIN}"
EMAIL_DOMAIN="${ENV_EMAIL_DOMAIN:-$EMAIL_DOMAIN}"
SERVICE_PROTOCOL="${ENV_CONTAINER_PROTOCOL:-$CONTAINER_PROTOCOL}"
WWW_ROOT_DIR="${CONTAINER_HTML_ENV:-${ENV_WWW_ROOT_DIR:-$WWW_ROOT_DIR}}"
DATABASE_DIR="${ENV_DATABASE_DIR_CUSTOM:-${DATABASE_DIR_CUSTOM:-${DATABASE_DIR_SQLITE:-$DATABASE_DIR}}}"
user_name="${ENV_DATABASE_USER_NORMAL:-${DATABASE_USER_NORMAL:-${CONTAINER_ENV_USER_NAME:-$user_name}}}"
user_pass="${ENV_DATABASE_PASS_NORMAL:-${DATABASE_PASS_NORMAL:-${CONTAINER_ENV_PASS_NAME:-$user_pass}}}"
root_user_name="${ENV_DATABASE_USER_ROOT:-${DATABASE_USER_ROOT:-$root_user_name}}"
root_user_pass="${ENV_DATABASE_PASS_ROOT:-${DATABASE_PASS_ROOT:-$root_user_pass}}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set password to random if variable is random
if [ "$user_pass" = "random" ]; then
user_pass="$(__random_password)"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$root_user_pass" = "random" ]; then
root_user_pass="$(__random_password)"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Allow variables via imports - Overwrite existing
[ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ] && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Only run check
if [ "$1" = "check" ]; then
__proc_check "$EXEC_CMD_NAME" || __proc_check "$EXEC_CMD_BIN"
exit $?
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set switch user command
if [ "$RUNAS_USER" = "root" ]; then
su_cmd() { eval "$@" || return 1; }
elif [ "$(builtin type -P gosu)" ]; then
su_cmd() { gosu $RUNAS_USER "$@" || return 1; }
elif [ "$(builtin type -P runuser)" ]; then
su_cmd() { runuser -u $RUNAS_USER "$@" || return 1; }
elif [ "$(builtin type -P sudo)" ]; then
su_cmd() { sudo -u $RUNAS_USER "$@" || return 1; }
elif [ "$(builtin type -P su)" ]; then
su_cmd() { su -s /bin/sh - $RUNAS_USER -c "$@" || return 1; }
else
su_cmd() { echo "Can not switch to $RUNAS_USER: attempting to run as root" && eval "$*" || return 1; }
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Change to working directory
[ "$HOME" = "/root" ] && [ "$RUNAS_USER" != "root" ] && __cd "/tmp" && echo "Changed to $PWD"
[ "$HOME" = "/root" ] && [ "$SERVICE_USER" != "root" ] && __cd "/tmp" && echo "Changed to $PWD"
[ -n "$WORK_DIR" ] && [ -n "$EXEC_CMD_BIN" ] && __cd "$WORK_DIR" && echo "Changed to $PWD"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# show init message
__pre_message
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Initialize ssl
__update_ssl_conf
__update_ssl_certs
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Updating config files
__create_service_env
__update_conf_files
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# run the pre execute commands
[ -n "$PRE_EXEC_MESSAGE" ] && eval echo "$PRE_EXEC_MESSAGE"
__pre_execute
__run_secure_function
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__run_start_script "$@" |& tee -a "/data/logs/entrypoint.log" &>/dev/null
if [ "$?" -ne 0 ] && [ -n "$EXEC_CMD_BIN" ]; then
eval echo "Failed to execute: ${cmd_exec:-$EXEC_CMD_BIN $EXEC_CMD_ARGS}" |& tee -a "/data/logs/entrypoint.log" "$LOG_DIR/init.txt"
rm -Rf "$SERVICE_PID_FILE"
SERVICE_EXIT_CODE=10
SERVICE_IS_RUNNING="false"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__script_exit $SERVICE_EXIT_CODE