Replace seq shell command with portable solution across codebase

Summary

The seq command is not available on all Unix-like systems and should be replaced with a more portable solution for better compatibility across different platforms.

Background

This issue was identified during the review of MR !8511 (merged) (Change SIGTERM behaviour for PgBouncer), where seq is used in a shell script loop. The seq command is a GNU coreutils utility that may not be available on systems like Alpine Linux, BSD variants, or minimal container images.

Current Usage

The seq command is currently used in shell scripts throughout the codebase, including:

  1. PgBouncer control script (files/gitlab-cookbooks/pgbouncer/templates/default/sv-pgbouncer-t.erb):

    for _i in $(seq 1 "${TIMEOUT}"); do
  2. Puma control script (mentioned in MR discussion as having similar usage)

Proposed Solution

Replace seq usage with portable POSIX-compliant alternatives:

Option 1: While loop with counter

# Instead of: for _i in $(seq 1 "${TIMEOUT}"); do
_i=1
while [ "${_i}" -le "${TIMEOUT}" ]; do
    # loop body
    _i=$((_i + 1))
done

Option 2: C-style for loop (bash-specific, if bash is guaranteed)

for ((_i=1; _i<=TIMEOUT; _i++)); do
    # loop body
done

Tasks

  • Audit the codebase to identify all uses of seq command
  • Replace seq usage in PgBouncer control script
  • Replace seq usage in Puma control script
  • Replace any other instances of seq found in shell scripts
  • Test the changes on different platforms (especially Alpine Linux)
  • Update any relevant documentation

Acceptance Criteria

  • All shell scripts work correctly on systems without GNU coreutils
  • No functionality is lost during the replacement
  • The solution maintains readability and performance
  • Changes are tested on multiple platforms

Related

  • Closes discussion in MR !8511 (merged): !8511 (comment 2604495177)
  • Related to improving cross-platform compatibility of omnibus-gitlab

Priority

This is a technical debt issue that improves portability but doesn't affect current functionality on most systems where omnibus-gitlab is typically deployed.

Assignee Loading
Time tracking Loading