管道apache2 customlog作为一个不同的用户运行的程序

发布于 2025-02-09 17:16:31 字数 954 浏览 3 评论 0原文

我有一个程序A2LOG2PG,该程序使用Apache2 CustomLog并将其写入数据库。

在apache2.conf中,我有一个定义CustomLog并将其输送到A2LOG2PG的行。

CustomLog "|/usr/bin/a2log2pg" combined

合并的位置是Apache日志格式之一。

尽管一切都很好,但此技术会导致A2LOG2PG作为root运行。我宁愿将其作为无私人用户,特别是称为A2Logger的用户运行。

为此,我一直在尝试使用这一行:

CustomLog "| sudo -u a2logger /usr/bin/a2log2pg" combined

但是Apache然后拒绝启动。 Apache日志中的错误是:

No such file or directory: AH00104: unable to start piped log program ' sudo -u a2logger /usr/bin/a2log2pg'

还有其他一些语法可以允许它起作用吗?

将Apache放在一边,如果我尝试类似的东西,但是只需使用shell脚本,它就可以使用:

$ cat 1234.txt
one
two
three
four
$ cat countlines.sh
#!/bin/bash
counter=0
while read line
do
  ((++counter))
done<&0
echo $USER counted $counter lines

然后登录为root

# cat 1234.txt | sudo -u a2logger ./countlines.sh
a2logger counted 4 lines

I have a program a2log2pg that takes an apache2 CustomLog and writes it to a database.

In apache2.conf, I have a line that defines a CustomLog and pipes it to a2log2pg.

CustomLog "|/usr/bin/a2log2pg" combined

where combined is one of the apache log formats.

Although it all works fine, this technique results in a2log2pg running as root. I'd rather run it as an unprivileged user, specifically a user called a2logger.

To that end, I've been attempting to use this line:

CustomLog "| sudo -u a2logger /usr/bin/a2log2pg" combined

but apache then refuses to start. The error in the apache log is:

No such file or directory: AH00104: unable to start piped log program ' sudo -u a2logger /usr/bin/a2log2pg'

Is there some other syntax that would allow this to work?

Leaving apache aside for a moment, if I try something similar, but just using shell scripts, it works:

$ cat 1234.txt
one
two
three
four
$ cat countlines.sh
#!/bin/bash
counter=0
while read line
do
  ((++counter))
done<&0
echo $USER counted $counter lines

and then, logged in as root

# cat 1234.txt | sudo -u a2logger ./countlines.sh
a2logger counted 4 lines

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

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

发布评论

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

评论(1

一抹淡然 2025-02-16 17:16:31

您需要在那里提供绝对路径,并避免前导空间,例如:

CustomLog "|/usr/bin/sudo -u a2logger /usr/bin/a2log2pg" combined

You need to provide the absolute path there and avoid leading spaces, like this:

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