mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
fix: permission denied for sock files (#6092)
* fix: permission denied for sock files * fix: error
This commit is contained in:
parent
03df117637
commit
4de54a1167
@ -3,6 +3,8 @@ set -e
|
|||||||
|
|
||||||
echo "COMMIT_HASH: $(cat /app/commit_hash.txt)"
|
echo "COMMIT_HASH: $(cat /app/commit_hash.txt)"
|
||||||
|
|
||||||
|
export NOCOBASE_RUNNING_IN_DOCKER=true
|
||||||
|
|
||||||
if [ ! -d "/app/nocobase" ]; then
|
if [ ! -d "/app/nocobase" ]; then
|
||||||
mkdir nocobase
|
mkdir nocobase
|
||||||
fi
|
fi
|
||||||
|
@ -8,19 +8,30 @@
|
|||||||
*/
|
*/
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const { Command } = require('commander');
|
const { Command } = require('commander');
|
||||||
const { isDev, run, postCheck, downloadPro, promptForTs } = require('../util');
|
const { run, postCheck, downloadPro, promptForTs } = require('../util');
|
||||||
const { existsSync, rmSync } = require('fs');
|
const { existsSync, rmSync } = require('fs');
|
||||||
const { resolve } = require('path');
|
const { resolve, isAbsolute } = require('path');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const chokidar = require('chokidar');
|
const chokidar = require('chokidar');
|
||||||
|
|
||||||
|
function getSocketPath() {
|
||||||
|
const { SOCKET_PATH } = process.env;
|
||||||
|
|
||||||
|
if (isAbsolute(SOCKET_PATH)) {
|
||||||
|
return SOCKET_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolve(process.cwd(), SOCKET_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
function deleteSockFiles() {
|
function deleteSockFiles() {
|
||||||
const { SOCKET_PATH, PM2_HOME } = process.env;
|
const { PM2_HOME } = process.env;
|
||||||
if (existsSync(PM2_HOME)) {
|
if (existsSync(PM2_HOME)) {
|
||||||
rmSync(PM2_HOME, { recursive: true });
|
rmSync(PM2_HOME, { recursive: true });
|
||||||
}
|
}
|
||||||
if (existsSync(SOCKET_PATH)) {
|
const socketPath = getSocketPath();
|
||||||
rmSync(SOCKET_PATH);
|
if (existsSync(socketPath)) {
|
||||||
|
rmSync(socketPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,11 +11,12 @@ const net = require('net');
|
|||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const execa = require('execa');
|
const execa = require('execa');
|
||||||
const fg = require('fast-glob');
|
const fg = require('fast-glob');
|
||||||
const { dirname, join, resolve, sep } = require('path');
|
const { dirname, join, resolve, sep, isAbsolute } = require('path');
|
||||||
const { readFile, writeFile } = require('fs').promises;
|
const { readFile, writeFile } = require('fs').promises;
|
||||||
const { existsSync, mkdirSync, cpSync, writeFileSync } = require('fs');
|
const { existsSync, mkdirSync, cpSync, writeFileSync } = require('fs');
|
||||||
const dotenv = require('dotenv');
|
const dotenv = require('dotenv');
|
||||||
const fs = require('fs');
|
const fs = require('fs-extra');
|
||||||
|
const os = require('os');
|
||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
|
|
||||||
exports.isPackageValid = (pkg) => {
|
exports.isPackageValid = (pkg) => {
|
||||||
@ -325,6 +326,32 @@ function areTimeZonesEqual(timeZone1, timeZone2) {
|
|||||||
return moment.tz(timeZone1).format('Z') === moment.tz(timeZone2).format('Z');
|
return moment.tz(timeZone1).format('Z') === moment.tz(timeZone2).format('Z');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generateGatewayPath() {
|
||||||
|
if (process.env.SOCKET_PATH) {
|
||||||
|
if (isAbsolute(process.env.SOCKET_PATH)) {
|
||||||
|
return process.env.SOCKET_PATH;
|
||||||
|
}
|
||||||
|
return resolve(process.cwd(), process.env.SOCKET_PATH);
|
||||||
|
}
|
||||||
|
if (process.env.NOCOBASE_RUNNING_IN_DOCKER === 'true') {
|
||||||
|
return resolve(os.homedir(), '.nocobase', 'gateway.sock');
|
||||||
|
}
|
||||||
|
return resolve(process.cwd(), 'storage/gateway.sock');
|
||||||
|
}
|
||||||
|
|
||||||
|
function generatePm2Home() {
|
||||||
|
if (process.env.PM2_HOME) {
|
||||||
|
if (isAbsolute(process.env.PM2_HOME)) {
|
||||||
|
return process.env.PM2_HOME;
|
||||||
|
}
|
||||||
|
return resolve(process.cwd(), process.env.PM2_HOME);
|
||||||
|
}
|
||||||
|
if (process.env.NOCOBASE_RUNNING_IN_DOCKER === 'true') {
|
||||||
|
return resolve(os.homedir(), '.nocobase', 'pm2');
|
||||||
|
}
|
||||||
|
return resolve(process.cwd(), './storage/.pm2');
|
||||||
|
}
|
||||||
|
|
||||||
exports.initEnv = function initEnv() {
|
exports.initEnv = function initEnv() {
|
||||||
const env = {
|
const env = {
|
||||||
APP_ENV: 'development',
|
APP_ENV: 'development',
|
||||||
@ -343,9 +370,9 @@ exports.initEnv = function initEnv() {
|
|||||||
MFSU_AD: 'none',
|
MFSU_AD: 'none',
|
||||||
MAKO_AD: 'none',
|
MAKO_AD: 'none',
|
||||||
WS_PATH: '/ws',
|
WS_PATH: '/ws',
|
||||||
SOCKET_PATH: 'storage/gateway.sock',
|
// PM2_HOME: generatePm2Home(),
|
||||||
|
// SOCKET_PATH: generateGatewayPath(),
|
||||||
NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),
|
NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),
|
||||||
PM2_HOME: resolve(process.cwd(), './storage/.pm2'),
|
|
||||||
PLUGIN_PACKAGE_PREFIX: '@nocobase/plugin-,@nocobase/plugin-sample-,@nocobase/preset-',
|
PLUGIN_PACKAGE_PREFIX: '@nocobase/plugin-,@nocobase/plugin-sample-,@nocobase/preset-',
|
||||||
SERVER_TSCONFIG_PATH: './tsconfig.server.json',
|
SERVER_TSCONFIG_PATH: './tsconfig.server.json',
|
||||||
PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), 'storage/playwright/.auth/admin.json'),
|
PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), 'storage/playwright/.auth/admin.json'),
|
||||||
@ -428,6 +455,11 @@ exports.initEnv = function initEnv() {
|
|||||||
`process.env.DB_TIMEZONE="${process.env.DB_TIMEZONE}" and process.env.TZ="${process.env.TZ}" are different`,
|
`process.env.DB_TIMEZONE="${process.env.DB_TIMEZONE}" and process.env.TZ="${process.env.TZ}" are different`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.env.PM2_HOME = generatePm2Home();
|
||||||
|
process.env.SOCKET_PATH = generateGatewayPath();
|
||||||
|
fs.mkdirpSync(dirname(process.env.SOCKET_PATH), { force: true, recursive: true });
|
||||||
|
fs.mkdirpSync(process.env.PM2_HOME, { force: true, recursive: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generatePlugins = function () {
|
exports.generatePlugins = function () {
|
||||||
|
@ -18,7 +18,7 @@ import fs from 'fs';
|
|||||||
import http, { IncomingMessage, ServerResponse } from 'http';
|
import http, { IncomingMessage, ServerResponse } from 'http';
|
||||||
import compose from 'koa-compose';
|
import compose from 'koa-compose';
|
||||||
import { promisify } from 'node:util';
|
import { promisify } from 'node:util';
|
||||||
import { resolve } from 'path';
|
import { isAbsolute, resolve } from 'path';
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import handler from 'serve-handler';
|
import handler from 'serve-handler';
|
||||||
import { parse } from 'url';
|
import { parse } from 'url';
|
||||||
@ -55,6 +55,16 @@ export interface AppSelectorMiddlewareContext {
|
|||||||
resolvedAppName: string | null;
|
resolvedAppName: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSocketPath() {
|
||||||
|
const { SOCKET_PATH } = process.env;
|
||||||
|
|
||||||
|
if (isAbsolute(SOCKET_PATH)) {
|
||||||
|
return SOCKET_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolve(process.cwd(), SOCKET_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
export class Gateway extends EventEmitter {
|
export class Gateway extends EventEmitter {
|
||||||
private static instance: Gateway;
|
private static instance: Gateway;
|
||||||
/**
|
/**
|
||||||
@ -73,9 +83,7 @@ export class Gateway extends EventEmitter {
|
|||||||
private constructor() {
|
private constructor() {
|
||||||
super();
|
super();
|
||||||
this.reset();
|
this.reset();
|
||||||
if (process.env.SOCKET_PATH) {
|
this.socketPath = getSocketPath();
|
||||||
this.socketPath = resolve(process.cwd(), process.env.SOCKET_PATH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getInstance(options: any = {}): Gateway {
|
public static getInstance(options: any = {}): Gateway {
|
||||||
@ -87,7 +95,7 @@ export class Gateway extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getIPCSocketClient() {
|
static async getIPCSocketClient() {
|
||||||
const socketPath = resolve(process.cwd(), process.env.SOCKET_PATH || 'storage/gateway.sock');
|
const socketPath = getSocketPath();
|
||||||
try {
|
try {
|
||||||
return await IPCSocketClient.getConnection(socketPath);
|
return await IPCSocketClient.getConnection(socketPath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user