0x4a42.net

Hello World.

SmokePing with nginx and FastCGI

/images/2016/smokeping.thumbnail.png

I’ve been running SmokePing with nginx and fcgiwrap for quite some time now. This works perfectly fine, but sometimes I feel the urge to change a running system just to improve the configuration a little bit. That’s exactly what happened when I noticed that you can actually run smokeping.cgi as a FastCGI script.

There’s not much you have to do, to get this running, just let your good old friend spawn-fcgi do the job with this systemd unit file in /etc/systemd/system/smokeping-fcgi.service:

[Unit]
Description=SmokePing FastCGI Service
After=network.target smokeping.service
Wants=smokeping.service

[Service]
StandardOutput=null
StandardError=syslog
ExecStart=/usr/bin/spawn-fcgi -u smokeping -s /run/smokeping-fcgi.sock \
          -M 600 -n -U www-data -- /usr/share/smokeping/smokeping.cgi
Restart=always

[Install]
WantedBy=multi-user.target

This runs the FastCGI process as the smokeping user while the UNIX socket will be owned by www-data as I prefer to run the webinterface as the service user. So maybe the owner of the cache directory has to be changed:

chown -R smokeping /var/cache/smokeping/

Start it all up:

systemctl daemon-reload
systemctl start smokeping-fcgi

And it’s running as a FastCGI daemon that can be accessed with the following really simple nginx configuration (for example in /etc/nginx/sites-enabled/default). The included fastcgi_params file is the default one as installed by Debian.

location = /smokeping/ {
    fastcgi_pass unix:/run/smokeping-fcgi.sock;
    include /etc/nginx/fastcgi_params;
}

location /smokeping/ {
    alias /usr/share/smokeping/www/;
}

Reload nginx and you’re ready to go:

systemctl reload nginx.service

As a small downside, you now have to restart both smokeping.service and smokeping-fcgi.service when you change the config.

Originally I used the socket activation feature of systemd together with a small shell script from the spawn-fcgi wiki but this resulted in a longer and more complicated config than with spawn-fcgi. You can find the necessary configuration over there if you prefer that method.