Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 366811 - www-servers/lighttpd-1.4.35: does not start properly
Summary: www-servers/lighttpd-1.4.35: does not start properly
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Alex Alexander (RETIRED)
URL:
Whiteboard:
Keywords: InVCS, PATCH
Depends on:
Blocks:
 
Reported: 2011-05-11 01:45 UTC by Dustin
Modified: 2015-09-03 16:34 UTC (History)
3 users (show)

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


Attachments
conf.d/init.d fixes (lighttpd-start-stop.patch,1.14 KB, patch)
2011-05-12 17:31 UTC, Markos Chandras (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dustin 2011-05-11 01:45:46 UTC
Using /etc/init.d/lighttpd stop|restart does not kill the running lighttpd process.  Similar to bug 220161.

I noticed that the init script has --pidfile /var/run/lighttpd.pid and this file is never created.  Also, if server.pid-file is set in lighttpd.conf, the init script does not honor the setting.

This can be temporarily worked around by adding

server.pid-file = "/var/run/lighttpd.pid"

to lighttpd.conf so that lighttpd creates a pidfile that lines up with the init script's expectations.

Reproducible: Always

Steps to Reproduce:
1. emerge lighttpd
2. /etc/init.d/lighttpd start
3. /etc/init.d/lighttpd restart
Actual Results:  
* Stopping lighttpd ...             [ ok ]
* Starting lighttpd ...             [ !! ]
* ERROR: lighttpd failed to start

Expected Results:  
Started
Comment 1 Jeremy Olexa (darkside) (RETIRED) archtester gentoo-dev Security 2011-05-11 01:56:23 UTC
Interesting bug. It would be better to modify the init script. 

So, in /etc/conf.d/lighttpd, you would have something like:

LIGHTTPD_PID=$(/usr/bin/awk '/^server.pid-file/{s=$3}END{print s}' /etc/lighttpd/lighttpd.conf)

and in /etc/init.d/lighttpd you would respect that value.

Assigning to maintainers. Thanks for the report.
Comment 2 Dustin 2011-05-11 02:18:37 UTC
Thanks,

Altering /etc/conf.d/lighttpd did help with honoring lighttpd.conf, however this still doesn't terminate the process (see output)

# /etc/init.d/lighttpd stop --debug
 * Stopping lighttpd ...
+ start-stop-daemon --stop --quiet --pidfile '"/var/run/lighttpd/lighttpd.pid"'
+ eend 0                                                                                                                    [ ok ]
++ command -v stop_post
+ '[' '' = stop_post ']'
+ shift
+ continue 2
+ '[' -n '' ']'

# ps aux |grep lighttpd
root      2641  0.0  0.1  39628  1000 ?        S    19:04   0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

# cat /var/run/lighttpd/lighttpd.pid 
2641

Is this because of the single-quote double-quote surrounding the pidfile?
Comment 3 Markos Chandras (RETIRED) gentoo-dev 2011-05-12 16:44:28 UTC
I cannot reproduce this behavior. In my system, lighttpd starts/stops fine out of the box


btrfs-box1 dev # ls /var/run/|grep lighttpd.pid
btrfs-box1 dev # /etc/init.d/lighttpd start
 * Starting lighttpd ...                                                                                                                                                                                                                                                  [ ok ]
btrfs-box1 dev # ls /var/run/|grep lighttpd.pid
lighttpd.pid
btrfs-box1 dev # /etc/init.d/lighttpd stop 
 * Stopping lighttpd ...                                                                                                                                                                                                                                                  [ ok ]
btrfs-box1 dev # ls /var/run/|grep lighttpd.pid
btrfs-box1 dev # 


However, I agree that the init/conf.d script has to be modified to respect custom values in /etc/lighttpd/lighttpd.conf
Comment 4 Dustin 2011-05-12 16:54:09 UTC
If it makes a difference, here are my USE flags:

[ebuild   R   ] www-servers/lighttpd-1.4.28-r1  USE="bzip2 ipv6 pcre php rrdtool ssl -doc -fam -gdbm -ldap -libev -lua -memcache -minimal -mysql -test -webdav -xattr" 0 kB
Comment 5 Markos Chandras (RETIRED) gentoo-dev 2011-05-12 17:31:15 UTC
Created attachment 272963 [details, diff]
conf.d/init.d fixes

Can you please test the attached patch and let me know if it fixes your problem? Try setting an non-default pid value on /etc/lighttpd/lighttpd.conf as well
Comment 6 Dustin 2011-05-12 18:06:39 UTC
Perfect.

# grep "server.pid-file" /etc/lighttpd/lighttpd.conf 
server.pid-file = "/var/run/foobar/lighttpd.pid"

# cat /var/run/foobar/lighttpd.pid
cat: /var/run/foobar/lighttpd.pid: No such file or directory

# /etc/init.d/lighttpd start
 * Starting lighttpd ...         [ ok ]

# cat /var/run/foobar/lighttpd.pid 
19760

# ps aux |grep lighttpd
root     19760  0.0  0.2  35636  1092 ?        S    11:03   0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

# /etc/init.d/lighttpd stop
 * Stopping lighttpd ...         [ ok ]

# cat /var/run/foobar/lighttpd.pid
cat: /var/run/foobar/lighttpd.pid: No such file or directory

# ps aux |grep lighttpd
#

Thanks :)
Comment 7 Markos Chandras (RETIRED) gentoo-dev 2011-05-12 18:16:09 UTC
Fixed in 1.4.28-r2. Thanks for reporting
Comment 8 Patrice Clement gentoo-dev 2015-08-22 21:23:09 UTC
This is NOT a working solution.

