Skip to content

Instantly share code, notes, and snippets.

@dermesser
Created February 15, 2020 18:29
Show Gist options
  • Save dermesser/035fe3e519ffbfdc6333a8c85bd98ec6 to your computer and use it in GitHub Desktop.
Save dermesser/035fe3e519ffbfdc6333a8c85bd98ec6 to your computer and use it in GitHub Desktop.
FastCGI config in purely systemd: This works for services expecting a socket on stdin, like HG Web (see example)
[Unit]
Wants=network.service nginx.service
[Install]
Alias=hgweb
WantedBy=multi-user.target
[Service]
User=lbo
Type=exec
ExecStart=/home/lbo/hg/.config/hgweb.fcgi
StandardInput=socket
ExecStop=/usr/bin/kill $MAINPID
Restart=always
[Unit]
Description = FCGI socket for hgweb
[Socket]
ListenStream = /run/web/hgweb.socket
Accept = false
[Install]
WantedBy = sockets.target hgweb.service
#!/usr/bin/env python2
#
# An example FastCGI script for use with flup, edit as necessary
# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "/home/lbo/hg/.config/hgweb_config"
# Uncomment and adjust if Mercurial is not installed system-wide
# (consult "installed modules" path from 'hg debuginstall'):
#import sys; sys.path.insert(0, "/path/to/python/lib")
# Uncomment to send python tracebacks to the browser if an error occurs:
#import cgitb; cgitb.enable()
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb import hgweb
from flup.server.fcgi import WSGIServer
application = hgweb(config)
WSGIServer(application).run()
[...]
location /lbo/hg/ {
fastcgi_pass unix:/run/web/hgweb.socket;
include fastcgi_hg;
fastcgi_intercept_errors on;
limit_except GET HEAD {
deny all;
}
}
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment