Repository navigation
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·72 lines (67 loc) · 2.55 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·72 lines (67 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -e
cd /
# Start as root only to fix the ownership of the data folders, then run
# LocalAI as an unprivileged user. The Sandbox add-on refuses to run as root,
# and a process that does not need root should not have it. A volume that an
# older image created as root is handed over on the first start. Set
# LOCALAI_RUN_AS_ROOT=true to keep the old behaviour (the sandbox is then
# unavailable). LOCALAI_UID and LOCALAI_GID change the user. A container that
# is already started as another user (docker --user, Kubernetes runAsUser) is
# left alone.
if [ "$(id -u)" = "0" ] && [ "${LOCALAI_RUN_AS_ROOT:-false}" != "true" ]; then
run_uid="${LOCALAI_UID:-10001}"
run_gid="${LOCALAI_GID:-10001}"
# LOCALAI_DATA_DIRS and LOCALAI_DEVICE_PATHS exist for the entrypoint test.
# shellcheck disable=SC2086
for dir in ${LOCALAI_DATA_DIRS:-/models /backends /configuration /data /tmp/generated}; do
[ -d "$dir" ] || continue
if [ "$(stat -c %u "$dir")" != "$run_uid" ]; then
echo "Handing $dir over to uid $run_uid (first start with the unprivileged user)"
chown -R "$run_uid:$run_gid" "$dir" || echo "warning: could not change the owner of $dir; LocalAI may not be able to write there"
fi
done
# The groups that own the devices the user needs (/dev/kvm for the sandbox,
# the render nodes of the GPUs). Group 0 is never added.
groups=""
# shellcheck disable=SC2086
for dev in ${LOCALAI_DEVICE_PATHS:-/dev/kvm /dev/kfd /dev/dri/*}; do
[ -e "$dev" ] || continue
gid="$(stat -c %g "$dev")"
case ",$groups," in *",$gid,"*) continue ;; esac
[ "$gid" = "0" ] || groups="${groups:+$groups,}$gid"
done
export HOME=/home/localai
if [ -n "$groups" ]; then
exec setpriv --reuid="$run_uid" --regid="$run_gid" --groups="$groups" -- "$0" "$@"
fi
exec setpriv --reuid="$run_uid" --regid="$run_gid" --clear-groups -- "$0" "$@"
fi
# If we have set EXTRA_BACKENDS, then we need to prepare the backends
if [ -n "$EXTRA_BACKENDS" ]; then
echo "EXTRA_BACKENDS: $EXTRA_BACKENDS"
# Space separated list of backends
for backend in $EXTRA_BACKENDS; do
echo "Preparing backend: $backend"
make -C $backend
done
fi
echo "CPU info:"
grep -e "model\sname" /proc/cpuinfo | head -1
grep -e "flags" /proc/cpuinfo | head -1
if grep -q -e "\savx\s" /proc/cpuinfo ; then
echo "CPU: AVX found OK"
else
echo "CPU: no AVX found"
fi
if grep -q -e "\savx2\s" /proc/cpuinfo ; then
echo "CPU: AVX2 found OK"
else
echo "CPU: no AVX2 found"
fi
if grep -q -e "\savx512" /proc/cpuinfo ; then
echo "CPU: AVX512 found OK"
else
echo "CPU: no AVX512 found"
fi
exec ./local-ai "$@"