Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 626688 - www-servers/lighttpd: pid file parser in /etc/init.d/lighttpd buggy
Summary: www-servers/lighttpd: pid file parser in /etc/init.d/lighttpd buggy
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Herb Miller Jr.
URL: https://redmine.lighttpd.net/issues/3072
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2017-07-31 09:41 UTC by Markus Osterhoff
Modified: 2022-07-24 01:49 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Osterhoff 2017-07-31 09:41:07 UTC
/etc/init.d/lighttpd tries to parse the server.pid-file from /etc/lighttpd/lighttpd.conf using the line

LIGHTTPD_PID="$(grep pid ${LIGHTTPD_CONF} | cut -d '=' -f 2 | tr -d \\\" | tr -d [:space:])"

This results in two problems. First, the LIGHTTPD_PID is also configured in /etc/conf.d/lighttpd as
LIGHTTPD_PID="/var/run/lighttpd.pid"

Then, the parser for the /etc/lighttpd/lighttpd.conf fails if any other line contains "pid", as in this case:

        $HTTP["useragent"] =~ "spider" {
                accesslog.filename   = "/var/www/foo/logs/robots.log"
        }

spider contains pid, and so LIGHTTPD_PID is set to /var/run/lighttpd.pid~spider{

This filename is then written out to /run/openrc/daemons/lighttpd/001. Since lighttpd itself uses /etc/lighttpd/lighttpd.conf, the actual PID is written to lighttpd.pid; but then /etc/init.d/lighttpd status looks at /var/run/lighttpd.pid~spider{ and hence reports the wrong status "crashed".


(1) Is there a reason why the value from /etc/conf.d/lighttpd is overwritten? If not, the parser from /etc/init.d/lighttpd could be dropped.

If yes:
(2) This would be a saner option:
LIGHTTPD_PID="$(sed -n 's/^[^#]*server.pid-file[[:space:]]*=[[:space:]]*\"\([^"]*\)\"/\1/p' ${LIGHTTPD_CONF})"
Comment 1 Herb Miller Jr. 2021-03-06 16:06:59 UTC
There is some history to this bug. The origin of stepping on the /etc/conf.d value came from https://bugs.gentoo.org/366811, where there was some disagreement over the solution and it was included with the knowledge that it's fragile. I'm hesitant to adjust the problematic line because I'd prefer not to trigger another parsing strategy debate.

To add to your observation, this also fails if the pid is specified in lighttpd.conf but commented out. It looks to me like the underlying problem, lighttpd not writing out a pid file unless explicitly told to do so, is what needs addressed, then we can adjust the tooling around it. Upstream is responsive, and I'm happy to work with them on a solution. 

I'm thinking of two ways of approaching this:

- Could lighttpd just have a default if one isn't set? This would eliminate the need for LIGHTTPD_PID to appear in /etc/conf.d at all. I'm not sure if not writing one out is by design, so I'll ask upstream. (We'd still have to fix the parsing.)
- Could upstream add a way of specifying the pid as a switch when launching? That way we could use LIGHTTPD_PID in /etc/conf.d exclusively and ignore lighttpd.conf, though that might cause some confusion for users expecting lighttpd.conf to take precedence.

On a side note, but potentially relevant is https://bugs.gentoo.org/598468. At one time we were just asking lighttpd itself for the config and grabbing the pid from that, but that fell apart because of the order of things. It was getting called before the filesystem was switched to read/write. Maybe we could ask upstream for a way to ask lighttpd specifically for its pid?
Comment 2 Herb Miller Jr. 2021-03-10 14:07:20 UTC
Dear Gentoo devs, can we mark this one confirmed? Markus and I are both able to reproduce.

I opened https://redmine.lighttpd.net/issues/3072 with upstream to see if we can make changes that make this easier to solve without command line parsing.
Comment 3 gstrauss 2022-01-21 12:02:26 UTC
Shortly after https://bugs.gentoo.org/598468 (Oct/Nov 2016), lighttpd 1.4.44 was released in Dec 2016 and deferred the call to li_rand_init().  That change in lighttpd 1.4.44 should have addressed the issue raised in https://bugs.gentoo.org/598468.

Therefore, the change made in https://bugs.gentoo.org/598468 to remove
LIGHTTPD_PID="$($(which lighttpd) -pf ${LIGHTTPD_CONF} | grep pid | cut -d '=' -f 2 | tr -d \\\" | tr -d [:space:])"
can probably be restored.

However, if server.pid-file is not configured (or is commented out), then lighttpd.initd should take an alternate approach.  Some alternatives are suggested in https://redmine.lighttpd.net/issues/3072  The current behavior in https://github.com/gentoo/gentoo/blob/master/www-servers/lighttpd/files/lighttpd.initd is also fine: checkconfig() returns an error with trace that server.pid-file should be configured in lighttpd.conf
Comment 4 Larry the Git Cow gentoo-dev 2022-01-23 17:57:22 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=855a7edcadc8ee44e8bddebaf8b6b33b94d7190d

commit 855a7edcadc8ee44e8bddebaf8b6b33b94d7190d
Author:     Glenn Strauss <gstrauss@gluelogic.com>
AuthorDate: 2022-01-21 14:10:47 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-01-23 17:57:13 +0000

    www-servers/lighttpd: adjust lighttpd.initd
    
    Closes: https://bugs.gentoo.org/626688
    Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
    Closes: https://github.com/gentoo/gentoo/pull/23900
    Signed-off-by: Sam James <sam@gentoo.org>

 .../lighttpd/{lighttpd-1.4.64-r1.ebuild => lighttpd-1.4.64.ebuild}      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)