Closed coderabbitai[bot] closed 2 months ago
This Convention Enhancement Proposal (CEP-5) seeks to generalize the use of the custom shlock
implementation (tool_shlock_helper.sh
) across all shell scripts within the project (excluding tool_shlock_helper.sh
itself). The goal is to ensure consistent, portable, and reliable file locking mechanisms throughout the project's shell scripts.
In the check_pip
script, a custom shlock
implementation is used to handle file locking due to inconsistencies and the lack of availability of standard shlock
tools across different environments. This custom approach has proven effective in ensuring portability and reliability.
Multiple shell scripts within the project may require file locking to prevent concurrent execution and ensure data integrity. However, relying on system-specific locking tools can lead to inconsistencies, failures, and increased maintenance overhead due to variations in tool availability and behavior across different environments.
Adopt the Custom shlock
Implementation: Standardize the use of tool_shlock_helper.sh
for file locking across all shell scripts in the project (excluding tool_shlock_helper.sh
itself to avoid circular dependencies).
Implementation Guidelines:
tool_shlock_helper.sh
: Utilize hash -p ./.github/tool_shlock_helper.sh shlock
to make the custom shlock
available as a shell command within scripts.
hash -p ./.github/tool_shlock_helper.sh shlock || exit 255
shlock
to determine if the lock was successfully acquired.
if [[ $(shlock -f "${LOCK_FILE}" -p $$) -eq 0 ]]; then
# Proceed with the script
else
printf "%s\n" "Script already in progress by $(head "${LOCK_FILE}")" >&2
exit 126
fi
trap
commands to handle signals and ensure that locks are released appropriately upon script exit or interruption.
trap 'cleanup; exit 129;' SIGHUP
trap 'cleanup; exit 143;' SIGTERM
trap 'cleanup; exit 131;' SIGQUIT
trap 'cleanup; exit 130;' SIGINT
trap 'cleanup; exit 137;' SIGABRT
trap 'cleanup; exit ${EXIT_CODE};' EXIT
TMPDIR
or /tmp
directory using a unique identifier).
LOCK_FILE="${TMPDIR:-/tmp}/org.projectname.scriptname.lock"
Documentation: Update all relevant documentation to reflect the standardization, providing clear instructions and examples for script authors.
shlock
is included in the repository and does not require external dependencies.tool_shlock_helper.sh
: Ensure the custom shlock
script is up-to-date and capable of supporting the needs of all shell scripts.shlock
: Rejected due to inconsistent availability and differing implementations across environments.flock
or Other Locking Tools: Not viable as they may not be universally available or could introduce additional dependencies.Standardizing the use of the custom shlock
implementation across all shell scripts enhances the project's portability, consistency, and reliability. CEP-5 proposes a clear path forward to achieve this standardization, minimizing dependencies on external tools and simplifying the development process.
(No normative references at this time.)
Bash Subshells Understanding Bash Subshells shlock Manual Page PR-123
_Originally posted by @coderabbitai[bot] in https://github.com/reactive-firewall/multicast/pull/123#discussion_r1770695801_
CEP-5 has been posted as a draft gitst at: https://gist.github.com/reactive-firewall/3d2bd3cf37f87974df6f7bee31a05a89
Introduction
This Convention Enhancement Proposal (CEP-5) seeks to generalize the use of the custom
shlock
implementation (tool_shlock_helper.sh
) across all shell scripts within the project (excludingtool_shlock_helper.sh
itself). The goal is to ensure consistent, portable, and reliable file locking mechanisms throughout the project's shell scripts.Background
In the
check_pip
script, a customshlock
implementation is used to handle file locking due to inconsistencies and the lack of availability of standardshlock
tools across different environments. This custom approach has proven effective in ensuring portability and reliability.Problem Statement
Multiple shell scripts within the project may require file locking to prevent concurrent execution and ensure data integrity. However, relying on system-specific locking tools can lead to inconsistencies, failures, and increased maintenance overhead due to variations in tool availability and behavior across different environments.