Signalling a Custom Module

Hi all,

Sorry if I’ve missed something that’s here already, but couldn’t find anything.

I’m looking to have a way to send a “signal” to my custom module. So far I’ve thought of 3 possible options:

  1. Run a webserver on localhost, listening to a different port. Then in the handler, I can be listening for my event
  2. Trap an OS signal, so I know that something happened (similar idea to how software in general listens to USR1 to reload config). The purpose isn’t to re-read the config, I know how Caddy can do that, it’s just an example of what I mean for capturing signals

Or another idea I’ve had is would I be able to add a command within Caddy? So I could have my own caddy custom-command alongside these? Command Line — Caddy Documentation?

I know the first 2 options would technically be fine and work, but the random 3rd idea sounds like the nicest option if it was possible.

Any ideas are welcome!

Thanks

It entirely depends on what you need this for.

I’d say the third option, adding your own subcommand, is probably the easiest. It’s already possible! See the following:

Why do you need a signal? Usually you would want to implement an API endpoint instead, so your module can also work on Windows (and with much greater flexibility than a mere signal offers).

That’s fantastic @francislavoie, it’s exactly what I was hoping for. Thanks for pointing me in the right direction!

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