-
-
Notifications
You must be signed in to change notification settings - Fork 472
Expand file tree
/
Copy pathlangflow.sh
More file actions
executable file
·195 lines (180 loc) · 7.13 KB
/
Copy pathlangflow.sh
File metadata and controls
executable file
·195 lines (180 loc) · 7.13 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash
COMMUNITY_SCRIPTS_URL="${COMMUNITY_SCRIPTS_URL:-https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main}"
source <(curl -fsSL "$COMMUNITY_SCRIPTS_URL/misc/build.func")
# Copyright (c) 2021-2026 community-scripts ORG
# Author: Yamon
# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
# Source: https://www.langflow.org/
APP="Langflow"
var_tags="${var_tags:-ai;interface}"
var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-12288}"
var_disk="${var_disk:-16}"
var_os="${var_os:-debian}"
var_version="${var_version:-13}"
var_unprivileged="${var_unprivileged:-1}"
header_info "$APP"
variables
color
catch_errors
function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -d /opt/langflow || ! -f /etc/systemd/system/langflow.service || ! -x /opt/langflow/.venv/bin/python ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
local TS BACKUP_DIR OLD_VERSION TARGET_VERSION
TS="$(date +%Y%m%d-%H%M%S)"
BACKUP_DIR="/opt/langflow/backups/${TS}"
TARGET_VERSION="${LANGFLOW_TARGET_VERSION:-latest}"
OLD_VERSION="$([ -x /opt/langflow/.venv/bin/python ] && /opt/langflow/.venv/bin/python -m pip show langflow 2>/dev/null | awk '/^Version:/ {print $2}')"
msg_info "Installed Version: ${OLD_VERSION:-unknown}"
if [[ "${TARGET_VERSION}" == "latest" ]] && ! check_for_gh_release "langflow" "langflow-ai/langflow"; then
msg_ok "Langflow is already up to date"
exit
fi
msg_info "Preparing Backup"
mkdir -p "${BACKUP_DIR}"
if [[ -f /opt/langflow/.env ]]; then
cp -a /opt/langflow/.env "${BACKUP_DIR}/.env"
fi
if compgen -G "/opt/langflow/data/langflow.db*" >/dev/null; then
cp -a /opt/langflow/data/langflow.db* "${BACKUP_DIR}/"
fi
msg_ok "Backup saved to ${BACKUP_DIR}"
msg_info "Stopping Service"
systemctl stop langflow
msg_ok "Stopped Service"
UV_PYTHON="3.12" setup_uv
UV_CONCURRENT_DOWNLOADS="${UV_CONCURRENT_DOWNLOADS:-2}"
UV_CONCURRENT_BUILDS="${UV_CONCURRENT_BUILDS:-1}"
UV_CONCURRENT_INSTALLS="${UV_CONCURRENT_INSTALLS:-1}"
LANGFLOW_NO_CACHE="${LANGFLOW_NO_CACHE:-false}"
UV_CACHE_ARGS=()
if [[ "${LANGFLOW_NO_CACHE,,}" == "true" || "${LANGFLOW_NO_CACHE}" == "1" ]]; then
UV_CACHE_ARGS+=(--no-cache)
fi
msg_info "Pinning CPU Torch"
if ! $STD env \
UV_CONCURRENT_DOWNLOADS="${UV_CONCURRENT_DOWNLOADS}" \
UV_CONCURRENT_BUILDS="${UV_CONCURRENT_BUILDS}" \
UV_CONCURRENT_INSTALLS="${UV_CONCURRENT_INSTALLS}" \
uv pip install --python /opt/langflow/.venv/bin/python "${UV_CACHE_ARGS[@]}" \
--index-strategy unsafe-best-match \
--index-url https://download.pytorch.org/whl/cpu \
--extra-index-url https://pypi.org/simple \
"torch==2.8.0+cpu"; then
msg_error "Failed to install CPU torch"
exit 1
fi
msg_ok "Pinned CPU Torch"
msg_info "Updating Langflow (${TARGET_VERSION})"
if [[ "${TARGET_VERSION}" == "latest" ]]; then
if ! $STD env \
UV_CONCURRENT_DOWNLOADS="${UV_CONCURRENT_DOWNLOADS}" \
UV_CONCURRENT_BUILDS="${UV_CONCURRENT_BUILDS}" \
UV_CONCURRENT_INSTALLS="${UV_CONCURRENT_INSTALLS}" \
uv pip install --python /opt/langflow/.venv/bin/python "${UV_CACHE_ARGS[@]}" --upgrade langflow; then
msg_error "Langflow update failed"
if [[ -n "${OLD_VERSION}" ]]; then
msg_info "Rolling back to ${OLD_VERSION}"
$STD env \
UV_CONCURRENT_DOWNLOADS="${UV_CONCURRENT_DOWNLOADS}" \
UV_CONCURRENT_BUILDS="${UV_CONCURRENT_BUILDS}" \
UV_CONCURRENT_INSTALLS="${UV_CONCURRENT_INSTALLS}" \
uv pip install --python /opt/langflow/.venv/bin/python "${UV_CACHE_ARGS[@]}" "langflow==${OLD_VERSION}"
fi
if [[ -f "${BACKUP_DIR}/.env" ]]; then
cp -a "${BACKUP_DIR}/.env" /opt/langflow/.env
fi
if compgen -G "${BACKUP_DIR}/langflow.db*" >/dev/null; then
cp -a "${BACKUP_DIR}/langflow.db"* /opt/langflow/data/
fi
if ! systemctl start langflow; then
msg_error "Failed to start service after rollback"
fi
exit 1
fi
else
if ! $STD env \
UV_CONCURRENT_DOWNLOADS="${UV_CONCURRENT_DOWNLOADS}" \
UV_CONCURRENT_BUILDS="${UV_CONCURRENT_BUILDS}" \
UV_CONCURRENT_INSTALLS="${UV_CONCURRENT_INSTALLS}" \
uv pip install --python /opt/langflow/.venv/bin/python "${UV_CACHE_ARGS[@]}" "langflow==${TARGET_VERSION}"; then
msg_error "Langflow update to ${TARGET_VERSION} failed"
if [[ -n "${OLD_VERSION}" ]]; then
msg_info "Rolling back to ${OLD_VERSION}"
$STD env \
UV_CONCURRENT_DOWNLOADS="${UV_CONCURRENT_DOWNLOADS}" \
UV_CONCURRENT_BUILDS="${UV_CONCURRENT_BUILDS}" \
UV_CONCURRENT_INSTALLS="${UV_CONCURRENT_INSTALLS}" \
uv pip install --python /opt/langflow/.venv/bin/python "${UV_CACHE_ARGS[@]}" "langflow==${OLD_VERSION}"
fi
if [[ -f "${BACKUP_DIR}/.env" ]]; then
cp -a "${BACKUP_DIR}/.env" /opt/langflow/.env
fi
if compgen -G "${BACKUP_DIR}/langflow.db*" >/dev/null; then
cp -a "${BACKUP_DIR}/langflow.db"* /opt/langflow/data/
fi
if ! systemctl start langflow; then
msg_error "Failed to start service after rollback"
fi
exit 1
fi
fi
msg_ok "Updated Langflow"
msg_info "Starting Service"
systemctl start langflow
if [[ "$(systemctl is-active langflow)" != "active" ]]; then
msg_error "Service failed to start"
if [[ -n "${OLD_VERSION}" ]]; then
msg_info "Rolling back to ${OLD_VERSION}"
$STD env \
UV_CONCURRENT_DOWNLOADS="${UV_CONCURRENT_DOWNLOADS}" \
UV_CONCURRENT_BUILDS="${UV_CONCURRENT_BUILDS}" \
UV_CONCURRENT_INSTALLS="${UV_CONCURRENT_INSTALLS}" \
uv pip install --python /opt/langflow/.venv/bin/python "${UV_CACHE_ARGS[@]}" "langflow==${OLD_VERSION}"
if [[ -f "${BACKUP_DIR}/.env" ]]; then
cp -a "${BACKUP_DIR}/.env" /opt/langflow/.env
fi
if compgen -G "${BACKUP_DIR}/langflow.db*" >/dev/null; then
cp -a "${BACKUP_DIR}/langflow.db"* /opt/langflow/data/
fi
if ! systemctl restart langflow; then
msg_error "Failed to restart service after rollback"
fi
fi
exit 1
fi
msg_info "Running Health Check"
ensure_dependencies curl
if command -v curl >/dev/null 2>&1; then
for _ in {1..30}; do
if curl -fsS http://127.0.0.1:7860/ >/dev/null 2>&1; then
break
fi
sleep 2
done
if ! curl -fsS http://127.0.0.1:7860/ >/dev/null 2>&1; then
msg_error "Health check failed. Check logs: journalctl -u langflow -n 100"
exit 1
fi
else
msg_info "curl not available, skipping HTTP health check"
fi
msg_ok "Health check passed"
msg_info "If migration errors occur, review Langflow docs before using 'langflow migration --fix'"
msg_ok "Updated successfully!"
exit
}
start
build_container
description
msg_ok "Completed successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:7860${CL}"
echo -e "${INFO}${YW} Post-install credential location:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}/opt/langflow/.env${CL}"