-2

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.

1

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
  • It's a Linux server app. Thanks. I totally forgot that 'stdin' is just another file descriptor. Apr 22 at 9:46
  • What makes you think this would not work in Windows?
    – Doc Brown
    Apr 22 at 12:13
  • select() isn't a true native API on Windows; it would probably work but I wouldn't rule out surprises.
    – pjc50
    Apr 22 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.