Smokeping Caddyfile

Hi, I’m trying to run Smokeping with Caddy.

Archlinux has a guide for Apache/Nginx but not Caddy: Smokeping - ArchWiki

I found an old gist SmokePing Caddyfile · GitHub

But my own config in /etc/caddy/caddy.conf.d:

smokeping.dabase.com {

startup spawn-fcgi -s /tmp/smokeping_cgi.sock -P /tmp/smokeping_cgi.pid /srv/http/smokeping/smokeping.fcgi.dist
shutdown bash -c 'kill -9 --verbose $(cat /tmp/smokeping_cgi.pid)'

        tls hendry@iki.fi
        root /srv/http/smokeping

        fastcgi /smokeping unix:/tmp/smokeping_cgi.sock {
                ext   .fcgi.dist
                split .fcgi.dist
                index smokeping.fcgi.dist
        }
}

Doesn’t work. At least https://smokeping.dabase.com/smokeping is a 404

I don’t quite understand spawn-fcgi or if it’s even really needed by Caddy.

Thanks for any pointers in advance!

Hi @hendry,

Firstly, I should note that startup and shutdown directives are deprecated, on favour of the new on directive that handles both their functionality:

https://caddyserver.com/docs/on

Effectively, you should just be able to replace startup with on startup, and shutdown with on shutdown.

Caddy doesn’t process scripts on its own; it needs a program to execute them, then feed the result back to Caddy to pass on to the connecting client.

I’m not familiar with spawn-fcgi specifically, but based on its command flags, I’m guessing it starts such a program in the background and instructs it to listen on /tmp/smokeping_cgi.sock.

The fastcgi directive later on in the Caddyfile tells Caddy that all requests should be proxied to that program so that it can run the script, /srv/http/smokeping/smokeping.fcgi.dist, and return its results to the client.

The shutdown command just stops that program running in the background when Caddy shuts down, so it’s not running forever.

Now, neither the guide nor the gist mention spawn-fcgi, so I’m not sure if you have that installed or not. If not, you could look at doing things the nginx way and use fcgiwrap. That would entail ensuring that the fcgiwrap service is running, removing the startup and shutdown commands entirely, and changing the socket to unix:/var/run/fcgiwrap.sock.

1 Like

Thanks Matthew! Though I’m hitting Cannot get script name, are DOCUMENT_ROOT and SCRIPT_NAME (or SCRIPT_FILENAME) set and is the script executable?

[hendry@study caddy.conf.d]$ cat smokeping.conf
smokeping.dabase.com {

        log stdout
        errors

        tls hendry@hidden
        root /srv/http/smokeping

        fastcgi /smokeping unix:/var/run/fcgiwrap.sock {
                ext   .fcgi.dist
                split .fcgi.dist
                index smokeping.fcgi.dist
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}
[hendry@study caddy.conf.d]$ sudo systemctl status fcgiwrap.socket
Failed to dump process list, ignoring: No such file or directory
● fcgiwrap.socket - fcgiwrap Socket
   Loaded: loaded (/usr/lib/systemd/system/fcgiwrap.socket; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2018-03-24 22:05:41 +08; 9min ago
   Listen: /run/fcgiwrap.sock (Stream)
   CGroup: /system.slice/fcgiwrap.socket

Mar 24 22:05:41 study systemd[1]: Listening on fcgiwrap Socket.

It should be running /srv/http/smokeping/smokeping.fcgi.dist

I don’t know your application, but… just an idea:

Your bin/bash file:

#!/bin/bash
thepid="/tmp/smokeping_cgi.pid";
thedist="/srv/http/smokeping/smokeping.fcgi.dist;";
thesock="/tmp/smokeping_cgi.sock";
theopen="spawn-fcgi -s $thesock -P $thepid $thedist";
theclose="bash -c 'kill -9 --verbose $(cat $thepid)'";

The Caddyfile:

on startup /your/path/bin-bash.file "$theopen"
on shutdown /your/path/bin-bash.file "$theclose"

Hmm. Few problems here:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name

  1. This syntax is totally unsupported.
    a. fastcgi_param should instead be env. (see https://caddyserver.com/docs/fastcgi)
    b. The form $variable is not expanded. The form {$VARIABLE} should be used instead. (see The Caddyfile — Caddy Documentation)
  2. It’s completely unnecessary! Caddy sets these variables automatically based on the web root and the request path.

I’d just remove that line entirely; leave the ext, split, and index subdirectives in.

Still doesn’t work. A 404.

Hmm. Looking deeper, I think I was wrong to advise keeping ext, split, and index in; We really just want all requests to go to Smokeping via FastCGI regardless of URI, and we don’t want to depend on the URI for the script filename. I’m thinking we’ll want to move along the lines of this:

fastcgi /smokeping unix:/var/run/fcgiwrap.sock {
  env SCRIPT_FILENAME /srv/http/smokeping/smokeping.fcgi.dist
}

There might be more env vars that need to be set along this manner, not sure off-hand. I might have some time to keep looking later.

1 Like

Thank your Matthew. It appears to be working with:

[hendry@study caddy.conf.d]$ cat smokeping.conf
smokeping.dabase.com {

        log stdout
        errors

        tls hendry@iki.fi
        root /srv/http/smokeping

        fastcgi / unix:/var/run/fcgiwrap.sock {
                env SCRIPT_FILENAME /srv/http/smokeping/smokeping.fcgi.dist
        }
}

smokeping.dabase.com/cache {
        root /var/cache/smokeping
}

I owe you a beer, that’s for sure!

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.