Let's imagine I have this in my configuration file, which is perfectly fine as far as the lighttpd syntax goes:
var.state_dir   = "/var/lib/lighttpd"
server.pid-file = state_dir + "/lighttpd.pid"

Now the awk one liner returns this:
# /usr/bin/awk '/^server.pid-file/{s=$3};{sub("\"","",s)};END{print s}' /etc/lighttpd/lighttpd.conf
state_dir

and lighttpd is refusing to start because the string "start_dir" is passed to start-stop-daemon instead of the pid file path.

# /etc/init.d/lighttpd start
 * Starting lighttpd ...
 * start-stop-daemon: failed to start `/usr/sbin/lighttpd'                                                                  [ !! ]
 * ERROR: lighttpd failed to start

We shouldn't rely on such hacks to work out variables in conf.d files.

Please revert this patch or I will revert it myself.
Comment 9 William Hubbs gentoo-dev 2015-08-22 21:49:05 UTC
I was on the channel when this was being discussed, and I agree. 

If you keep the awk code at all, I think it should go in the service
script and not in the conf.d file.

Also, I recommend leveraging the default start and stop functions if
possible (see the openrc-run man page).
Comment 10 Patrice Clement gentoo-dev 2015-08-22 22:08:28 UTC
(In reply to William Hubbs from comment #9)
> If you keep the awk code at all, I think it should go in the service
> script and not in the conf.d file.

No. Even with awk, it is going to be hard to work out the actual variable name because the lighttpd grammar allow you to reuse previously defined tokens to create new tokens:
foo = "my_foo"
bar = foo + " is bar"

How do you parse that with a one-liner? You can't. This hack should go, full stop.
Comment 11 Markos Chandras (RETIRED) gentoo-dev 2015-08-30 08:44:40 UTC
(In reply to Patrice Clement from comment #8)
> This is NOT a working solution.

It's not an I will look at it.

> We shouldn't rely on such hacks to work out variables in conf.d files.

Ok but you have to calm down.

> 
> Please revert this patch or I will revert it myself.
That's not a proper way to seek help is it?
Comment 12 Markos Chandras (RETIRED) gentoo-dev 2015-08-30 09:18:40 UTC
There is also another bug. if you don't set 'server.pid-file' the server does not create a pid file and the init script goes crazy. Can you test the following solution on your environment please?

diff --git a/www-servers/lighttpd/files/lighttpd.confd b/www-servers/lighttpd/files/lighttpd.confd
index f3afb07..c7733de 100644
--- a/www-servers/lighttpd/files/lighttpd.confd
+++ b/www-servers/lighttpd/files/lighttpd.confd
@@ -6,7 +6,3 @@
 
 # Location of the lighttpd configuration file
 LIGHTTPD_CONF="/etc/lighttpd/lighttpd.conf"
-
-# Location of the lighttpd pid file
-LIGHTTPD_PID="$(/usr/bin/awk '/^server.pid-file/{s=$3};{sub("\"","",s)};END{print s}' ${LIGHTTPD_CONF})"
-
diff --git a/www-servers/lighttpd/files/lighttpd.initd b/www-servers/lighttpd/files/lighttpd.initd
index 23c0983..8abe3ba 100644
--- a/www-servers/lighttpd/files/lighttpd.initd
+++ b/www-servers/lighttpd/files/lighttpd.initd
@@ -5,6 +5,8 @@
 
 extra_started_commands="reload graceful"
 
+LIGHTTPD_PID="$($(which lighttpd) -pf ${LIGHTTPD_CONF} | grep pid | cut -d '=' -f 2 | tr -d \\\" | tr -d [:space:])"
+
 depend() {
        need net
        use mysql logger spawn-fcgi ldap slapd netmount dns
@@ -19,9 +21,10 @@ checkconfig() {
        fi
 
        if [ -z "${LIGHTTPD_PID}" ] ; then
-               ewarn "server.pid-file variable in ${LIGHTTPD_CONF}"
-               ewarn "is not set. Falling back to lighttpd.pid"
-               LIGHTTPD_PID="/run/lighttpd.pid"
+               eerror "server.pid-file variable in ${LIGHTTPD_CONF}"
+               eerror "is not set. Please set this variable properly"
+               eerror "and try again."
+               return 1
        fi
        /usr/sbin/lighttpd -t -f ${LIGHTTPD_CONF} >/dev/null
 }
Comment 13 Markos Chandras (RETIRED) gentoo-dev 2015-09-02 17:00:05 UTC
Fixed
Comment 14 Patrice Clement gentoo-dev 2015-09-02 20:48:36 UTC
(sorry for not commenting this bug before, I was a bit busy up until now)

-# Location of the lighttpd pid file
-LIGHTTPD_PID="$(/usr/bin/awk '/^server.pid-file/{s=$3};{sub("\"","",s)};END{print s}' ${LIGHTTPD_CONF})"

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

Hm. Right. So we went to an one-liner awk hack to more hacks piped together.

(In reply to Markos Chandras from comment #13)
> Fixed

Really?

To read the configuration file with lighttpd is a good idea so that variables get expended. I like that. However, to spawn 6 shells to do some parsing is not so good.

Here's how I would have solved it:

---

LIGHTTPD_BIN=$(type -P lighttpd)

while read -r line; do
        if [[ "$line" =~ ^server\.pid-file ]]; then
                # Break up $line content in positional args i.e. $1, $2, etc.
                set -- junk "$line"
                # Shift $junk.
                shift
                # Stuff the $* array into another array.
                pid_file=($*)
                break
        fi
done < <("$LIGHTTPD_BIN" -pf /etc/lighttpd/lighttpd.conf)

LIGHTTPD_PID="${pid_file[2]}"

---

That's it. No need for awk, grep, cut, tr, etc. Bash builtins are a lot more efficient.
Comment 15 Markos Chandras (RETIRED) gentoo-dev 2015-09-03 16:17:04 UTC
(In reply to Patrice Clement from comment #14)
> (sorry for not commenting this bug before, I was a bit busy up until now)
> 
> -# Location of the lighttpd pid file
> -LIGHTTPD_PID="$(/usr/bin/awk
> '/^server.pid-file/{s=$3};{sub("\"","",s)};END{print s}' ${LIGHTTPD_CONF})"
> 
> +LIGHTTPD_PID="$($(which lighttpd) -pf ${LIGHTTPD_CONF} | grep pid | cut -d
> '=' -f 2 | tr -d \\\" | tr -d [:space:])"
> 
> Hm. Right. So we went to an one-liner awk hack to more hacks piped together.
> 
> (In reply to Markos Chandras from comment #13)
> > Fixed
> 
> Really?
> 

Yes, really because I don't like your tone.
Comment 16 Patrice Clement gentoo-dev 2015-09-03 16:31:36 UTC
(In reply to Markos Chandras from comment #15)
> (In reply to Patrice Clement from comment #14)
> > Really?
> > 
> 
> Yes, really because I don't like your tone.

Sorry if I sounded rude, it wasn't my intention. I'm always connected on IRC and you can ping me to discuss, or better yet, you can send me an email. I apologised for not responding right away.

If you don't want to fix this bug properly then.. whatever. Just leave it.
Comment 17 Markos Chandras (RETIRED) gentoo-dev 2015-09-03 16:34:44 UTC
(In reply to Patrice Clement from comment #16)
> (In reply to Markos Chandras from comment #15)
> > (In reply to Patrice Clement from comment #14)
> > > Really?
> > > 
> > 
> > Yes, really because I don't like your tone.
> 
> Sorry if I sounded rude, it wasn't my intention. I'm always connected on IRC
> and you can ping me to discuss, or better yet, you can send me an email. I
> apologised for not responding right away.
> 
> If you don't want to fix this bug properly then.. whatever. Just leave it.

you seem to forget that bash built-ins are not allowed in init scripts. they are supposed to be shell independent.