You are not logged in.

#1 2012-08-06 15:12:20

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 776

systemd socket activation - mpd, lighttpd etc.

Last week I switched to systemd and I'm trying to get socket activation working. Unfortunately, I've found only this:

Currently we do not have guidance on how to write socket files as this is something that needs upstream code and they can add a proper .socket file at the same time.

Socket activation for this services is included in the packages: cups, sshd, saned. All I had to do was

systemctl enable service-name.socket

instead of

systemctl enable service-name.service

After reading the man pages (systemd.service(5) and systemd.socket(5)) I was able to write .socket files for mpd and lighttpd. It's working for mpd, but not for lighttpd, (can't bind to port, see below).
Content of lighttpd.socket (mpd.socket looks pretty much the same):

[Unit]
Description=lighttpd socket

[Socket]
ListenStream=80
ListenStream=443
Service=lighttpd.service

[Install]
WantedBy=sockets.target

and for completeness the content of official lighttpd.service:

[Unit]
Description=A secure, fast, compliant and very flexible web-server
After=syslog.target network.target

[Service]
PrivateTmp=true
ExecStart=/usr/sbin/lighttpd-angel -D -f /etc/lighttpd/lighttpd.conf
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

Using `ss -a` command I've confirmed that systemd is listening on ports 80 and 443, but when I try to access localhost on these ports, the lighttpd service isn't started. In journalctl I get this:

Aug 06 16:30:41 asusntb lighttpd-angel[31265]: 2012-08-06 16:30:41: (network.c.379) can't bind to port:  80 Address already in use
Aug 06 16:30:41 asusntb lighttpd-angel[31265]: lighttpd-angel.c.140: child (pid=31271) exited normally with exitcode: 255
Aug 06 16:30:42 asusntb lighttpd-angel[31274]: 2012-08-06 16:30:42: (network.c.379) can't bind to port:  80 Address already in use
Aug 06 16:30:42 asusntb lighttpd-angel[31274]: lighttpd-angel.c.140: child (pid=31275) exited normally with exitcode: 255
Aug 06 16:30:42 asusntb lighttpd-angel[31277]: 2012-08-06 16:30:42: (network.c.379) can't bind to port:  80 Address already in use
Aug 06 16:30:42 asusntb lighttpd-angel[31277]: lighttpd-angel.c.140: child (pid=31278) exited normally with exitcode: 255
Aug 06 16:30:42 asusntb lighttpd-angel[31280]: 2012-08-06 16:30:42: (network.c.379) can't bind to port:  80 Address already in use
Aug 06 16:30:42 asusntb lighttpd-angel[31280]: lighttpd-angel.c.140: child (pid=31281) exited normally with exitcode: 255
Aug 06 16:30:42 asusntb lighttpd-angel[31283]: 2012-08-06 16:30:42: (network.c.379) can't bind to port:  80 Address already in use
Aug 06 16:30:42 asusntb lighttpd-angel[31283]: lighttpd-angel.c.140: child (pid=31284) exited normally with exitcode: 255
Aug 06 16:30:42 asusntb lighttpd-angel[31286]: 2012-08-06 16:30:42: (network.c.379) can't bind to port:  80 Address already in use
Aug 06 16:30:42 asusntb lighttpd-angel[31286]: lighttpd-angel.c.140: child (pid=31287) exited normally with exitcode: 255
Aug 06 16:30:42 asusntb systemd[1]: lighttpd.service start request repeated too quickly, refusing to start.
Aug 06 16:30:42 asusntb systemd[1]: Unit lighttpd.socket entered failed state.

Any ideas?

Offline

#2 2012-08-07 00:24:37

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: systemd socket activation - mpd, lighttpd etc.

sshd does not have socket activation in the systemd sense. sshd offers sshd.socket and a matching sshd@.service, which offers inetd style activation.

You really do need to patch daemons to support proper socket activation (see the daemon(7) manpage). mpd supports it, cups supposedly supports it. udev definitely supports it. lighttpd does not.

Offline

#3 2012-08-07 12:50:26

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 776

Re: systemd socket activation - mpd, lighttpd etc.

OK, thanks for pointing me to the right direction, I'll look into it...

Offline

Board footer

Powered by FluxBB