mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-03-12 17:07:23 +01:00
avoid using PYTHONPATH to enable setup mod hooks, which is problematic for managment command line tool use
- save the directory path to setup mods in /etc/mailinabox.conf - dynamically add the path to python during hook initialization
This commit is contained in:
@@ -317,18 +317,54 @@ say() {
|
||||
echo "$@"
|
||||
}
|
||||
|
||||
wait_for_management_daemon() {
|
||||
local progress="${1:-progress}" # show progress? "progress"/"no-progress"
|
||||
local max_wait="${2:-60}" # seconds, 0=forever
|
||||
local start=$(date +%s)
|
||||
local elapsed=0 now
|
||||
[ "$max_wait" = "forever" ] && max_wait=0
|
||||
|
||||
# Wait for the management daemon to start...
|
||||
until nc -z -w 4 127.0.0.1 10222
|
||||
do
|
||||
now=$(date +%s)
|
||||
# let returns 1 if the equasion evaluates to zero, which will
|
||||
# cause the script to exit because of set -e. add one.
|
||||
[ $now -eq $start ] && let now+=1
|
||||
let elapsed="$now - $start"
|
||||
if [ $max_wait -ne 0 -a $elapsed -gt $max_wait ]; then
|
||||
echo "Timeout waiting for Mail-in-a-Box management daemon to start"
|
||||
return 1
|
||||
fi
|
||||
if [ "$progress" = "progress" ]; then
|
||||
echo Waiting for the Mail-in-a-Box management daemon to start...
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
}
|
||||
|
||||
install_hook_handler() {
|
||||
# this is used by local setup mods to install a hook handler for
|
||||
# the management daemon
|
||||
# the management daemon. source /etc/mailinabox.conf before
|
||||
# calling
|
||||
local handler_file="$1"
|
||||
local dst="${LOCAL_MODS_DIR:-local}/management_hooks_d"
|
||||
mkdir -p "$dst"
|
||||
cp "$handler_file" "$dst"
|
||||
# let the daemon know there's a new hook handler
|
||||
tools/hooks_update >/dev/null
|
||||
if [ ! -d "$dst" -o -e "$dst/$(basename "$handler_file")" ]; then
|
||||
mkdir -p "$dst"
|
||||
cp "$handler_file" "$dst"
|
||||
if systemctl is-active --quiet mailinabox; then
|
||||
systemctl restart mailinabox
|
||||
wait_for_management_daemon no-progress
|
||||
fi
|
||||
else
|
||||
cp "$handler_file" "$dst"
|
||||
# let the daemon know there's a new hook handler
|
||||
tools/hooks_update >/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
remove_hook_handler() {
|
||||
# source /etc/mailinabox.conf before calling
|
||||
local hook_py=$(basename "$1")
|
||||
local dst="${LOCAL_MODS_DIR:-local}/management_hooks_d/$hook_py"
|
||||
if [ -e "$dst" ]; then
|
||||
|
||||
@@ -103,7 +103,7 @@ tr -cd '[:xdigit:]' < /dev/urandom | head -c 32 > /var/lib/mailinabox/api.key
|
||||
chmod 640 /var/lib/mailinabox/api.key
|
||||
|
||||
source $venv/bin/activate
|
||||
export PYTHONPATH=$(pwd)/management:${LOCAL_MODS_DIR:-$(pwd)/local}
|
||||
export PYTHONPATH=$(pwd)/management
|
||||
exec gunicorn --log-level ${MGMT_LOG_LEVEL:-info} -b localhost:10222 -w 1 --timeout 630 wsgi:app
|
||||
EOF
|
||||
chmod +x $inst_dir/start
|
||||
|
||||
@@ -105,6 +105,9 @@ if [ ! -f $STORAGE_ROOT/mailinabox-ldap.version ]; then
|
||||
chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox-ldap.version
|
||||
fi
|
||||
|
||||
# normalize the directory path for setup mods
|
||||
LOCAL_MODS_DIR="$(realpath -m "${LOCAL_MODS_DIR:-${DEFAULT_LOCAL_MODS_DIR:-local}}")"
|
||||
|
||||
# Save the global options in /etc/mailinabox.conf so that standalone
|
||||
# tools know where to look for data. The default MTA_STS_MODE setting
|
||||
# is blank unless set by an environment variable, but see web.sh for
|
||||
@@ -118,6 +121,7 @@ PUBLIC_IPV6=$PUBLIC_IPV6
|
||||
PRIVATE_IP=$PRIVATE_IP
|
||||
PRIVATE_IPV6=$PRIVATE_IPV6
|
||||
MTA_STS_MODE=${DEFAULT_MTA_STS_MODE:-enforce}
|
||||
LOCAL_MODS_DIR=$LOCAL_MODS_DIR
|
||||
EOF
|
||||
|
||||
# Start service configuration.
|
||||
@@ -139,11 +143,7 @@ source setup/management-capture.sh
|
||||
source setup/munin.sh
|
||||
|
||||
# Wait for the management daemon to start...
|
||||
until nc -z -w 4 127.0.0.1 10222
|
||||
do
|
||||
echo Waiting for the Mail-in-a-Box management daemon to start...
|
||||
sleep 2
|
||||
done
|
||||
wait_for_management_daemon progress forever
|
||||
|
||||
# ...and then have it write the DNS and nginx configuration files and start those
|
||||
# services.
|
||||
@@ -174,9 +174,9 @@ fi
|
||||
#
|
||||
# Run setup mods
|
||||
#
|
||||
if [ -d "${LOCAL_MODS_DIR:-local}" ]; then
|
||||
for mod in $(ls "${LOCAL_MODS_DIR:-local}" | grep -v '~$'); do
|
||||
mod_path="${LOCAL_MODS_DIR:-local}/$mod"
|
||||
if [ -d "$LOCAL_MODS_DIR" ]; then
|
||||
for mod in $(ls "$LOCAL_MODS_DIR" | grep -v '~$'); do
|
||||
mod_path="$LOCAL_MODS_DIR/$mod"
|
||||
if [ -f "$mod_path" -a -x "$mod_path" ]; then
|
||||
echo ""
|
||||
echo "Running mod: $mod_path"
|
||||
|
||||
Reference in New Issue
Block a user