Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
systemd to FastCGI socket passing compatibility script
#!/bin/bash
set -e
if [ "${LISTEN_PID}" != $$ ]; then
echo >&2 "file descriptors not for us, pid not matching: '${LISTEN_PID}' != '$$'"
exit 255
fi
if [ "${LISTEN_FDS}" != "1" ]; then
echo >&2 "Requires exactly one socket passed to fastcgi, got: '${LISTEN_FDS:-0}'"
exit 255
fi
unset LISTEN_FDS
# move socket from 3 to 0
exec 0<&3
exec 3<&-
# spawn fastcgi backend
exec "$@"
@throwable-one

This comment has been minimized.

Copy link

throwable-one commented Dec 17, 2016

Why do you need separate script for it?
Systemd can pass socket as stdin (0), not 3.
See "StandardInput=socket".

Following config works for me:

$ cat munin-cgi-graph.socket
[Unit]
Description=Munin socket

[Socket]
ListenStream=/run/munin/munin-cgi-graph.sock
Accept=false

[Install]
WantedBy=sockets.target


$ cat munin-cgi-graph.service
[Unit]
Description=Munin cgi graphics
After=network.target
Requires=munin-cgi-graph.socket


[Service]
ExecStart=/var/www/cgi-bin/munin-cgi-graph
User=munin
Type=simple
Group=nginx
StandardInput=socket

[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.