如何在脚本内更改 Glassfish 上的管理端口

发布于 2024-09-25 19:26:41 字数 1215 浏览 0 评论 0原文

这里遇到了一个奇怪的 Glassfish 问题。重现方法如下:

(1) 安装 Glassfish v3
(2) 启动您的默认域:

$GLASSFISH_HOME/bin/asadmin start-domain domain1

(3) 更改管理端口(您需要输入管理员 uid 和密码,在我们的脚本中我们使用 -u 和 -W 参数):

$GLASSFISH_HOME/bin/asadmin set configs.config.server-config.network-config.network-listeners.network-listener.admin-listener.port=34848

(4) 关闭域:

$GLASSFISH_HOME/bin/asadmin stop-domain domain1

你会发现这不起作用。您会得到:

CLI306 Warning - server is not running.
Command stop-domain executed successfully.

但是您的 Glassfish 进程仍在运行。更糟糕的是,当您尝试启动该过程时,您会收到一条警告,指出某些端口已在使用中。当然是,旧的流程仍然有它们!您唯一的出路是 killall -9 java

虽然某些配置更改是动态的,但似乎这个不是,但域停止假定它动态并使用新的端口来尝试执行命令。

可能的解决方案是:

(1) 在 domain.xml 上使用 sed - 不希望这样做,因为它很复杂通过 XML 代码进行危险的 grep 操作。我已经看到 Glassfish 更改了该文件中的属性顺序,因此我们不能仅使用 sed port="4848"
(2) 使用脚本安装程序而不是 zip 文件,并将参数作为应答文件提供给安装程序 - 这对于我们需要具有同理效力的安装脚本来说是有问题的。
(3) 使用已更改的domain.xml 的Glassfish 安装存档的自定义制作的zip - 这不是一个选项,因为我们设置的端口将来可能会更改。

这几乎是极端情况的定义,但我们需要解决。现在我们将使用 sed domain.xml,但很高兴知道是否有一种可以通过 CLI 实现的方法。

Got a weird Glassfish issue here. Here's how to reproduce it:

(1) Install Glassfish v3
(2) Start your default domain:

$GLASSFISH_HOME/bin/asadmin start-domain domain1

(3) Change the admin port (you'll need to enter admin uid & password, in our script we use the -u & -W parameters):

$GLASSFISH_HOME/bin/asadmin set configs.config.server-config.network-config.network-listeners.network-listener.admin-listener.port=34848

(4) Shut down the domain:

$GLASSFISH_HOME/bin/asadmin stop-domain domain1

You'll see this doesn't work. You get:

CLI306 Warning - server is not running.
Command stop-domain executed successfully.

But your Glassfish process is still running. Worse, when you attempt to start the process you'll get a warning that some of your ports are already in use. Of course they are, the old process has still got 'em! Your only way out is killall -9 java

While some of the config changes are dynamic it seems this one isn't but the domain stop assumes it is dynamic and uses the new port to try and execute the command.

Possible solutions are:

(1) Use sed on domain.xml - would prefer not to as it's complicated & risky grepping through XML code. I've seen Glassfish change the order of attributes in this file so we can't just sed for port="4848"
(2) Use the scripted installer rather than the zip file and feed the parameters to the setup program as an answer file - this is problematic for our install scripts which are required to be idem potent.
(3) Use a custom crafted zip of the Glassfish install archive with domain.xml already changed - not an option as the port we are setting may change in the future.

This is almost the definition of a corner case but one we need to solve. For now we're going to sed domain.xml but it would be nice to know if there was a way that's possible via the CLI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲性难收 2024-10-02 19:26:41

您可能想要执行以下操作...

  1. 通过解压缩安装 v3
  2. 删除domain1
  3. 使用您喜欢的端口创建一个新的domain1。
    手册页 所有详细信息
  4. create-domain 子命令 将包含启动此新域的

...无需额外启动或停止(如果您愿意记住说“asadmin start-domain mydomain”而不是,则可以跳过步骤 2 'asadmin 起始域'

You might want to do the following instead...

  1. install v3 by unzipping
  2. delete domain1
  3. create a new domain1 using the ports that you prefer.
    The man page for the create-domain subcommand will have all the details
  4. start this new domain...

No extra start or stop necessary (and you can skip step 2 if you are willing to remember to say 'asadmin start-domain mydomain' instead of 'asadmin start-domain'

○愚か者の日 2024-10-02 19:26:41

Sed 并没有我想象的那么糟糕,这就是我所做的:

cd $GLASSFISH_HOME
sed -i.bak '/<network-listener[^>]*name="admin-listener"/s/port="4848"/port="34848"/g' glassfish/domains/domain1/config/domain.xml

这仍然是一个错误,asadmin 认为端口更改是动态的,而实际上它不是,但我可以忍受这个黑客攻击。

Sed wasn't as bad as I thought it might be, here's what I did:

cd $GLASSFISH_HOME
sed -i.bak '/<network-listener[^>]*name="admin-listener"/s/port="4848"/port="34848"/g' glassfish/domains/domain1/config/domain.xml

It's still a bug that asadmin thinks the port change is dynamic when it isn't but I can live with this hack.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文