Skip to content

Instantly share code, notes, and snippets.

@stbuehler
Created March 28, 2015 09:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stbuehler/439a9849747279a1f0a9 to your computer and use it in GitHub Desktop.
Save stbuehler/439a9849747279a1f0a9 to your computer and use it in GitHub Desktop.
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
Copy link

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