我目前正在使用网络管理面板系统来管理特定游戏和模组的游戏服务器。我希望在面板中实现一项功能,该功能允许您通过单击启动和停止按钮来分别启动和停止服务器。
为了能够标记服务器进程及其子进程,以便以后可以再次找到它们以杀死它们,我正在使用Linux屏幕并对其进行标记。我正在使用nodejs的spawn命令启动屏幕。如此处所示:
console.log(`screen -m -d -S serverscreen${server.id} wine ${(args.disableWSE === true) ? 'mb_warband_dedicated.exe' : 'WSELoaderServer.exe'} -r "Configs/${args.config}" -m "${args.module}"`);
const program = spawn(
'screen',
[
'-m', '-d',
'-S', `serverscreen${server.id}`,
'wine',
(args.disableWSE === true) ? 'mb_warband_dedicated.exe' : 'WSELoaderServer.exe',
'-r', `Configs/${args.config}`,
'-m', `${args.module}`
],
{
cwd: currentGameserverPath,
detached: true,
stdio: 'ignore'
}
);
但是,我面临的一个问题是,我在解决问题上已经用尽了全部知识。当在spawn中使用该命令时不起作用,即我可以将console.log
中显示的命令运行到cwd
目录中,但是当将spawn命令称为屏幕时,游戏服务器会很高兴地启动。无法启动。我已经记录了stderr和stdout,它们都是空的,并且生成的退出是0
。
有什么建议吗?
有关更多信息,以下是封装此代码段的其余功能:
export default async (parent, args, context) => {
/* Check for Permissions */
if (context.user === null)
throw new Error('You must be logged in to complete this action.');
const requestingAdmin = await AdminPermission.findOne({
server: args.serverID,
admin: context.user
});
if (requestingAdmin === null)
throw new Error('You do not have permission to do that.');
const server = await Server.findOne({
id: args.serverID
});
if(server === null) throw new Error('Server not found.');
const currentGameserverPath = path.join(
require.resolve('gameservers'),
`../${server.id}`
);
if (!fs.existsSync(currentGameserverPath))
throw new Error('Server folder does not exist!');
const executablePath = path.join(
currentGameserverPath,
(args.disableWSE === true) ? '/mb_warband_dedicated.exe' : '/WSELoaderServer.exe'
);
if (!fs.existsSync(executablePath)) throw new Error('Executable does not exist!');
const moduleFolder = path.join(currentGameserverPath, `/Modules/${args.module}`);
if (!fs.existsSync(moduleFolder)) throw new Error('Module does not exist!');
let configFile = path.join(currentGameserverPath, `/Configs/${args.config}`);
if (!fs.existsSync(configFile)) throw new Error('Config does not exist!');
console.log(`screen -m -d -S serverscreen${server.id} wine ${(args.disableWSE === true) ? 'mb_warband_dedicated.exe' : 'WSELoaderServer.exe'} -r "Configs/${args.config}" -m "${args.module}"`);
const program = spawn(
'screen',
[
'-m', '-d',
'-S', `serverscreen${server.id}`,
'wine',
(args.disableWSE === true) ? 'mb_warband_dedicated.exe' : 'WSELoaderServer.exe',
'-r', `Configs/${args.config}`,
'-m', `${args.module}`
],
{
cwd: currentGameserverPath,
detached: true,
stdio: 'ignore'
}
);
program.unref();
server.gameserverLastModule = args.module;
server.gameserverLastConfig = args.config;
await server.save();
return server;
}
答案 0 :(得分:0)
我在浏览SO时找到了新线索:
-L
will create a log file. wine: /home/tsm/.wine is not owned by you
。sudo chown -R root: ~/.wine
。这是因为我以root身份运行Web服务器以获取端口80权限,因此它以root身份启动wine,因此root必须拥有.wine
文件夹。