如何以特定用户身份运行 Ruby 守护程序?
我正在尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该以
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.