fix(update): run the database migration before starting the service (#6729)

update_x-ui() started x-ui.service and then called config_after_update right
away, which runs `x-ui setting -show true` and `x-ui migrate`. The service and
the CLI each run InitDB(), and with it every schema migration, on the same
database at the same time. On an upgrade that adds schema, the loser exits
with an error. Upgrading 3.8.5 to 3.9.0 stopped the service with
"duplicate column name: exclude_from_sub", and only Restart=on-failure
brought it back 5 s later.

Tolerating the duplicate-column error in the column helpers is not enough.
The same race also hits the tables new in 3.9.0: concurrent InitDB fails with
"table `node_pending_resets` already exists" and
"table `tuic_traffic_receipts` already exists". The cause is two processes
migrating at once, so the fix is to stop that from happening during update.

Run `x-ui migrate` to completion before the service is started, on both the
systemd and the OpenRC path. This mirrors install.sh, whose
config_after_install already migrates before the first start. The service and
the follow-up CLI calls then find the schema current, and their InitDB has
nothing to change.

Refs #6728
This commit is contained in:
Mr. Nickson
2026-10-05 17:48:50 +03:00
committed by GitHub
parent d7da64f2f0
commit a8d65a55b0
+5
View File
@@ -1171,6 +1171,11 @@ update_x-ui() {
chmod 640 ${xui_folder}/bin/config.json > /dev/null 2>&1
fi
# Finish the schema/data migrations before the service starts, so the service and
# config_after_update's CLI calls never run them on the same database at once (#6728).
echo -e "${green}Migrating database...${plain}"
"${xui_folder}/x-ui" migrate
if [[ $release == "alpine" ]]; then
echo -e "${green}Downloading and installing startup unit x-ui.rc...${plain}"
xui_rc_temp="/etc/init.d/x-ui.tmp.$$"