管道apache2 customlog作为一个不同的用户运行的程序
我有一个程序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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在那里提供绝对路径,并避免前导空间,例如:
You need to provide the absolute path there and avoid leading spaces, like this: