在没有管理员密码的情况下,Wicket 应用程序是否可以触发自身重新启动?

发布于 2024-08-13 17:42:59 字数 868 浏览 3 评论 0原文

我是 Wicket 的新手,希望使用某种维护管理页面来从内部维护一个 Web 应用程序来运行清理、数据库更新、恢复等。由于我计划使用 Hibernate 或类似的数据绑定,我想从内部触发应用程序的完全重新启动,而不向每个能够运行这些操作的人提供随附的 Tomcat 管理器密码。

据我发现,似乎没有一种简单的方法可以在没有管理员密码的情况下触发 Java Web 应用程序的真正重新启动?然而,由于许多 Java Web 应用程序在其管理面板中具有此类重新启动功能,因此我认为应该可以在特定的 Servlet 容器或某些 Web 框架中触发重新启动。他们必须以某种方式做到这一点? (或者也许它们并没有真正从头开始重新启动,而只是在没有干净重启的情况下重新初始化?)

我找不到任何有关 Wicket 或 Tomcat 能够通过关闭并从其应用程序重新启动来触发的信息,尽管 Wicket 中有一些内部方法那也许可以做到这一点? (可以公开访问,但 JavaDoc 建议不要这样做,因为它们仅供内部使用)

从安全角度来看,我真的不明白为什么应用程序不应该能够从自己的代码请求此类重新启动。

可以这样做吗?如果可以,我需要在我的应用程序中做什么才能重新启动它?

编辑:只是为了让我的问题更精确:用户和应用程序都不应该有任何可用于访问 Tomcat 管理器界面的密码。我正在考虑调用一些方法或设置一些标志来触发 servlet 容器来重新启动该特定应用程序,而无需授权这样做。我的想法是,由于应用程序在 servlet 容器中运行,因此应该有某种方式关闭和重新启动。如果这对于 Java 应用程序服务器来说通常是不可能的,则可能有某种方法可以在应用程序级别上完成此操作,方法是调用底层框架(本例中为 Wicket)来结束所有正在运行的线程,尽可能清理并重新启动使用该框架的应用程序;类似于应用程序堆栈的“软重启”。

I'm new to Wicket and would like to maintain a web application from inside itself using some sort of maintenance admin page for running clean-up, DB updates, recovery and so on. Since I plan to use Hibernate or similar for data binding I would like to trigger a complete reboot of the application from inside itself without giving everybody who will be able to run these actions the accompanying Tomcat manager password.

As far as I found out, there does not seem to be an easy way to trigger a real restart of a Java web application without the manager password? However, since there are many Java webapps having such restart functionality in their admin panels, I assume it should be possible to trigger a restart in either specific servlet containers or some web frameworks. They somehow have to do the trick? (or maybe they don't really restart from scratch but just reinitialize without a clean restart?)

I could not find anything about Wicket or Tomcat being able to be triggered with a shutdown and restart from their applications although there are some internal methods in Wicket that might be able to do that? (can be accessed publically but JavaDoc advises against it since they are only for internal use)

From a security point of view I don't really see why an application should not be able to request such a restart from its own code.

Can this be done and if yes, what will I have to do in my application to have it restarted?

Edit: Just to make my question more precise: Neither the user nor the app should have any password that could be used to access the Tomcat manager interface. I was thinking of some method to call or some flag to set to have the servlet container be triggered to restart that particular application without the need of authorization to do so. My thoughts are that since the application is running in a servlet container it should have some way to shutdown and be restarted. If that's not possible in general with Java app servers, there may be some way to do it on application level by doing a call to the underlaying framework (Wicket in this case) to end all running threads, clean up as much as possible and restart the application using the framework; something like a "soft reboot" of the app stack.

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

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

发布评论

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

评论(3

紙鸢 2024-08-20 17:42:59

您的应用程序正在使用 Wicket,这与您的问题几乎无关。它是一个使用 Wicket 框架的 Java Web 应用程序。用这样的措辞,您正在寻找如何使用 Tomcat 容器重新启动 Web 应用程序。如果您选择另一个 Web 应用程序容器(码头等),那么您将需要更改过程。

您可以点击此 URL 来启动应用程序:http://localhost:8080/manager/start?path=/myapphttp://localhost:8080/manager/stop?path =/myapp 来停止您的应用程序。将 /myapp 更改为您的应用程序上下文,您就可以控制启动/停止。

然后,您可以在代码内部处理密码问题。

根据您的说明,您可以查看 此 tomcat 文档 并使用JMX。然而,即使是 JMX 也受密码保护。从 Web 应用程序获取容器控件没有标准。

It's mostly irrelevant to your question that your app is using Wicket. It's a java web application using the Wicket framework. Worded like this, your looking for how to restart a web app, using the Tomcat container. If you choose another web application container (jetty etc) then you would need to change the procedure.

You can hit this URL to start an app: http://localhost:8080/manager/start?path=/myapp and http://localhost:8080/manager/stop?path=/myapp to stop your app. Change /myapp to your applications context, and you have start/stop control.

You can then deal with password issues internally in your code.

In light of your clarification you might look at this tomcat documentation and use JMX. However, even JMX is password protected. There is no standard for getting at the container controls from your web app.

_蜘蛛 2024-08-20 17:42:59

我正在尝试思考其他网络框架是否/什么真正支持这一点。我认为吉姆正在指出解决方案的正确水平。无论使用什么框架,Web 容器都应该允许重新启动所包含的 Web 应用程序。 Tomcat 需要管理器应用程序可用。看来(根据我的谷歌搜索)Jetty 通过 JMX MBean 公开了此功能。因此重启功能可能无法在容器之间移植。

为了使其在任何框架中都可移植,我认为您必须隔离重新启动所需的内容。如果是休眠状态,则重新初始化会话工厂。如果是 spring 配置,这肯定会更具侵入性,但替换或重新配置 bean 似乎是可行的方法。如果是 i18n 或标记资源检票口,我相信已经可以提供帮助了。

I'm trying to think if/what other web frameworks really support this. I think Jim is on to pointing to the right level of the solution. Regardless of what framework being used a web container should allow for the restart of a contained web app. Tomcat would require the manager application to be available. It appears that (from my googling) that Jetty exposes this functionality through JMX MBeans. So the restart functionality may not be portable between containers.

To make this portable, in any framework, I think you'd have to isolate what things are needed to restart. If it's hibernate re-initialize the session factory. If it's spring configuration, this may certainly be more intrusive, but replacing or reconfiguring beans seems the way to go. If it's i18n or markup resources wicket I believes can help with that already.

以歌曲疗慰 2024-08-20 17:42:59

我还鼓励您看看 JMX。您可以关闭 JMX 身份验证,在这种情况下,请确保无法从 Internet 访问 JMX 端口(过滤基于主机的防火墙上的端口,或仅将其绑定到本地 IP 地址)。 JMX 旨在标准化 Java EE 世界中应用程序、容器的远程监视和控制,因此它或多或少提供了您正在寻找的基础设施。

或者使用另一个 Web 容器(最好是嵌入式容器)并处理甚至从 Java 代码重新启动的容器。

I also encourage you to take a look at JMX. You can turn off authentication for JMX in which case make sure the JMX port is not reachable from the internet (filter the port on your host based firewall, or bind it only to a local ip address). JMX was intended to standardize remote monitoring and control of applications, containers in a Java EE world, so it more or less provides the infrastructure you're looking for.

Or alternatively use another web container (preferably an embedded one) and handle even container restarts from your java code.

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