Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for on-demand starting #3382

Open
hadmut opened this issue May 16, 2024 · 5 comments
Open

Support for on-demand starting #3382

hadmut opened this issue May 16, 2024 · 5 comments
Labels

Comments

@hadmut
Copy link

hadmut commented May 16, 2024

Problem: Quite often a web/api/rest server is only need sometimes to run, and usually on small and older machines not packed with heaps of RAM it is reasonable to run only those processes that are actually needed, i.e. start them on demand only.

There is currently two common and well established methods to run servers on demand:

  1. The old fashioned way to start them with inetd / xinetd, which open a socket, wait for connections, and once a client connect, spawn a process to handle all incoming requests, and once the process terminates itself (e.g. due to timeout), again, wait and spawn if needed.

  2. The newer systemd, which virtually does the same, but supports two different methods of passing the socket to the server application, which is a) the traditional inetd method and b) the newer way sd_listen_fds(3), see man systemd.socket and man 3 sd_listen_fds

Would be great if it was possible to have small web servers or REST APIs, that are needed occasionally only, be able to be started on demand through systemd.

Describe alternatives you've considered
Start the server through systemd permanently (as a system task) or once the user is logged in (as a user unit). Means the server is running always, even if not needed.

@dentarg
Copy link
Member

dentarg commented Jun 5, 2024

Is there anything needed to be done in Puma to support this?

@hadmut
Copy link
Author

hadmut commented Jun 5, 2024

I wouldn't see how to start Puma/rack in its current state. If it is possible, there should be something in the docs explaining it.

@dentarg
Copy link
Member

dentarg commented Jun 5, 2024

You start Puma by running puma? Or bundle exec puma

Have you seen https://github.com/puma/puma/blob/master/docs/systemd.md?

@hadmut
Copy link
Author

hadmut commented Jun 5, 2024

No, didn't see this.

I recently spent some time trying to find a solution for rack applications with different servers such as puma, but for whatever reason, I did not find this, not a single hint that puma is capable of running from systemd with socket activation.

But it seems to solve my problem only partly.

If you need to pass the TLS key file with a -b option like
ExecStart=//puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem

will this still work with socket activation? The Examples seem to intermix a permanent start as a regular service with a socket activation.

@dentarg
Copy link
Member

dentarg commented Jun 5, 2024

I'm not using systemd myself so I'm not sure. Maybe you can test it and report back. Maybe you can even improve the docs if there's need for that. This is open source after all :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants