将自定义信息传递给 mongrel_rails start

发布于 2024-08-28 13:22:18 字数 1198 浏览 10 评论 0原文

我真正不明白的一件事是如何将自定义启动选项传递给混合实例。

我发现一种常见的方法是使用环境变量,但在我的环境中这是行不通的,因为我的 Rails 应用程序为许多不同的客户端提供服务。许多代码在客户端之间共享,但也存在许多差异,我通过子类化控制器和视图来重载或扩展现有功能或引入新功能来实现。为了使这一切正常工作,我只需将客户端特定模块的路径添加到模块加载路径($:)。

为了为特定客户端启动应用程序,我现在可以使用环境变量,例如 TARGET=AMAZONE。不幸的是,在某些系统上我运行多个混合集群,每个集群服务于不同的客户端。其中一些系统在 Windows 下运行,为了启动 mongrel,我安装了 mongrel_services。显然,这使得我的环境变量不合适。

事实证明,将这些额外的数据传递给应用程序是一个真正的挑战。首先, mongrel_rails service_install 将拒绝任何未记录的[自定义]命令行参数。我不太担心,因为使用安装程序安装服务很简单。

但是,即使我设法安装 mongrel_services,以便在运行时将自定义命令行选项 --target 传递给 mongrel_rails start,我也会收到错误,因为 mongrel_rails 无法识别该开关。

以下是我查看的内容:

  1. 传递额外参数:

    mongrel_rails start --target XYZ ...

  2. 使用配置文件并添加 target:XYZ,然后执行:

    mongrel_rails start -C x:\myapp\myconfig.yml

  3. 修改文件:

    Ruby\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mswin32-60\lib\mongrel\command.rb

  4. 也许我可以使用 --script 选项,但我在其上找到的所有文档都是针对 Unix 的

1 和 2,根本不起作用。我玩过 4 个,但从来没有让它做任何事情。所以我别无选择,只能选择3。虽然它相对简单,但我讨厌更改ruby库代码。

特别令人失望的是2不起作用。我的意思是在配置文件中添加其他[自定义]选项有什么不合理的?实际上我认为这是 Rails 中缺少的一个基本部分。无论如何,应用程序应该能够注册和访问它期望的命令行参数。

如果有人知道如何使用当前的基础设施更优雅地做到这一点,我有一条巧克力鱼可以赠送!

One thing I really don't understand is how I can pass custom start-up options to a mongrel instance.

I see that a common approach is the use environment variables, but in my environment this is not going to work because my rails application serves many different clients. Much code is shared between clients, but there are also many differences which I implement by subclassing controllers and views to overload or extend existing features or introduce new ones. To make this all work, I simply add the paths to client specific modules the module load path ($:).

In order to start the application for a particular client, I could now use an environment variable like say, TARGET=AMAZONE. Unfortunately, on some systems I'm running multiple mongrel clusters, each cluster serving a different client. Some of these systems run under Windows and to start mongrel I installed mongrel_services. Clearly, this makes my environment variable unsuitable.

Passing this extra bit of data to the application is proving to be a real challenge. For a start, mongrel_rails service_install will reject any [custom] command line parameters that aren't documented. I'm not too concerned as installing the services using the install program is trivial.

However, even if I manage to install mongrel_services such that when run it passes the custom command line option --target to mongrel_rails start, I get an error because mongrel_rails doesn't recognize the switch.

So here were the things I looked at:

  1. Pass an extra parameter:

    mongrel_rails start --target XYZ ...

  2. use a config file and add target:XYZ, then do:

    mongrel_rails start -C x:\myapp\myconfig.yml

  3. modify the file:

    Ruby\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mswin32-60\lib\mongrel\command.rb

  4. Perhaps I can use the --script option, but all docs that I found on it were for Unix

1 and 2 simply don't work. I played with 4 but never managed it to do anything. So I had no choice but to go with 3. While it is relatively simple, I hate changing ruby library code.

Particularly disappointing is that 2 doesn't work. I mean what is so unreasonable about adding other [custom] options in the config file? Actually I think this is a fundamental piece that is missing in rails. Somehow, the application should be able to register and access command line arguments it expects.

If anybody has a good idea how to do this more elegantly using the current infrastructure, I have a chocolate fish to give away!!!

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

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

发布评论

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

评论(1

橙味迷妹 2024-09-04 13:22:18

可能没有必要向 mongrel 传递一些东西。或许可以使用现有的机制来提供您所寻求的灵活性。让我们首先尝试清楚地了解这些限制。

换言之,似乎以下条件有效。

  • 使用相同的代码库(或非常相似的代码库)为多个客户提供服务
  • 在应用程序启动时(或执行之前)需要影响应用程序执行的标识符来定义应用程序行为
  • 可以在单个系统上使用多组混合集群,每个集群专用于单个客户端的集群
    • 这意味着进程集群都使用相同的配置值服务于相同的代码库
  • 一些客户希望在 Windows 服务器上运行,从而避免使用某些 Unix 风格的环境和脚本行为。

应该验证的一个假设是每个代码库都位于单独的目录中。如果是这样,那么可能有一个非常简单的解决方案。

如果每个客户都在自己的目录中,如下所示:

/src
  /customer1
  /customer2
  /customer3

如果您使用以下内容启动混合进程:

[/src/customer1]$ mongrel_rails cluster::start

那么,您可以拥有一个在系统启动时读取的 customer_config.yml 文件(在您的环境中) .rb),您可以在其中放置您的客户端自定义值。因此,如果您需要传入“Amazone”作为目标值,那么您的 yaml 文件可能如下所示:

target:
  Amazone

然后,每个客户都会获得自己的 customer_config.yml 文件,该文件仅驻留在他们的目录中,并且您只有一个文件可以使用更改添加新客户时切换行为。

修改您的environment.rb以查找专门命名的YAML文件是完全可以接受的。解析 YAML 文件相当容易,并且为管理每个客户的定制提供了很大的灵活性。

It may not be necessary to pass in something to mongrel. It may be possible to use an existing mechanism that will provide the flexibility you seek. Let's start by trying to be very clear about the constraints.

To paraphrase, it seems that the following conditions are in effect.

  • The same code base (or very similar code base) is used to serve multiple customers
  • Identifiers that influence application execution are needed at application startup (or before execution) to define application behavior
  • Multiple sets of mongrel clusters can be used on a single system with each cluster dedicated to a single client
    • This implies that a cluster of processes are all serving the same code base with the same configuration value(s)
  • Some customers wish to run on Windows servers, which obviates the use of some Unix style environment and scripting behavior.

One assumption that should be validated is that each code base is in a separate directory. If so, then there may be a very straightforward solution.

If each customer is in its own directory, like so:

/src
  /customer1
  /customer2
  /customer3

And if you start your mongrel processes with something like:

[/src/customer1]$ mongrel_rails cluster::start

Then, you could have a customer_config.yml file that is read at system startup (in your environment.rb) in which you can place your client customization value. So, if you need to pass in "Amazone" as the target value, then your yaml file might look like:

target:
  Amazone

Then, each customer gets their own customer_config.yml file, which resides only in their directory, and you have only one file to change to switch behaviors when adding a new customer.

Modifying your environment.rb to look for a specifically named YAML file would be perfectly acceptable. It's rather easy to parse a YAML file, and it gives a lot of flexibility for managing customization by each customer.

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