mirror of
https://github.com/N0rthernL1ghts/wordpress.git
synced 2025-02-04 13:32:51 +01:00
Implement proccess locking for plugin installer in order to prevent script from running on multiple instances at the same time
This commit is contained in:
parent
879df6c042
commit
47ba7873f1
|
@ -5,6 +5,13 @@ trap scriptExitHandler EXIT
|
||||||
|
|
||||||
function scriptExitHandler() {
|
function scriptExitHandler() {
|
||||||
LAST_EXIT_CODE=$?
|
LAST_EXIT_CODE=$?
|
||||||
|
|
||||||
|
# START_PROCESS is set only if script has passed the lock check
|
||||||
|
# This should ensure that the lock is lifted in any case
|
||||||
|
if [ -n "${WP_PLUGINS_PATH}" ] && [ -n "${START_PROCESS}" ]; then
|
||||||
|
rm "${WP_PLUGINS_PATH}/.installer-lock" -f
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "${LAST_EXIT_CODE}" = "0" ]; then
|
if [ "${LAST_EXIT_CODE}" = "0" ]; then
|
||||||
echo "> Script finished successfully"
|
echo "> Script finished successfully"
|
||||||
exit "${LAST_EXIT_CODE}"
|
exit "${LAST_EXIT_CODE}"
|
||||||
|
@ -56,9 +63,19 @@ function main() {
|
||||||
PLUGIN_STRICT_INSTALL="${WORDPRESS_PLUGIN_INSTALL_STRICT:-false}"
|
PLUGIN_STRICT_INSTALL="${WORDPRESS_PLUGIN_INSTALL_STRICT:-false}"
|
||||||
WP_CONTENT_PATH="/var/www/html/wp-content"
|
WP_CONTENT_PATH="/var/www/html/wp-content"
|
||||||
WP_PLUGINS_PATH="${WP_CONTENT_PATH}/plugins"
|
WP_PLUGINS_PATH="${WP_CONTENT_PATH}/plugins"
|
||||||
CONCURRENCY_LIMIT="${CONCURRENCY_LIMIT:-4}"
|
|
||||||
|
|
||||||
export WP_PLUGINS_PATH
|
# Process locking to prevent multiple instances of this script from running at the same time
|
||||||
|
if [ -f "${WP_PLUGINS_PATH}/.installer-lock" ]; then
|
||||||
|
echo "> Installer is locked by another process. Skipping installation."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
START_PROCESS="$(date +%s)"
|
||||||
|
|
||||||
|
export WP_PLUGINS_PATH START_PROCESS
|
||||||
|
touch "${WP_PLUGINS_PATH}/.installer-lock"
|
||||||
|
|
||||||
|
CONCURRENCY_LIMIT="${CONCURRENCY_LIMIT:-4}"
|
||||||
|
|
||||||
echo "> Automated WordPress Plugin Installer"
|
echo "> Automated WordPress Plugin Installer"
|
||||||
if [ -z "${PLUGIN_LIST}" ]; then
|
if [ -z "${PLUGIN_LIST}" ]; then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user