| 1 | #!/bin/bash |
| 2 | |
| 3 | echo "Running initialization script..." |
| 4 | |
| 5 | # branch from parameter |
| 6 | if [ -z "$1" ]; then |
| 7 | echo "Error: Branch parameter is empty. Please provide a valid branch name." |
| 8 | exit 1 |
| 9 | fi |
| 10 | BRANCH="$1" |
| 11 | |
| 12 | raise_open_file_limit() { |
| 13 | local requested="${A0_NOFILE_LIMIT:-65535}" |
| 14 | local soft |
| 15 | local hard |
| 16 | local target |
| 17 | |
| 18 | if ! [[ "$requested" =~ ^[0-9]+$ ]] || [ "$requested" -lt 1 ]; then |
| 19 | echo "Warning: invalid A0_NOFILE_LIMIT='$requested'; keeping open file limit at $(ulimit -S -n)." >&2 |
| 20 | return |
| 21 | fi |
| 22 | |
| 23 | soft="$(ulimit -S -n)" |
| 24 | hard="$(ulimit -H -n)" |
| 25 | |
| 26 | if [ "$soft" = "unlimited" ]; then |
| 27 | echo "Open file limit is already unlimited." |
| 28 | return |
| 29 | fi |
| 30 | |
| 31 | target="$requested" |
| 32 | if [ "$hard" != "unlimited" ] && [ "$target" -gt "$hard" ]; then |
| 33 | target="$hard" |
| 34 | fi |
| 35 | |
| 36 | if [ "$target" -gt "$soft" ]; then |
| 37 | if ulimit -S -n "$target"; then |
| 38 | echo "Raised open file soft limit from $soft to $(ulimit -S -n) (hard: $hard)." |
| 39 | else |
| 40 | echo "Warning: failed to raise open file soft limit from $soft to $target (hard: $hard)." >&2 |
| 41 | fi |
| 42 | else |
| 43 | echo "Open file soft limit is $soft (target: $requested, hard: $hard)." |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | raise_open_file_limit |
| 48 | |
| 49 | # Copy all contents from persistent /per to root directory (/) without overwriting |
| 50 | cp -r --no-preserve=ownership,mode /per/* / |
| 51 | |
| 52 | # Ensure upload storage exists before API and connector callers can reference it. |
| 53 | mkdir -p /a0/usr/uploads |
| 54 | |
| 55 | # allow execution of /root/.bashrc and /root/.profile |
| 56 | chmod 444 /root/.bashrc |
| 57 | chmod 444 /root/.profile |
| 58 | |
| 59 | # update package list to save time later |
| 60 | apt-get update > /dev/null 2>&1 & |
| 61 | |
| 62 | # let supervisord handle the services |
| 63 | exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf |