1809 lines
41 KiB
Bash
Executable File
1809 lines
41 KiB
Bash
Executable File
#!/bin/bash
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
#
|
|
|
|
#
|
|
# Plesk script
|
|
#
|
|
|
|
|
|
|
|
#default values
|
|
|
|
product_default_conf()
|
|
{
|
|
|
|
PRODUCT_ROOT_D=/opt/psa
|
|
PRODUCT_RC_D=/etc/init.d
|
|
PRODUCT_ETC_D=/opt/psa/etc
|
|
PLESK_LIBEXEC_DIR=/usr/lib/plesk-9.0
|
|
HTTPD_VHOSTS_D=/var/www/vhosts
|
|
HTTPD_CONF_D=/etc/apache2
|
|
HTTPD_INCLUDE_D=/etc/apache2/conf-enabled
|
|
HTTPD_BIN=/usr/sbin/apache2
|
|
HTTPD_LOG_D=/var/log/apache2
|
|
HTTPD_SERVICE=apache2
|
|
QMAIL_ROOT_D=/var/qmail
|
|
PLESK_MAILNAMES_D=/var/qmail/mailnames
|
|
RBLSMTPD=/usr/sbin/rblsmtpd
|
|
NAMED_RUN_ROOT_D=/var/named/run-root
|
|
WEB_STAT=/usr/bin/webalizer
|
|
MYSQL_VAR_D=/var/lib/mysql
|
|
MYSQL_BIN_D=/usr/bin
|
|
MYSQL_SOCKET=/var/run/mysqld/mysqld.sock
|
|
PGSQL_DATA_D=/var/lib/postgresql/16/main
|
|
PGSQL_CONF_D=/etc/postgresql/16/main
|
|
PGSQL_BIN_D=/usr/lib/postgresql/16/bin
|
|
DUMP_D=/var/lib/psa/dumps
|
|
DUMP_TMP_D=/tmp
|
|
MAILMAN_ROOT_D=/usr/lib/mailman
|
|
MAILMAN_VAR_D=/var/lib/mailman
|
|
PYTHON_BIN=/usr/bin/python2
|
|
GPG_BIN=/usr/bin/gpg
|
|
TAR_BIN=/usr/lib/plesk-9.0/sw-tar
|
|
AWSTATS_ETC_D=/etc/awstats
|
|
AWSTATS_BIN_D=/usr/lib/cgi-bin
|
|
AWSTATS_TOOLS_D=/usr/share/awstats/tools
|
|
AWSTATS_DOC_D=/usr/share/awstats
|
|
OPENSSL_BIN=/usr/bin/openssl
|
|
LIB_SSL_PATH=/lib/libssl.so
|
|
LIB_CRYPTO_PATH=/lib/libcrypto.so
|
|
CLIENT_PHP_BIN=/opt/psa/bin/php-cli
|
|
SNI_SUPPORT=true
|
|
APS_DB_DRIVER_LIBRARY=/usr/lib/x86_64-linux-gnu/sw/libmysqlserver.so.2.0
|
|
SA_MAX_MAIL_SIZE=256000
|
|
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
set_apache_params()
|
|
{
|
|
apache_user="www-data"
|
|
apache_UID=80
|
|
apache_group="www-data"
|
|
apache_GID=80
|
|
|
|
apache_pid_file="$APACHE_ROOT/logs/httpd.pid"
|
|
apache_lock_file="$APACHE_ROOT/logs/httpd.lock"
|
|
product_lock_file="$HTTPD_CONF_D/cnf.lock"
|
|
apache_service_name="apache2"
|
|
|
|
apache_modules_d="/usr/lib/apache2/modules"
|
|
|
|
apache_service="$apache_service_name"
|
|
|
|
apache_httpd_conf="$HTTPD_CONF_D/apache2.conf"
|
|
|
|
apache_httpd_include="$HTTPD_INCLUDE_D/zz010_psa_httpd.conf"
|
|
|
|
APACHE_ROOT="/usr"
|
|
|
|
min_suexec_UID=10000
|
|
max_suexec_UID=16000
|
|
min_suexec_GID=$min_suexec_UID
|
|
max_suexec_GID=$max_suexec_UID
|
|
|
|
suexec_storage=/usr/lib/plesk-9.0/suexec
|
|
suexec=/usr/lib/apache2/suexec
|
|
suexec_dir="`dirname "$suexec"`"
|
|
suexec_file="`basename "$suexec"`"
|
|
|
|
rpm_httpd_bin=/usr/sbin/httpd
|
|
}
|
|
|
|
# db_select <query>
|
|
# runs <query> via mysql_raw
|
|
# writes output to db_select_output
|
|
# if query fails, output errors and return 1
|
|
db_select()
|
|
{
|
|
local desc="execute SQL query"
|
|
local query="$1"
|
|
|
|
local output
|
|
output="`mysql_raw -e \"$query\" 2>>\"$product_log\"`"
|
|
local status="$?"
|
|
if [ "$status" -ne "0" ]; then
|
|
p_echo "$output"
|
|
die "run the following SQL query: $query"
|
|
fi
|
|
|
|
db_select_output="$output"
|
|
return 0
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
set_drweb_params()
|
|
{
|
|
drweb_service="drwebd"
|
|
true drweb_status
|
|
}
|
|
|
|
drweb_status()
|
|
{
|
|
local pidfile="/var/drweb/run/drwebd.pid"
|
|
if [ ! -r "$pidfile" ]; then
|
|
p_echo "drweb is stopped (no pidfile found)"
|
|
return 1
|
|
fi
|
|
|
|
local pid=$(head -1 "$pidfile" 2>/dev/null)
|
|
if [ -z "$pid" ]; then
|
|
p_echo "drweb is stopped (wrong pidfile)"
|
|
return 1
|
|
fi
|
|
|
|
if kill -0 "$pid" 2>/dev/null || ps -p "$pid" >/dev/null 2>&1 ; then
|
|
p_echo "drwebd (pid $pid) is running..."
|
|
return 0
|
|
fi
|
|
p_echo "drwebd is stopped"
|
|
return 1
|
|
}
|
|
|
|
is_remote_db_feature_enabled()
|
|
{
|
|
[ -s "/etc/psa/private/dsn.ini" ]
|
|
}
|
|
|
|
get_dsn()
|
|
{
|
|
local section="$1"
|
|
local param="$2"
|
|
! is_remote_db_feature_enabled || get_ini_conf_var "/etc/psa/private/dsn.ini" "$section" "$param"
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
set_kav_params()
|
|
{
|
|
kav_service="kavehost"
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh
|
|
# Usage: pleskrc <service> <action>
|
|
pleskrc()
|
|
{
|
|
[ 2 -le $# ] || die "Not enough arguments"
|
|
|
|
local service_name=${1//[-.@]/_}
|
|
local action=$2
|
|
local ret=0
|
|
local inten
|
|
shift
|
|
shift
|
|
|
|
# Now check redefined functions
|
|
if test "$machine" = "linux" && is_function "${service_name}_${action}_${machine}_${linux_distr}"; then
|
|
"${service_name}_${action}_${machine}_${linux_distr}" "$@"
|
|
return $?
|
|
elif is_function "${service_name}_${action}_${machine}"; then
|
|
"${service_name}_${action}_${machine}" "$@"
|
|
return $?
|
|
elif is_function "${service_name}_${action}"; then
|
|
"${service_name}_${action}" "$@"
|
|
return $?
|
|
fi
|
|
|
|
# Not redefined - call default action
|
|
eval "service=\$${service_name}_service"
|
|
[ -n "$service" ] || die "$action $service_name service (Empty service name for '$service_name')"
|
|
|
|
if [ "$action" = "name" ]; then
|
|
echo "${service}.service"
|
|
return 0
|
|
fi
|
|
|
|
inten="$action service $service"
|
|
pleskrc_is_failure_for_action_ok "$action" || echo_try "$inten"
|
|
|
|
if [ -x "/bin/systemctl" -a "$do_upgrade" = "1" -a ! -f "/var/lock/parallels-panel-bootstrapper-running.lock" -a -z "$SYSTEMD_DAEMON_RELOADED" ]; then
|
|
# reload systemd units if requested from an upgrade package script - in case a unit was changed
|
|
/bin/systemctl daemon-reload
|
|
SYSTEMD_DAEMON_RELOADED="yes"
|
|
fi
|
|
|
|
service_ctl "$action" "$service" "$service_name"
|
|
ret="$?"
|
|
|
|
pleskrc_is_failure_for_action_ok "$action" || {
|
|
if [ "$ret" -eq 0 ]; then
|
|
suc
|
|
else
|
|
if [ -x "/bin/systemctl" ]; then
|
|
p_echo "`/bin/systemctl -l status \"${service}.service\" | awk 'BEGIN {s=0} s==1 {s=2} /^$/ {s=1} s==2 {print}'`"
|
|
fi
|
|
warn "$inten failed"
|
|
fi
|
|
}
|
|
|
|
return $ret
|
|
}
|
|
|
|
pleskrc_is_failure_for_action_ok()
|
|
{
|
|
local action="$1"
|
|
case "$action" in
|
|
status|exists|is-active|is-enabled|is-failed) return 0 ;;
|
|
esac
|
|
return 1
|
|
}
|
|
|
|
# NOTE:
|
|
# Function service_ctl is just helper for pleskrc().
|
|
# Do not call it directly, use pleskrc()!!!
|
|
service_ctl()
|
|
{
|
|
local action=$1
|
|
local service=$2
|
|
local service_name=$3
|
|
|
|
if [ "$action" != "exists" ]; then
|
|
_service_exec $service exists
|
|
if [ "$?" != "0" ]; then
|
|
p_echo "attempt to ${inten} - service doesn't exist (missing unit file or not executable control script)"
|
|
return 1
|
|
fi
|
|
fi
|
|
|
|
case "$action" in
|
|
start)
|
|
pleskrc "$service_name" status || _service_exec "$service" "$action"
|
|
;;
|
|
stop)
|
|
! pleskrc "$service_name" status || _service_exec "$service" "$action"
|
|
;;
|
|
restart)
|
|
if pleskrc "$service_name" status; then
|
|
_service_exec "$service" "$action"
|
|
else
|
|
_service_exec "$service" start
|
|
fi
|
|
;;
|
|
reload)
|
|
! pleskrc "$service_name" status || _service_exec "$service" "$action"
|
|
;;
|
|
status)
|
|
_service_exec "$service" status
|
|
;;
|
|
try-restart)
|
|
if [ -x "/bin/systemctl" ]; then
|
|
_service_exec "$service" "$action"
|
|
else
|
|
! pleskrc "$service_name" status || _service_exec "$service" "restart"
|
|
fi
|
|
;;
|
|
try-reload)
|
|
! pleskrc "$service_name" status || _service_exec "$service" "reload"
|
|
;;
|
|
reload-or-restart)
|
|
if [ -x "/bin/systemctl" ]; then
|
|
_service_exec "$service" "$action"
|
|
elif pleskrc "$service_name" status; then
|
|
_service_exec "$service" "reload"
|
|
else
|
|
_service_exec "$service" "start"
|
|
fi
|
|
;;
|
|
*)
|
|
_service_exec "$service" "$action"
|
|
;;
|
|
esac >> "$product_log"
|
|
}
|
|
|
|
_service_exec()
|
|
{
|
|
# Keep in sync with pylibplesk/plesk_service.py
|
|
local service=$1
|
|
local action=$2
|
|
|
|
local action_cmd
|
|
local sysvinit_service="/etc/init.d/$service"
|
|
|
|
if [ -x "/bin/systemctl" ]; then
|
|
case "${action}" in
|
|
exists)
|
|
if /bin/systemctl cat "$service.service" >/dev/null 2>&1; then
|
|
return 0 # systemd unit
|
|
elif [ -f "/lib/systemd/system/$service.service" ]; then
|
|
/bin/systemctl daemon-reload
|
|
return 0 # systemd unit which exists but was changed and has not been reloaded before
|
|
elif [ -x "$sysvinit_service" ]; then
|
|
return 0 # sysvinit compat
|
|
fi
|
|
return 1 # not found
|
|
;;
|
|
status)
|
|
action="is-active"
|
|
;;
|
|
reload|graceful)
|
|
action='reload-or-try-restart'
|
|
;;
|
|
esac
|
|
/bin/systemctl "$action" "${service}.service"
|
|
else
|
|
warn "Cannot $action $service on this system: no executable /bin/systemctl"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
is_function()
|
|
{
|
|
local type_output=$(type -t "$1")
|
|
test "X${type_output}" = "Xfunction"
|
|
}
|
|
|
|
# echo message to product log, also to console in debug mode
|
|
p_echo()
|
|
{
|
|
if [ -n "$product_log" ] ; then
|
|
echo "$@" >> "$product_log" 2>&1
|
|
fi
|
|
if [ -n "$PLESK_INSTALLER_DEBUG" -o -n "$PLESK_INSTALLER_VERBOSE" -o -z "$product_log" ] ; then
|
|
echo "$@" >&2
|
|
fi
|
|
}
|
|
|
|
# same as p_echo, but without new line
|
|
pnnl_echo()
|
|
{
|
|
p_echo -n "$@"
|
|
}
|
|
|
|
int_err()
|
|
{
|
|
report_problem "internal" "Internal error: $@"
|
|
exit 1
|
|
}
|
|
|
|
p_see_product_log()
|
|
{
|
|
log_is_in_dev "${product_log}" || printf " (see log file: ${product_log})" >&2
|
|
}
|
|
|
|
die()
|
|
{
|
|
report_problem "fatal" "ERROR while trying to $@"
|
|
printf "Check the error reason" >&2
|
|
p_see_product_log
|
|
echo ", fix and try again" >&2
|
|
|
|
selinux_close
|
|
|
|
exit 1
|
|
}
|
|
|
|
warn()
|
|
{
|
|
local inten="$1"
|
|
|
|
if [ -n "$PLESK_INSTALLER_DEBUG" -o -n "$PLESK_INSTALLER_VERBOSE" ]; then
|
|
p_echo
|
|
p_echo "WARNING!"
|
|
pnnl_echo "Some problems are found during $inten"
|
|
p_see_product_log
|
|
p_echo
|
|
p_echo "Continue..."
|
|
p_echo
|
|
fi
|
|
|
|
report_problem "warning" "Warning: $inten"
|
|
}
|
|
|
|
echo_try()
|
|
{
|
|
msg="$*"
|
|
pnnl_echo " Trying to $msg... "
|
|
}
|
|
|
|
suc()
|
|
{
|
|
p_echo "done"
|
|
}
|
|
|
|
write_structured_report()
|
|
{
|
|
# Write json error report into file $PLESK_INSTALLER_ERROR_REPORT if specified.
|
|
# @params are tags in format "key=value"
|
|
# Report body (human readable information) is read from stdin.
|
|
local report_file="$PLESK_INSTALLER_ERROR_REPORT"
|
|
|
|
[ -n "$report_file" ] || return 0
|
|
|
|
local python_bin=
|
|
for bin in "/opt/psa/bin/python" "/usr/local/psa/bin/python" "/usr/bin/python2" "/usr/libexec/platform-python" "/usr/bin/python3"; do
|
|
if [ -x "$bin" ]; then
|
|
python_bin="$bin"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ ! -x "$python_bin" ]; then
|
|
p_echo "Cannot write structured error report: python interpreter not found."
|
|
return 1
|
|
fi
|
|
|
|
"$python_bin" -c 'import sys, json
|
|
report_file = sys.argv[1]
|
|
error = sys.stdin.read()
|
|
|
|
data = {
|
|
"error": error,
|
|
}
|
|
|
|
for tag in sys.argv[2:]:
|
|
k, v = tag.split("=", 1)
|
|
data[k] = v
|
|
|
|
with open(report_file, "a") as f:
|
|
json.dump(data, f)
|
|
f.write("\n")
|
|
' "$report_file" "date=$(date --utc --iso-8601=ns)" "$@"
|
|
}
|
|
|
|
get_default_locale()
|
|
{
|
|
# Note that CentOS 7 typically doesn't have C.UTF-8
|
|
for lc in "C.UTF-8" "en_US.UTF-8" "C"; do
|
|
if [ -z "`LC_ALL=$lc locale 2>&1 >/dev/null`" ]; then
|
|
echo "$lc"
|
|
return 0
|
|
fi
|
|
done
|
|
echo "C"
|
|
}
|
|
|
|
detect_vz()
|
|
{
|
|
[ -z "$PLESK_VZ_RESULT" ] || return $PLESK_VZ_RESULT
|
|
|
|
PLESK_VZ_RESULT=1
|
|
PLESK_VZ=0
|
|
PLESK_VE_HW_NODE=0
|
|
PLESK_VZ_TYPE=
|
|
|
|
local issue_file="/etc/issue"
|
|
local vzcheck_file="/proc/self/status"
|
|
[ -f "$vzcheck_file" ] || return 1
|
|
|
|
local env_id=`sed -ne 's|^envID\:[[:space:]]*\([[:digit:]]\+\)$|\1|p' "$vzcheck_file"`
|
|
[ -n "$env_id" ] || return 1
|
|
if [ "$env_id" = "0" ]; then
|
|
# Either VZ/OpenVZ HW node or unjailed CloudLinux
|
|
PLESK_VE_HW_NODE=1
|
|
return 1
|
|
fi
|
|
|
|
if grep -q "CloudLinux" "$issue_file" >/dev/null 2>&1 ; then
|
|
return 1
|
|
fi
|
|
|
|
if [ -f "/proc/vz/veredir" ]; then
|
|
PLESK_VZ_TYPE="vz"
|
|
elif [ -d "/proc/vz" ]; then
|
|
PLESK_VZ_TYPE="openvz"
|
|
fi
|
|
|
|
PLESK_VZ=1
|
|
PLESK_VZ_RESULT=0
|
|
return 0
|
|
}
|
|
|
|
# detects lxc and docker containers
|
|
detect_lxc()
|
|
{
|
|
[ -z "$PLESK_LXC_RESULT" ] || return $PLESK_LXC_RESULT
|
|
PLESK_LXC_RESULT=1
|
|
PLESK_LXC=0
|
|
if { [ -f /proc/1/cgroup ] && grep -q 'docker\|lxc' /proc/1/cgroup; } || \
|
|
{ [ -f /proc/1/environ ] && cat /proc/1/environ | tr \\0 \\n | grep -q "container=lxc"; };
|
|
then
|
|
PLESK_LXC_RESULT=0
|
|
PLESK_LXC=1
|
|
fi
|
|
return "$PLESK_LXC_RESULT"
|
|
}
|
|
|
|
call_optional_function()
|
|
{
|
|
local type_output="`LC_ALL=C type \"$1\" 2>/dev/null | head -n 1`"
|
|
case "$type_output" in
|
|
*function)
|
|
"$@"
|
|
;;
|
|
*)
|
|
return 0
|
|
;;
|
|
esac
|
|
}
|
|
|
|
get_random_string()
|
|
{
|
|
local str_length="$1"
|
|
local str_symbols="$2"
|
|
if [ -x "$PRODUCT_ROOT_D/admin/sbin/random_str" -a -z "$str_symbols" ]; then
|
|
"$PRODUCT_ROOT_D/admin/sbin/random_str" "$str_length"
|
|
else
|
|
# random_str utility may be unavailable in pre phase
|
|
if [ -z "$str_length" ]; then
|
|
str_length="14"
|
|
fi
|
|
if [ -z "$str_symbols" ]; then
|
|
str_symbols="A-Za-z0-9_"
|
|
fi
|
|
|
|
< /dev/urandom tr -dc "$str_symbols" 2>/dev/null | head -c "$str_length" 2>/dev/null
|
|
fi
|
|
}
|
|
|
|
sequence()
|
|
{
|
|
if type seq >/dev/null 2>&1; then
|
|
seq $*
|
|
elif type jot >/dev/null 2>&1; then
|
|
jot $*
|
|
else
|
|
die "Unable to find seq or jot command"
|
|
fi
|
|
}
|
|
|
|
get_ini_conf_var()
|
|
{
|
|
local conf="$1"
|
|
local section="$2"
|
|
local param="$3"
|
|
|
|
[ -n "$conf" -a -n "$param" ] || die "get_ini_conf_var(): required parameters missing"
|
|
|
|
local section_empty=0
|
|
[ -n "$section" ] || section_empty=1
|
|
|
|
perl -n -e 'BEGIN { $insect='$section_empty' }
|
|
next if (/^\s*;/);
|
|
$insect=0 if (/^\s*\[.*\]/);
|
|
$insect=1 if (/^\s*\['$section'\]/);
|
|
$val = $2, $val =~ s/\s+$//, print $val . "\n"
|
|
if ($insect && /^\s*('$param')\s*=\s*([^;\n]*)(;.*)?$/);' $conf | head -n 1
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
set_xinetd_params()
|
|
{
|
|
xinetd_conf="/etc/xinetd.conf"
|
|
xinetd_service="xinetd"
|
|
xinetd_dir="/etc/xinetd.d"
|
|
}
|
|
|
|
problems_log_tail()
|
|
{
|
|
[ -f "$product_problems_log" ] || return 0
|
|
{
|
|
tac "$product_problems_log" | awk '/^START/ { exit } { print }' | tac
|
|
} 2>/dev/null
|
|
}
|
|
|
|
product_log_tail()
|
|
{
|
|
[ -f "$product_log" ] || return 0
|
|
{
|
|
tac "$product_log" | awk '/^START/ { exit } { print }' | tac
|
|
} 2>/dev/null
|
|
}
|
|
|
|
product_and_problems_log_tail()
|
|
{
|
|
product_log_tail
|
|
[ "$product_log" = "$product_problems_log" ] || problems_log_tail
|
|
}
|
|
|
|
log_is_in_dev()
|
|
{
|
|
test "${1:0:5}" = "/dev/"
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
get_pid()
|
|
{
|
|
local i
|
|
|
|
local ex_f="$1"
|
|
local opt="$2"
|
|
local owner="$3"
|
|
|
|
local min_num="1"
|
|
local ps_long="ps axuw"
|
|
|
|
# Use pidof by default, bug 121868, except for FreeBSD - 140182
|
|
if type pidof >/dev/null 2>&1 && [ "$os" != "BSD" ]; then
|
|
for pid in `pidof -o $$ -o $PPID -o %PPID -x $ex_f`; do
|
|
# Check for owner
|
|
[ "$opt" = "true" -a "$owner" != "`ps -p $pid -o ruser=`" ] && continue
|
|
min_num=$pid
|
|
break
|
|
done
|
|
common_var=$min_num
|
|
return $min_num
|
|
fi
|
|
|
|
case "$opt" in
|
|
false)
|
|
for i in `$ps_long | grep $ex_f | grep -v grep | grep -v httpsdctl | grep -v apachectl | awk '{print $2}' -`; do
|
|
min_num=$i
|
|
break
|
|
done
|
|
;;
|
|
true)
|
|
for i in `$ps_long | grep $ex_f | grep -v grep | grep -v httpsdctl | grep -v apachectl | grep "$owner" | awk '{print $2}' -`; do
|
|
min_num=$i
|
|
break
|
|
done
|
|
;;
|
|
*)
|
|
p_echo "get_pid: wrong parameter"
|
|
die "get_pid $ex_f $opt $owner"
|
|
;;
|
|
esac
|
|
|
|
common_var=$min_num
|
|
return $min_num
|
|
}
|
|
|
|
wait_after_stop()
|
|
{
|
|
PIDS=`echo "$1" | tr ' ' ,`
|
|
count=${2:-50}
|
|
|
|
echo_try "Terminate processes $PIDS" >> $product_log
|
|
|
|
while [ 0$count -gt 0 ]; do
|
|
if [ "X$machine" = "XDarwin" ]; then
|
|
col_procs="`ps -p $PIDS 2>/dev/null|wc -l| xargs echo`"
|
|
[ 0$col_procs -lt 2 ] && break
|
|
else
|
|
ps -p $PIDS > /dev/null 2>&1 || break
|
|
fi
|
|
|
|
count=`expr $count - 1`
|
|
[ 0$count -eq 0 ] && kill -9 $1 > /dev/null 2>&1
|
|
|
|
sleep 1
|
|
done
|
|
|
|
suc
|
|
return 0
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
construct_report_template()
|
|
{
|
|
local severity="${1:-error}"
|
|
local summary="$2"
|
|
|
|
local update_ticket="`get_update_ticket`"
|
|
|
|
set_error_report_source
|
|
set_error_report_component
|
|
set_error_report_params
|
|
set_error_report_environment
|
|
|
|
true construct_report_code construct_report_debug construct_report_message
|
|
|
|
cat <<-EOL
|
|
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<error>
|
|
<source>$report_source</source>
|
|
<severity>$severity</severity>
|
|
<datetime>`date --iso-8601=seconds`</datetime>
|
|
|
|
<component>$report_component</component>
|
|
<summary><![CDATA[`echo "$summary" | sed -e 's/\]\]>/] ]>/g'`]]></summary>
|
|
<message encoding="base64">`construct_report_message | base64`</message>
|
|
|
|
<additional_info>
|
|
<component_params encoding="base64">$report_params</component_params>
|
|
<code encoding="base64">`construct_report_code | base64`</code>
|
|
<debug encoding="base64">`construct_report_debug | base64`</debug>
|
|
<environment encoding="base64">$report_environment</environment>
|
|
<update_ticket>$update_ticket</update_ticket>
|
|
</additional_info>
|
|
</error>
|
|
EOL
|
|
}
|
|
|
|
construct_report_code()
|
|
{
|
|
local call_level=${1:-5}
|
|
local func_level=$[call_level - 1]
|
|
local lineno_func=${BASH_LINENO[ $func_level ]}
|
|
local script_name=${BASH_SOURCE[ $[func_level + 1] ]}
|
|
|
|
echo "# Call of ${FUNCNAME[$func_level]}() from ${FUNCNAME[$[func_level + 1]]}() at `readlink -m $script_name`:${BASH_LINENO[$func_level]}"
|
|
head -n $[lineno_func + 4] "$script_name" 2>/dev/null | tail -n 8
|
|
}
|
|
|
|
construct_report_debug()
|
|
{
|
|
local call_level=${1:-5}
|
|
call_level=$[call_level-1]
|
|
|
|
# Generate calls stack trace.
|
|
for i in `seq $call_level ${#FUNCNAME[@]}`; do
|
|
[ "${FUNCNAME[$i]}" != "main" ] || break
|
|
|
|
local func_call="`sed -n -e "${BASH_LINENO[$i]}p" "${BASH_SOURCE[$[i+1]]}" 2>/dev/null |
|
|
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`"
|
|
[ -n "$func_call" -a -z "${func_call##*${FUNCNAME[$i]}*}" ] || func_call="${FUNCNAME[$i]}"
|
|
echo "#$[i - $call_level] `readlink -m ${BASH_SOURCE[$[i+1]]}`(${BASH_LINENO[$i]}): $func_call"
|
|
done
|
|
}
|
|
|
|
construct_report_message()
|
|
{
|
|
product_and_problems_log_tail
|
|
|
|
echo ""
|
|
if [ -n "$report_context" ]; then
|
|
echo "Context: $report_context"
|
|
echo ""
|
|
fi
|
|
if [ -n "$RP_LOADED_PATCHES" ]; then
|
|
echo "Loaded runtime patches: $RP_LOADED_PATCHES"
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
# Construct report to send it to our errors tracker
|
|
construct_report()
|
|
{
|
|
local severity="${1:-error}"
|
|
local summary="$2"
|
|
|
|
[ -n "$summary" ] || int_err "Unable to send error report. Some parameters are not defined."
|
|
|
|
set_error_report_source
|
|
get_product_versions
|
|
|
|
construct_report_template "$severity" "$summary" \
|
|
| $PRODUCT_ROOT_D/admin/bin/send-error-report --version "$product_this_version" $report_source >/dev/null 2>&1
|
|
}
|
|
|
|
# Use this function to report failed actions.
|
|
# Typical report should contain
|
|
# - reason or problem description (example: file copying failed)
|
|
# - how to resolve or investigate problem (example: check file permissions, free disk space)
|
|
# - how to re-run action (example: perform specific command, restart bootstrapper script, run installation again)
|
|
report_problem()
|
|
{
|
|
local severity="${1:-error}"
|
|
|
|
# Get first string of error as a summary of report
|
|
shift
|
|
|
|
local summary="$1"
|
|
|
|
[ -n "$product_problems_log" ] || product_problems_log="/dev/stderr"
|
|
|
|
p_echo
|
|
if [ "0$problems_occured" -eq 0 ]; then
|
|
echo "***** $process problem report *****" >> "$product_problems_log" 2>&1
|
|
fi
|
|
for problem_message in "$@"; do
|
|
p_echo "$problem_message"
|
|
if [ "$product_log" != "$product_problems_log" ]; then
|
|
echo "$problem_message" >> "$product_problems_log" 2>&1
|
|
fi
|
|
done
|
|
p_echo
|
|
|
|
construct_report "$severity" "$summary"
|
|
|
|
[ -n "$PLESK_INSTALLER_DEBUG" -o -n "$PLESK_INSTALLER_VERBOSE" ] || \
|
|
product_log_tail
|
|
|
|
problems_occured=1
|
|
}
|
|
|
|
set_error_report_source()
|
|
{
|
|
[ -z "$1" ] || report_source="$1"
|
|
[ -n "$report_source" ] || {
|
|
if [ -n "$PACKAGE_ID" -o -n "$PACKAGE_ACTION" -o -n "$PACKAGE_NAME" -o -n "$PACKAGE_VERSION" ]; then
|
|
report_source="install"
|
|
else
|
|
report_source="backend"
|
|
fi
|
|
}
|
|
}
|
|
|
|
set_error_report_component()
|
|
{
|
|
local component="$1"
|
|
|
|
if [ "$report_source" = "install" ]; then
|
|
[ -n "$report_component" ] || report_component="$PACKAGE_ID"
|
|
return 0
|
|
fi
|
|
|
|
[ -z "$component" ] || report_component="$1"
|
|
[ -n "$report_component" ] || report_component="`basename $0`"
|
|
}
|
|
|
|
set_error_report_params()
|
|
{
|
|
if [ "$report_source" = "install" ]; then
|
|
[ -n "$report_params" ] || report_params="`echo "$PACKAGE_ACTION of $PACKAGE_NAME $PACKAGE_VERSION" | base64`"
|
|
return 0
|
|
fi
|
|
|
|
[ -z "$*" ] || report_params="`echo "$*" | base64`"
|
|
[ -n "$report_params" ] || report_params="`echo "$PLESK_SCRIPT_COMMAND_LINE" | base64`"
|
|
}
|
|
|
|
detect_virtualization()
|
|
{
|
|
detect_vz
|
|
detect_lxc
|
|
local is_docker="`[ -f "/.dockerenv" ] && echo yes || :`"
|
|
local systemd_detect_virt_ct="`/usr/bin/systemd-detect-virt -c 2>/dev/null | grep -v '^none$' || :`"
|
|
local systemd_detect_virt_vm="`/usr/bin/systemd-detect-virt -v 2>/dev/null | grep -v '^none$' || :`"
|
|
local virt_what="`/usr/sbin/virt-what 2>/dev/null | xargs || :`"
|
|
|
|
if [ -n "$is_docker" ]; then
|
|
echo "docker $virt_what"
|
|
elif [ "$PLESK_VZ" = "1" ]; then
|
|
echo "${PLESK_VZ_TYPE:-virtuozzo}"
|
|
elif [ "$PLESK_LXC" = "1" ]; then
|
|
echo "lxc $virt_what"
|
|
elif [ -n "$systemd_detect_virt_ct" ]; then
|
|
echo "$systemd_detect_virt_ct $systemd_detect_virt_vm"
|
|
elif [ -n "$virt_what" ]; then
|
|
echo "$virt_what"
|
|
elif [ -n "$systemd_detect_virt_vm" ]; then
|
|
echo "$systemd_detect_virt_vm"
|
|
fi
|
|
}
|
|
|
|
default_error_report_environment()
|
|
{
|
|
local virtualization="`detect_virtualization`"
|
|
|
|
if [ -n "$virtualization" ]; then
|
|
echo "virtualization: $virtualization"
|
|
fi
|
|
}
|
|
|
|
set_error_report_environment()
|
|
{
|
|
[ -z "$*" ] || report_environment="`echo "$*" | base64`"
|
|
[ -n "$report_environment" ] || report_environment="`default_error_report_environment | base64`"
|
|
}
|
|
|
|
get_update_ticket()
|
|
{
|
|
[ -r $PRODUCT_ROOT_D/var/update_ticket ] && cat $PRODUCT_ROOT_D/var/update_ticket | awk '{$1=$1};1'
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
#
|
|
# Support for runtime patching of shell scripts (including utilities and package scripts).
|
|
#
|
|
|
|
# --- Service functions ---
|
|
|
|
# Load and apply a patch in a relatively safe way
|
|
rp_safe_load_patch()
|
|
{
|
|
local patch_file="$1"
|
|
echo_try "load shell patch '$patch_file'"
|
|
/bin/sh -n "$RP_BASEDIR/$patch_file" &&
|
|
{
|
|
. "$RP_BASEDIR/$patch_file"
|
|
RP_LOADED_PATCHES="$RP_LOADED_PATCHES $patch_file"
|
|
} &&
|
|
suc
|
|
}
|
|
|
|
# Apply patches specific to the current context (e.g., depending on utility basename or package name)
|
|
# This is currently not implemented. This may be overriden by "spark".
|
|
rp_patch_runtime_context_specific()
|
|
{
|
|
:
|
|
}
|
|
|
|
# --- Main entry points ---
|
|
|
|
rp_patch_runtime()
|
|
{
|
|
# List of loaded patch files
|
|
RP_LOADED_PATCHES=
|
|
|
|
local RP_BASEDIR="$PRODUCT_BOOTSTRAPPER_DIR/rp"
|
|
[ -d "$RP_BASEDIR" ] || return 0
|
|
|
|
if [ -r "$RP_BASEDIR/spark" ]; then
|
|
rp_safe_load_patch "spark"
|
|
fi
|
|
|
|
call_optional_function rp_patch_runtime_context_specific "$@"
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
get_user_id()
|
|
{
|
|
local name="$1"
|
|
|
|
[ -n "$name" ] || int_err "Wrong value of argument 'name': $name"
|
|
|
|
getent passwd "$name" 2>/dev/null | awk -F':' '{print $3}'
|
|
}
|
|
|
|
get_group_id()
|
|
{
|
|
local name="$1"
|
|
|
|
[ -n "$name" ] || int_err "Wrong value of argument 'name': $name"
|
|
|
|
getent group "$name" 2>/dev/null | awk -F':' '{print $3}'
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh
|
|
|
|
initial_conf()
|
|
{
|
|
PRODNAME="psa"
|
|
PRODUCT_NAME="psa"
|
|
product=${PRODNAME}
|
|
PRODUCT_FULL_NAME="Plesk"
|
|
|
|
product_etc="/etc/${PRODNAME}"
|
|
prod_conf_t="/etc/psa/psa.conf"
|
|
|
|
support_contact="https://support.plesk.com/"
|
|
|
|
conceived_os_vendor=Ubuntu
|
|
conceived_os_version="24.04"
|
|
|
|
clients_group="psacln"
|
|
clients_GID="10001"
|
|
|
|
services_group="psaserv"
|
|
services_GID="10003"
|
|
|
|
product_suff="saved_by_${product}".`date "+%m.%d;%H:%M"`
|
|
product_suffo="saved_by_${product}"
|
|
|
|
# plesk default password
|
|
PRODUCT_DEFAULT_PASSWORD="setup"
|
|
}
|
|
|
|
get_my_cnf_param()
|
|
{
|
|
local r=
|
|
|
|
local my_cnf
|
|
find_my_cnf "non-fatal" && \
|
|
r=`perl -e '$p="'"$1"'";
|
|
undef $/; $_=<>; s/#.*$//gm;
|
|
/\[mysqld\](.*?)\[/sg;
|
|
$_=substr($1, rindex $1,"$p") and
|
|
/$p\s*=(.*)/m and print $1
|
|
' ${my_cnf}`
|
|
echo $r
|
|
}
|
|
|
|
get_mysql_socket()
|
|
{
|
|
# Marked as local as it's not used anywhere else now.
|
|
local mysql_socket="/var/run/mysqld/mysqld.sock"
|
|
|
|
local mysqlsock=`get_my_cnf_param socket`
|
|
local MYSQL_SOCKETS="/var/lib/mysql/mysql.sock /tmp/mysql.sock /var/run/mysqld/mysqld.sock"
|
|
|
|
for i in $mysql_socket $mysqlsock $MYSQL_SOCKETS; do
|
|
if [ -S "$i" ]; then
|
|
# This is used internally by mysqld_safe. Maybe this whole function isn't required nowadays.
|
|
# See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-mysql-sock.html
|
|
MYSQL_UNIX_PORT=$i
|
|
export MYSQL_UNIX_PORT
|
|
mysql_socket="$i"
|
|
break
|
|
fi
|
|
done
|
|
}
|
|
|
|
selinux_close()
|
|
{
|
|
if [ -z "$SELINUX_ENFORCE" -o "$SELINUX_ENFORCE" = "Disabled" ]; then
|
|
return
|
|
fi
|
|
|
|
setenforce "$SELINUX_ENFORCE"
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh:
|
|
|
|
#set_params
|
|
|
|
set_common_params()
|
|
{
|
|
common_var=0
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
|
LANG="`get_default_locale`"
|
|
export PATH LANG
|
|
unset GREP_OPTIONS
|
|
umask 022
|
|
ulimit -n 65535 2>/dev/null
|
|
|
|
get_product_versions
|
|
|
|
certificate_file="$PRODUCT_ETC_D/httpsd.pem"
|
|
services="/etc/services"
|
|
|
|
crontab="/usr/bin/crontab"
|
|
|
|
SYSTEM_RC_D="/etc/init.d"
|
|
PLESK_LIBEXEC_DIR="/usr/lib/plesk-9.0"
|
|
PLESK_DB_DIR="/var/lib/plesk"
|
|
PRODUCT_BOOTSTRAPPER_DIR="`printf "/opt/psa/bootstrapper/pp%s-bootstrapper" "$product_this_version"`"
|
|
AUTOGENERATED_CONFIGS="#ATTENTION!\n#\n#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,\n#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.\n"
|
|
AUTOGENERATED_CONFIGS_UPGRADE="#ATTENTION!\n#\n#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,\n#SO ALL YOUR CHANGES WILL BE LOST AFTER YOU UPGRADE PLESK.\n"
|
|
PRODUCT_LOGS_D="/var/log/plesk"
|
|
|
|
sendmail="/usr/sbin/sendmail"
|
|
ps="ps axw"
|
|
ifconfig="/sbin/ifconfig -a"
|
|
|
|
machine="linux"
|
|
if [ -f /etc/debian_version ]; then
|
|
linux_distr="debian"
|
|
else
|
|
linux_distr="redhat"
|
|
fi
|
|
|
|
dummy_home="/"
|
|
if [ -x /usr/sbin/nologin ]; then
|
|
dummy_shell="/usr/sbin/nologin"
|
|
else
|
|
dummy_shell="/bin/false"
|
|
fi
|
|
|
|
rp_patch_runtime
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
set_sw_engine_params()
|
|
{
|
|
sw_engine_service="sw-engine"
|
|
sw_engine_process="${sw_engine_service}-fpm"
|
|
}
|
|
|
|
get_product_versions()
|
|
{
|
|
# Don't use global variables set elsewhere in this code. Use substitutions if needed.
|
|
local prod_root_d="/opt/psa"
|
|
|
|
product_name="psa"
|
|
|
|
if [ -z "$product_this_version" ]; then
|
|
# 1. Try to fetch version from file created by bootstrapper (should be 3-component).
|
|
product_this_version="`cat "/var/lock/plesk-target-version" 2>/dev/null`"
|
|
# 2. Fallback to $PRODUCT_ROOT_D/version (should be 3-component).
|
|
if [ -z "$product_this_version" -a -r "$prod_root_d/version" ]; then
|
|
product_this_version="`awk '{ print $1 }' "$prod_root_d/version"`"
|
|
fi
|
|
# 3. Fallback to hardcoded version (2-component). This may cause some other code to fail.
|
|
if [ -z "$product_this_version" ]; then
|
|
product_this_version="18.0"
|
|
echo "Unable to determine \$product_this_version, will use less precise value '$product_this_version'" >&2
|
|
fi
|
|
fi
|
|
|
|
product_version="$product_this_version"
|
|
|
|
if [ -z "$product_prev_version" ]; then
|
|
if [ -r "$prod_root_d/version.upg" ]; then
|
|
product_prev_version=`awk '{ print $1 }' "$prod_root_d/version.upg"`
|
|
elif [ -r "$prod_root_d/version" ]; then
|
|
product_prev_version=`awk '{ print $1 }' "$prod_root_d/version"`
|
|
else
|
|
product_prev_version="$product_this_version"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
true exim_status_linux_debian
|
|
exim_status_linux_debian()
|
|
{
|
|
get_pid /usr/lib/exim/exim3 false
|
|
local pid=$common_var
|
|
|
|
if test "$pid" -ne 1; then
|
|
#running
|
|
return 0;
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
set_mysql_auth()
|
|
{
|
|
# This function requires set_mysql_server_params and set_mysql_client_params (or set_mysqld_params)
|
|
# to be called before
|
|
local inten="set up mysql authentication"
|
|
local dsn_plesk_host="`get_dsn plesk host`"
|
|
local dsn_plesk_port="`get_dsn plesk port`"
|
|
local dsn_plesk_username="`get_dsn plesk username`"
|
|
local dsn_plesk_password="`get_dsn plesk password`"
|
|
|
|
get_admin_passwd
|
|
|
|
[ -n "$dsn_plesk_host" ] || pleskrc mysql start
|
|
|
|
mysql_host="${dsn_plesk_host:+--host=$dsn_plesk_host}"
|
|
mysql_port="${dsn_plesk_port:+--port=$dsn_plesk_port}"
|
|
mysql_user="--user=${dsn_plesk_username:-admin}"
|
|
mysql_passwd="${dsn_plesk_password:-$admin_passwd}"
|
|
|
|
if find_my_cnf 'non-fatal'; then
|
|
mysql_defaults="--defaults-file=$my_cnf"
|
|
else
|
|
mysql_defaults="--no-defaults"
|
|
fi
|
|
|
|
if [ -z "$PLESK_MYSQL_AUTH_SKIP_CONNECTION_CHECK" ]; then
|
|
mysql_test_connection 10 || die "$inten"
|
|
fi
|
|
suc
|
|
}
|
|
|
|
get_admin_passwd()
|
|
{
|
|
[ -z "$admin_passwd" ] || return 0
|
|
|
|
if [ -f "$mysql_passwd_file" ]; then
|
|
admin_passwd=`cat "$mysql_passwd_file"`
|
|
return 0
|
|
fi
|
|
|
|
admin_passwd=`get_random_string 1 'A-Z'`
|
|
admin_passwd+=`get_random_string 1 'a-z'`
|
|
admin_passwd+=`get_random_string 1 '0-9'`
|
|
admin_passwd+=`get_random_string 1 '_%=+\-@<>:.,:'`
|
|
admin_passwd+=`get_random_string 10 'A-Za-z0-9_%=+\-@<>:.,:'`
|
|
admin_passwd=`printf "%s" "$admin_passwd" | fold -w 1 | shuf - | tr -d '\n'`
|
|
|
|
[ -n "$admin_passwd" ] || admin_passwd="$PRODUCT_DEFAULT_PASSWORD"
|
|
touch "$admin_password_needs_encryption_flag"
|
|
}
|
|
|
|
mysql_test_connection()
|
|
{
|
|
inten="establish test connection"
|
|
echo_try $inten
|
|
attempts=${1:-1}
|
|
for i in `sequence $attempts`; do
|
|
echo "" | mysql_direct mysql >> "$product_log" 2>&1
|
|
if [ "$?" -eq "0" ]; then
|
|
p_echo "connected"
|
|
return 0
|
|
fi
|
|
[ "$attempts" -eq "1" ] || sleep 1
|
|
done
|
|
|
|
p_echo "failed"
|
|
return 1
|
|
}
|
|
|
|
find_my_cnf()
|
|
{
|
|
local non_fatal="$1"
|
|
local cnf_files="/etc/my.cnf /etc/mysql/my.cnf /var/db/mysql/my.cnf"
|
|
|
|
for my_cnf in $cnf_files; do
|
|
if [ -f ${my_cnf} ]; then
|
|
break
|
|
fi
|
|
done
|
|
|
|
[ -f "$my_cnf" -o -n "$non_fatal" ] || {
|
|
local msg="find the MySQL server configuration file. \
|
|
If you use a third-party MySQL server build, make sure you do not use implicit default configuration \
|
|
and you have the MySQL configuration file in one of the following locations: $cnf_files"
|
|
echo "Failed to $msg" | write_structured_report 'stage=mysqlsetup' 'level=fatal' 'errtype=mysqlnomycnf' "mycnffiles=$cnf_files" || :
|
|
die "$msg"
|
|
}
|
|
|
|
[ -f "$my_cnf" ] || return 1
|
|
|
|
my_cnf_d=`awk '/^\s*!includedir\>/ {print $2}' "$my_cnf" | head -1`
|
|
|
|
return 0
|
|
}
|
|
|
|
set_mysql_server_params()
|
|
{
|
|
get_mysql_socket
|
|
|
|
if [ -n "/lib/systemd/system" -a -f "/lib/systemd/system/mariadb.service" ]; then
|
|
mysql_service="mariadb"
|
|
elif [ -n "/lib/systemd/system" -a -f "/lib/systemd/system/mysqld.service" ]; then
|
|
# Percona server
|
|
mysql_service="mysqld"
|
|
elif [ -n "/lib/systemd/system" -a -f "/lib/systemd/system/mysql.service" ]; then
|
|
# MySQL 8 installations on debian / ubuntu
|
|
mysql_service="mysql"
|
|
elif [ -x "${PRODUCT_RC_D}/mysql" ]; then
|
|
mysql_service="mysql"
|
|
elif [ -x "${PRODUCT_RC_D}/mysql.sh" ]; then
|
|
mysql_service="mysql.sh"
|
|
elif [ -x "${PRODUCT_RC_D}/mysqld" ]; then
|
|
mysql_service="mysqld"
|
|
elif [ -x "${PRODUCT_RC_D}/mysql" ]; then
|
|
mysql_service="mysql"
|
|
else
|
|
die "detect MySQL service name"
|
|
fi
|
|
}
|
|
|
|
set_mysql_client_params()
|
|
{
|
|
mysql_client="$MYSQL_BIN_D/mysql"
|
|
[ -f "$MYSQL_BIN_D/mariadb" ] && mysql_client="$MYSQL_BIN_D/mariadb"
|
|
|
|
# Override this variable as needed
|
|
mysql_db_name="$PRODNAME"
|
|
mysql_passwd_file="$product_etc/.${PRODNAME}.shadow"
|
|
|
|
mysql_args="-N"
|
|
mysql_args_raw="-Br"
|
|
|
|
local dsn_plesk_dbname="`get_dsn plesk dbname`"
|
|
[ -z "$dsn_plesk_dbname" ] || mysql_db_name="$dsn_plesk_dbname"
|
|
}
|
|
|
|
#Invoke mysql
|
|
dbclient_invoke()
|
|
{
|
|
mysql_anydb -D$mysql_db_name "$@"
|
|
}
|
|
|
|
mysql_anydb()
|
|
{
|
|
(
|
|
export MYSQL_PWD="$mysql_passwd"
|
|
$mysql_client $mysql_defaults $mysql_host $mysql_port $mysql_user $mysql_args "$@" 2>>"$product_log"
|
|
local status=$?
|
|
|
|
if [ $status -gt 0 ]; then
|
|
$mysql_client $mysql_defaults $mysql_host $mysql_port $mysql_user $mysql_args -D$mysql_db_name $mysql_args_raw -e "SHOW ENGINE innodb status" >>"$product_log" 2>&1
|
|
fi
|
|
unset MYSQL_PWD
|
|
return $status
|
|
)
|
|
}
|
|
|
|
# Invoke mysql without any wrapper or something else
|
|
mysql_direct()
|
|
{
|
|
# a bit dirty but it works properly for passwords with spaces, quotes and double quotes:
|
|
if [ -n "$mysql_passwd" ]; then
|
|
(
|
|
export MYSQL_PWD="$mysql_passwd"
|
|
$mysql_client $mysql_defaults $mysql_host $mysql_port $mysql_user $mysql_args "$@" 2>>"$product_log"
|
|
rc=$?
|
|
unset MYSQL_PWD
|
|
return $rc
|
|
)
|
|
else
|
|
$mysql_client $mysql_defaults $mysql_host $mysql_port $mysql_user $mysql_args "$@" 2>>"$product_log"
|
|
fi
|
|
}
|
|
|
|
# Invoke mysql in raw mode
|
|
mysql_raw()
|
|
{
|
|
dbclient_invoke $mysql_args_raw "$@"
|
|
}
|
|
|
|
uses_mysql_client()
|
|
{
|
|
# Initialize local MySQL authentication parameters and test connection.
|
|
# After that db_*() and mysql*() functions may be used.
|
|
# Any MySQL-specific overrides (e.g., local mysql_db_name="whatever") should appear
|
|
# *after* calling this function.
|
|
# This function is for use in component installers that require access to MySQL DB.
|
|
|
|
set_mysql_server_params
|
|
set_mysql_client_params
|
|
set_mysql_auth
|
|
}
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# -*- vim:ft=sh
|
|
|
|
# MySQL service action handlers
|
|
|
|
### FIXME: probably need var service_restart warn
|
|
true mysql_stop
|
|
mysql_stop()
|
|
{
|
|
local op_result i
|
|
|
|
inten="stop MySQL server"
|
|
echo_try $inten
|
|
|
|
service_ctl stop $mysql_service mysql
|
|
op_result=$?
|
|
|
|
if [ "X$linux_distr" = "Xdebian" ]; then
|
|
# Debian has well designed mysql stopping code
|
|
[ "$op_result" -eq 0 ] || die $inten
|
|
suc
|
|
return 0
|
|
fi
|
|
|
|
for i in 2 4 6 8 16; do
|
|
if ! mysql_status ; then
|
|
suc
|
|
return 0
|
|
fi
|
|
|
|
# I just want to be sure that mysql really stopped
|
|
killall -TERM mysqld mysql safe_mysqld mysqld_safe >> $product_log 2>&1
|
|
|
|
sleep $i
|
|
done
|
|
|
|
die "$inten"
|
|
}
|
|
|
|
true mysql_status
|
|
mysql_status()
|
|
{
|
|
# Previously this handler also checked for mysqld pid on Debian systems. Should not be needed nowadays.
|
|
service_ctl status $mysql_service mysql
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
# vim:ft=sh:
|
|
|
|
set_named_params()
|
|
{
|
|
# set up default values
|
|
bind_UID=53
|
|
bind_GID=53
|
|
bind_user="bind";
|
|
bind_group="bind";
|
|
|
|
# get UID of named user, if exists
|
|
bind_UID="`get_user_id $bind_user`"
|
|
|
|
# get GID of named group, if exists
|
|
bind_GID="`get_group_id $bind_group`"
|
|
|
|
# path to directory of internal named
|
|
NAMED_ROOT_D="${PRODUCT_ROOT_D:?'PRODUCT_ROOT_D is undefined'}/named"
|
|
|
|
# path to directory of named pid file
|
|
bind_run="${NAMED_RUN_ROOT_D:?'NAMED_RUN_ROOT_D is undefined'}/var/run/named"
|
|
|
|
named_bin="/usr/sbin/named"
|
|
named_service="named"
|
|
named_log="/dev/null"
|
|
|
|
named_sysconf_file="/etc/default/$named_service"
|
|
|
|
# path to named config file
|
|
named_conf="/etc/named.conf"
|
|
named_run_root_template="/opt/psa/var/run-root.tar"
|
|
rndc_conf="/etc/rndc.conf"
|
|
rndc_namedb_conf="/etc/namedb/rndc.conf"
|
|
rndc_bind_conf="/etc/bind/rndc.conf"
|
|
named_user_options_conf="/etc/named-user-options.conf"
|
|
|
|
#140025. Restrict CPU cores for Bind
|
|
bind_number_of_workers=2
|
|
}
|
|
|
|
true postfix_status
|
|
postfix_status()
|
|
{
|
|
# here be dragons.
|
|
# the practical experience shows that simple checking of status of
|
|
# Postfix "master" process is not enough. So we read Postfix master
|
|
# process pid file if any, then try to look for a process with
|
|
# name ``qmgr'' and parent pid being equal to
|
|
# the pid read from the pidfile. If pgrep finds such a process
|
|
# it returns 0, if not its exit status is non-zero.
|
|
# pgrep is portable enough to prefer it to "hand-made" alternatives
|
|
# such as famous ``ps | grep $name | grep -v grep...'' pipes
|
|
# bug 147822. do not interrupt installation for FreeBSD
|
|
|
|
[ -f "/var/spool/postfix/pid/master.pid" ] || return 1
|
|
|
|
local ppid
|
|
|
|
read ppid </var/spool/postfix/pid/master.pid 2>/dev/null
|
|
if [ $? -ne 0 -o -z "$ppid" ]; then
|
|
# not found or other error
|
|
return 1;
|
|
fi
|
|
pgrep -P $ppid qmgr >/dev/null 2>/dev/null
|
|
}
|
|
|
|
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.
|
|
|
|
LANG="`get_default_locale`"
|
|
export LANG
|
|
|
|
PRODUCT_NAME="psa"
|
|
PRODNAME="psa"
|
|
PRODUCT_ROOT_D="/opt/psa"
|
|
PRODUCT_UTILS_DIR="${PRODUCT_ROOT_D}/admin/sbin"
|
|
|
|
set_sw_engine_params
|
|
|
|
sw_cp_server_service="sw-cp-server"
|
|
mailer_service="$PRODUCT_UTILS_DIR/mailmng-service"
|
|
spamfilter_service="spamassassin"
|
|
|
|
status()
|
|
{
|
|
local proc_name="$1"
|
|
local pid
|
|
|
|
pid=`get_pid ${proc_name}`
|
|
if [ "X$pid" != "X" ] ; then
|
|
echo "${proc_name} (pid $pid) is running..."
|
|
return 0
|
|
fi
|
|
|
|
echo "${proc_name} is stopped"
|
|
return 1
|
|
}
|
|
|
|
is_boot_mode()
|
|
{
|
|
[ -z "$RUNLEVEL" ] && return 1 || return 0
|
|
}
|
|
|
|
get_local_mail_setting()
|
|
{
|
|
local setting_name="$1"
|
|
local default_value="$2"
|
|
local setting_val rc
|
|
|
|
db_select "SELECT value FROM ServiceNodeConfiguration WHERE serviceNodeId=1 AND section='mailServer' AND name='$setting_name'"
|
|
rc="$?"
|
|
|
|
[ -n "$db_select_output" ] && setting_val="$db_select_output" || setting_val="$default_value"
|
|
eval mail_${setting_name}="$setting_val"
|
|
return $rc
|
|
}
|
|
|
|
get_pids_byname()
|
|
{
|
|
proc_name="$1"
|
|
PIDS=`ps axww | awk '$5 ~ "'$proc_name'$" {print $1}'`
|
|
echo $PIDS
|
|
}
|
|
|
|
define_virusfilter()
|
|
{
|
|
local mail_virusfilter
|
|
get_local_mail_setting virusfilter none
|
|
|
|
case $mail_virusfilter in
|
|
kav)
|
|
set_kav_params
|
|
virusfilter_service="kav"
|
|
;;
|
|
drweb)
|
|
set_drweb_params
|
|
virusfilter_service="drweb"
|
|
;;
|
|
*)
|
|
virusfilter_service=""
|
|
;;
|
|
esac
|
|
}
|
|
|
|
rc_syntax()
|
|
{
|
|
if test -z "$LINES" -o -z "$COLUMNS" ; then
|
|
eval `exec 3<&1; stty size <&3 2>/dev/null | (read L C; \
|
|
echo LINES=${L:-24} COLUMNS=${C:-80})`
|
|
fi
|
|
|
|
if test -t 1 -a "$TERM" != "raw" -a "$TERM" != "dumb" && stty size <&1 > /dev/null 2>&1 ; then
|
|
esc=`echo -en "\033"`
|
|
extd="${esc}[1m"
|
|
warn="${esc}[1;31m"
|
|
attn="${esc}[1;33m"
|
|
norm=`echo -en "${esc}[m\017"`
|
|
stat=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"`
|
|
done="${esc}[1;32m"
|
|
else
|
|
esc=""
|
|
extd=""
|
|
warn=""
|
|
attn=""
|
|
norm=""
|
|
stat=""
|
|
done=""
|
|
fi
|
|
|
|
rc_done="${stat}${done}done${norm}"
|
|
rc_started="${stat}${done}already started${norm}"
|
|
rc_stopped="${stat}${done}already stopped${norm}"
|
|
rc_not_installed="${stat}${extd}not installed${norm}"
|
|
rc_not_used="${stat}${extd}unused${norm}"
|
|
rc_failed="${stat}${warn}failed${norm}"
|
|
|
|
# For status command
|
|
rc_running="${stat}${done}is running${norm}"
|
|
rc_not_running="${stat}${done}is not running${norm}"
|
|
}
|
|
|
|
service_start()
|
|
{
|
|
local serv_list="$1"
|
|
|
|
for i in $serv_list; do
|
|
echo -n "Starting $i service... "
|
|
|
|
if ! pleskrc "$i" "exists"; then
|
|
echo "$rc_not_installed"
|
|
continue
|
|
fi
|
|
|
|
if ! used $i; then
|
|
echo "$rc_not_used"
|
|
continue
|
|
fi
|
|
|
|
if pleskrc "$i" "status"; then
|
|
echo "$rc_started"
|
|
continue
|
|
fi
|
|
|
|
pleskrc "$i" "start" >>$product_log 2>&1 && echo "$rc_done" || echo "$rc_failed"
|
|
done
|
|
}
|
|
|
|
service_stop()
|
|
{
|
|
local serv_list="$1"
|
|
|
|
for i in $serv_list; do
|
|
echo -n "Stopping $i service... "
|
|
if ! pleskrc "$i" "exists"; then
|
|
echo "$rc_not_installed"
|
|
continue
|
|
fi
|
|
|
|
if ! used $i; then
|
|
echo "$rc_not_used"
|
|
continue
|
|
fi
|
|
|
|
if ! pleskrc "$i" "status"; then
|
|
echo "$rc_stopped"
|
|
continue
|
|
fi
|
|
|
|
pleskrc "$i" "stop" >>$product_log 2>&1 && echo "$rc_done" || echo "$rc_failed"
|
|
done
|
|
}
|
|
|
|
used()
|
|
{
|
|
local service=$1
|
|
if is_function "${service}_used"; then
|
|
"${service}_used"
|
|
return $?
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
true drweb_used
|
|
|
|
drweb_used()
|
|
{
|
|
local has_enabled_handlers="`$PRODUCT_ROOT_D/admin/sbin/mail_handlers_control --list --json |
|
|
"/usr/bin/python3" -c 'import sys, json; \
|
|
handlers = json.load(sys.stdin)["handlers"]; \
|
|
print(any(h["enabled"] for h in handlers if h["name"] == "drweb"));' 2>>$product_log`"
|
|
|
|
[ "$has_enabled_handlers" = "True" ]
|
|
}
|
|
|
|
start_service()
|
|
{
|
|
local mode="$1"
|
|
local apache_started=0
|
|
|
|
service_start "sw_engine sw_cp_server"
|
|
|
|
if ! is_boot_mode; then
|
|
service_start "mysql"
|
|
fi
|
|
|
|
if ! is_boot_mode; then
|
|
define_virusfilter
|
|
[ -x "$mailer_service" ] && mailer="mailer" || mailer=""
|
|
service_start "named $mailer spamfilter ${virusfilter_service} apache xinetd"
|
|
fi
|
|
}
|
|
|
|
stop_all()
|
|
{
|
|
define_virusfilter
|
|
service_stop "apache ${virusfilter_service} spamfilter mailer named mysql sw_cp_server sw_engine"
|
|
$PRODUCT_ROOT_D/bin/apache_cleanup.sh
|
|
}
|
|
|
|
make_lockdir()
|
|
{
|
|
local plesk_lock_dir="/run/lock/files"
|
|
[ -d "$plesk_lock_dir" ] || mkdir -p $plesk_lock_dir
|
|
|
|
local lm_lockdir="/var/lock/lmlib"
|
|
(
|
|
mkdir -p "$lm_lockdir"
|
|
chgrp lock-manager "$lm_lockdir"
|
|
chmod 770 "$lm_lockdir"
|
|
) > /dev/null 2>&1
|
|
}
|
|
|
|
start()
|
|
{
|
|
make_lockdir
|
|
start_service "start"
|
|
}
|
|
|
|
true sw_engine_start
|
|
true sw_engine_stop
|
|
|
|
sw_engine_start()
|
|
{
|
|
/etc/init.d/$sw_engine_service start >>$product_log 2>&1 && return 0
|
|
return 1
|
|
}
|
|
|
|
sw_engine_stop()
|
|
{
|
|
/etc/init.d/$sw_engine_service stop >>$product_log 2>&1
|
|
wait_after_stop "`get_pids_byname "${sw_engine_process}"`" 100 || return 1
|
|
return 0
|
|
}
|
|
|
|
true sw_cp_server_start
|
|
true sw_cp_server_stop
|
|
|
|
sw_cp_server_start()
|
|
{
|
|
/etc/init.d/$sw_cp_server_service start && return 0
|
|
return 1
|
|
}
|
|
|
|
sw_cp_server_stop()
|
|
{
|
|
/etc/init.d/$sw_cp_server_service stop
|
|
wait_after_stop "`get_pids_byname "${sw_cp_server_service}"`" 100 || return 1
|
|
return 0
|
|
}
|
|
|
|
restart()
|
|
{
|
|
pleskrc sw_cp_server stop >>$product_log 2>&1
|
|
pleskrc sw_engine stop >>$product_log 2>&1
|
|
start
|
|
}
|
|
|
|
reload()
|
|
{
|
|
pleskrc ${sw_engine_base_name} reload >>$product_log 2>&1
|
|
}
|
|
|
|
true mailer_start
|
|
true mailer_stop
|
|
true mailer_status
|
|
true mailer_restart
|
|
true mailer_reload
|
|
true mailer_exists
|
|
|
|
mailer_start()
|
|
{
|
|
$mailer_service --start-service --mail-component=daemons-only >/dev/null 2>&1 || return 1
|
|
}
|
|
|
|
mailer_stop()
|
|
{
|
|
$mailer_service --stop-service --mail-component=daemons-only >/dev/null 2>&1 || return 1
|
|
}
|
|
|
|
mailer_exists()
|
|
{
|
|
return 0
|
|
}
|
|
|
|
mailer_status()
|
|
{
|
|
# get total number of mailer services
|
|
subservno=`$mailer_service --status-service | wc -l`
|
|
# get number of running services
|
|
subservrun=`$mailer_service --status-service | grep 'is running' | wc -l`
|
|
if [ $subservrun -eq 0 ]; then
|
|
return 1
|
|
fi
|
|
if [ $subservno -ne $subservrun ]; then
|
|
# some mail services are running and some not
|
|
return 3
|
|
fi
|
|
}
|
|
|
|
mailer_restart()
|
|
{
|
|
$mailer_service --restart-service --mail-component=daemons-only >/dev/null 2>&1 || return 1
|
|
}
|
|
|
|
mailer_reload()
|
|
{
|
|
$mailer_service --reload-service --mail-component=daemons-only >/dev/null 2>&1 || return 1
|
|
}
|
|
|
|
status_of_plesk()
|
|
{
|
|
pleskrc "sw_engine" "status"
|
|
local rc="$?"
|
|
|
|
[ "$rc" = "0" ] && echo "$rc_running" || echo "$rc_not_running"
|
|
return $rc
|
|
}
|
|
|
|
rc_syntax
|
|
|
|
product_default_conf
|
|
set_common_params
|
|
initial_conf
|
|
|
|
product_log="$PRODUCT_LOGS_D/psa_service.log"
|
|
echo "===> `date`, args: $@" >> $product_log
|
|
|
|
if [ "$1" = "status" ]; then
|
|
status_of_plesk
|
|
exit $?
|
|
fi
|
|
|
|
PLESK_MYSQL_AUTH_SKIP_CONNECTION_CHECK=yes
|
|
uses_mysql_client
|
|
set_apache_params
|
|
set_named_params
|
|
set_xinetd_params
|
|
|
|
case "$1" in
|
|
start|reload|restart)
|
|
$1
|
|
;;
|
|
stop)
|
|
service_stop "sw_engine"
|
|
;;
|
|
start1)
|
|
service_start "sw_engine"
|
|
;;
|
|
startall)
|
|
start_service "startall"
|
|
;;
|
|
stopall)
|
|
stop_all
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|startall|stopall|restart|status}"
|
|
exit 1
|
|
esac
|
|
|
|
exit $?
|
|
|
|
# vim:ft=sh
|