如何以特定用户身份运行 Ruby 守护程序?

发布于 2024-11-03 10:54:49 字数 461 浏览 3 评论 0原文

我正在尝试使用 daemons gem 运行 Ruby 守护程序。

它将以用户“joe”启动,但一旦被妖魔化,就需要更改为“www-data”,以便它可以访问将要处理的文件。

我可以看到守护进程有 Application 类的 change_privilege 方法,但我不知道如何在这段代码中使用它:

require 'daemons'
Daemons.run(
  File.join(File.dirname(__FILE__), 'worker.rb'),
  {
    :backtrace  => true,
    :log_output => true,
    :dir_mode   => :script,
    :log_dir    => '/tmp',
    :monitor    => true
  }
)

I am trying to run a Ruby daemon using the daemons gem.

It will be started as user 'joe' but needs to change to 'www-data' once it's demonized so that it can access the files it will be working on.

I can see that daemons has change_privilege method for the Application class, but I can't figure out how to use it around this code:

require 'daemons'
Daemons.run(
  File.join(File.dirname(__FILE__), 'worker.rb'),
  {
    :backtrace  => true,
    :log_output => true,
    :dir_mode   => :script,
    :log_dir    => '/tmp',
    :monitor    => true
  }
)

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

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

发布评论

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

评论(1

倾听心声的旋律 2024-11-10 10:54:49

您不应该以 www-data 身份运行,因为这是 apache 的特定用户。但是,您应该将“joe”添加到可以访问此类文件的 www 用户组。

You should not be running as www-data as this is a specific user to apache. You should however add "joe" to your www user group that can access such files.

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