Skip to content

Commit cb8c174

Browse files
xboardCopilot
andcommitted
fix(deploy): make install/update redis-independent and clean stale octane state
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dc8fbd1 commit cb8c174

4 files changed

Lines changed: 61 additions & 12 deletions

File tree

.docker/entrypoint.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,35 @@ export OCTANE_WORKERS OCTANE_TASK_WORKERS OCTANE_MAX_REQUESTS \
116116
echo "[entrypoint] Auto-tune (profile=${RESOURCE_PROFILE}): cpus=${CPUS} mem=${MEM_MIB}MiB slots=${SLOTS} -> octane=${OCTANE_WORKERS} horizon(dp/biz/notif)=${HORIZON_DATA_PIPELINE_MAX}/${HORIZON_BUSINESS_MAX}/${HORIZON_NOTIFICATION_MAX} horizon_worker_mem=${HORIZON_WORKER_MEMORY_MB}MB"
117117
echo "[entrypoint] Horizon supervisors use balance=auto with minProcesses=1, so they scale up to the cap on demand and back down when idle."
118118

119+
redis_reachable() {
120+
local host port
121+
host=$(grep -E '^REDIS_HOST=' /www/.env 2>/dev/null | tail -1 | cut -d= -f2- | tr -d '"' | tr -d "'")
122+
port=$(grep -E '^REDIS_PORT=' /www/.env 2>/dev/null | tail -1 | cut -d= -f2- | tr -d '"' | tr -d "'")
123+
command -v redis-cli >/dev/null 2>&1 || return 1
124+
[ -n "$host" ] || return 1
125+
case "$host" in
126+
/*) [ -S "$host" ] && redis-cli -s "$host" ping 2>/dev/null | grep -q PONG ;;
127+
*) redis-cli -h "$host" -p "${port:-6379}" ping 2>/dev/null | grep -q PONG ;;
128+
esac
129+
}
130+
119131
if [ ! -s /www/.env ] || ! grep -qE '^INSTALLED=(1|true)$' /www/.env || echo " $* " | grep -q ' xboard:install '; then
120132
echo "[entrypoint] Skipping xboard:update (not yet installed or running xboard:install)."
121133
else
122-
echo "[entrypoint] Running xboard:update..."
123-
php /www/artisan xboard:update --no-interaction || \
124-
echo "[entrypoint] WARNING: xboard:update failed; continuing so supervisor can boot anyway." >&2
134+
if redis_reachable; then
135+
echo "[entrypoint] Running xboard:update (redis reachable, real drivers)..."
136+
php /www/artisan xboard:update --no-interaction || \
137+
echo "[entrypoint] WARNING: xboard:update failed; continuing so supervisor can boot anyway." >&2
138+
else
139+
echo "[entrypoint] Running xboard:update (redis not yet up, using array/sync drivers)..."
140+
CACHE_DRIVER=array QUEUE_CONNECTION=sync SESSION_DRIVER=array \
141+
php /www/artisan xboard:update --no-interaction || \
142+
echo "[entrypoint] WARNING: xboard:update failed; continuing so supervisor can boot anyway." >&2
143+
fi
125144
fi
126145

127146
echo "[entrypoint] Starting services (caddy=${ENABLE_CADDY} web=${ENABLE_WEB} horizon=${ENABLE_HORIZON} ws=${ENABLE_WS_SERVER})..."
147+
# Drop stale Octane/WorkerMan state files so the new master does not signal
148+
# PIDs left over from a previous container run (causes Swoole kill EPERM).
149+
rm -f /www/storage/logs/octane-server-state.json /www/storage/logs/xboard-ws-server.pid 2>/dev/null || true
128150
exec "$@"

.docker/supervisor/supervisord.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ command=redis-server --dir /data
4747
--save 900 1
4848
--save 300 10
4949
--save 60 10000
50+
--bind 127.0.0.1
51+
--port 6379
5052
--unixsocket /data/redis.sock
5153
--unixsocketperm 777
5254
autostart=%(ENV_ENABLE_REDIS)s

app/Console/Commands/XboardInstall.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,17 @@ public function handle()
101101
$isReidsValid = false;
102102
while (!$isReidsValid) {
103103
// 判断是否为Docker环境
104-
if ($isDocker == 'true' && ($enableRedis || confirm(label: '是否启用Docker内置的Redis', default: true, yes: '启用', no: '不启用'))) {
104+
$useBuiltinRedis = $isDocker && ($enableRedis || confirm(label: '是否启用Docker内置的Redis', default: true, yes: '启用', no: '不启用'));
105+
if ($useBuiltinRedis) {
105106
$envConfig['REDIS_HOST'] = '/data/redis.sock';
106107
$envConfig['REDIS_PORT'] = 0;
107108
$envConfig['REDIS_PASSWORD'] = null;
108-
} else {
109-
$envConfig['REDIS_HOST'] = text(label: '请输入Redis地址', default: '127.0.0.1', required: true);
110-
$envConfig['REDIS_PORT'] = text(label: '请输入Redis端口', default: '6379', required: true);
111-
$envConfig['REDIS_PASSWORD'] = text(label: '请输入redis密码(默认: null)', default: '');
109+
$isReidsValid = true;
110+
break;
112111
}
112+
$envConfig['REDIS_HOST'] = text(label: '请输入Redis地址', default: '127.0.0.1', required: true);
113+
$envConfig['REDIS_PORT'] = text(label: '请输入Redis端口', default: '6379', required: true);
114+
$envConfig['REDIS_PASSWORD'] = text(label: '请输入redis密码(默认: null)', default: '');
113115
$redisConfig = [
114116
'client' => 'phpredis',
115117
'default' => [
@@ -148,6 +150,20 @@ public function handle()
148150
$password = Helper::guid(false);
149151
$this->saveToEnv($envConfig);
150152

153+
$installDriverOverrides = [
154+
'CACHE_DRIVER' => 'array',
155+
'QUEUE_CONNECTION' => 'sync',
156+
'SESSION_DRIVER' => 'array',
157+
];
158+
foreach ($installDriverOverrides as $key => $value) {
159+
putenv("{$key}={$value}");
160+
$_ENV[$key] = $value;
161+
$_SERVER[$key] = $value;
162+
}
163+
Config::set('cache.default', 'array');
164+
Config::set('queue.default', 'sync');
165+
Config::set('session.driver', 'array');
166+
151167
$this->call('config:cache');
152168
Artisan::call('cache:clear');
153169
$this->info('正在导入数据库请稍等...');
@@ -170,6 +186,11 @@ public function handle()
170186
$this->info("访问 http(s)://你的站点/{$defaultSecurePath} 进入管理面板,你可以在用户中心修改你的密码。");
171187
$envConfig['INSTALLED'] = true;
172188
$this->saveToEnv($envConfig);
189+
foreach (array_keys($installDriverOverrides) as $key) {
190+
putenv($key);
191+
unset($_ENV[$key], $_SERVER[$key]);
192+
}
193+
Artisan::call('config:clear');
173194
} catch (\Exception $e) {
174195
$this->error($e);
175196
}

app/Console/Commands/XboardUpdate.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ public function handle()
5151
$updateService->updateVersionCache();
5252
$themeService = app(ThemeService::class);
5353
$themeService->refreshCurrentTheme();
54-
try {
55-
Artisan::call('horizon:terminate');
56-
} catch (\Throwable $e) {
57-
$this->warn('horizon:terminate skipped: ' . $e->getMessage());
54+
if (config('queue.default') === 'sync') {
55+
$this->info('horizon:terminate skipped (sync queue, no workers to terminate).');
56+
} else {
57+
try {
58+
Artisan::call('horizon:terminate');
59+
} catch (\Throwable $e) {
60+
$this->warn('horizon:terminate skipped: ' . $e->getMessage());
61+
}
5862
}
5963
$this->info('更新完毕,队列服务已重启,你无需进行任何操作。');
6064
}

0 commit comments

Comments
 (0)