Skip to content

Instantly share code, notes, and snippets.

@kohenkatz
Forked from stbuehler/systemd-spawn-fcgi.sh
Last active August 28, 2017 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohenkatz/e505eeb34ef982d99636 to your computer and use it in GitHub Desktop.
Save kohenkatz/e505eeb34ef982d99636 to your computer and use it in GitHub Desktop.
How to run a FastCGI process as a service under Systemd, based on http://redmine.lighttpd.net/projects/spawn-fcgi/wiki/Systemd/2
#!/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 "$@"
[Unit]
Description=WebApp service
After=network.target postgresql.service mysql.service
Wants=postgresql.service mysql.service
[Service]
User=webappuser
Group=webappgroup
StandardOutput=null
StandardError=syslog
ExecStart=/usr/local/sbin/systemd-spawn-fcgi.sh /home/webappuser/webapp/runfcgi
[Install]
WantedBy=multi-user.target
[Unit]
Description=WebApp Listen Socket
[Socket]
SocketUser=www-data
SocketGroup=www-data
SocketMode=0600
ListenStream=/run/webapp.sock
[Install]
WantedBy=sockets.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment