I have a server application that runs in an infinite loop, only reacting to SIGINT. It is put inside a screen
process. If I have to make any changes (reload configuration, add new plugins, etc) I simply restart the whole process so the changes are picked up during initialization.
I’d love to refactor the application so that I have two ways of interacting with it: A web UI, and a console interface.
For the web UI I use a small embedded HTTP server and can hook up the requests to my event loop. But I’m unsure how I should implement the cli. Is it advantageous to provide a separate cli process, accessing the same embedded server? Or would it be preferrable to make my own application wait for text input? In the latter case, I’m struggling with implementing the event loop to poll both the web requests as well as the console at the same time.
Quite often server processes are run truly headless: input and output redirected to null.
Re-using the application’s standard input means that only one user can access it, and that must be the user that started it. Conversely, if you have a CLI tool that accesses the HTTP API, you then have to wonder about authentication, but multiple users can now use it. But it may make more sense to the user because it can be used from the shell in the normal way.
implementing the event loop to poll both the web requests as well as the console at the same time.
This is normally simple: add stdin to the select()/poll() loop and make sure it is handled separately.
(unless this is a Windows app?)
3