tinyproxy / tinyproxy

tinyproxy - a light-weight HTTP/HTTPS proxy daemon for POSIX operating systems
GNU General Public License v2.0
4.67k stars 645 forks source link

Improve support for systemd and daemontools #507

Closed Oppen closed 9 months ago

Oppen commented 10 months ago

Tinyproxy version

None yet, but the observations are over master.

Issue

Tinyproxy seems designed with the following rules, which were commonplace with sysvinit:

Currently, both systemd and most modern daemontools derivatives supervise processes, which not forking makes easier, and makes pidfiles redundant. They support file descriptor passing as well, which I'll come back to later. They capture stdout and stderr for logging. They have pipes and sockets to receive simple signs of readiness to serve.

What I propose is supporting these. It shouldn't be a lot of code and I wouldn't be against implementing (some of) it myself, but I'd like to see if the interest is there. It's several features that can be implemented separately.

I'm thinking of using tinyproxy as a reverse proxy, but I'd really like to be able to not hack around s6. Indeed, one of the reasons I'm considering it is that everything else is "broken" in these regards, but this one at least I feel confident I can submit patches, while the other ones are simply too big to understand.

Oppen commented 10 months ago

OK, looking at the code I see the default logging is already stdout. It doesn't seem documented and a very old mail in the supervision mailing list mislead me to believe it was still not supported. The same can be found about daemonizing. So only two are missing AFAICT.

rofl0r commented 10 months ago

the quickstart guide on the official homepage explicitly uses the options you desire. i can't see the purpose of "readiness signaling", please enlighten me. as of current master, with an average config file the parsing on startup requires only nanoseconds so tinyproxy is for all means instantly "ready". if you have a filterlist of thousands of entries, then it might take a little longer.

Oppen commented 9 months ago

The purpose of readiness signaling is to allow proper dependency tracking for service managers.

Oppen commented 9 months ago

Re: quickstart guide: the only option I see there is the one for not daemonizing, which I reformatted as strike through because I later noticed it was there. But the other ones aren't. In particular there's some value in dropping privileges before launching the program, since this avoids running the parser before that (often error prone).

rofl0r commented 9 months ago

the QS guide uses foreground mode/stdout logging/no pid files/restricted user account which are all best practices for daemontools and simple systemd services. if you already start as restricted user, there's no value to be gained from dropping privileges. as for the parsing you mentioned, on SIGUSR1 tinyproxy reloads the config file, so it has to be able to parse even after it's up. i also worked together with distro people (e.g. debian) to modernize their crufty service scripts.

Oppen commented 9 months ago

The point with starting without privileges is precisely not needing to do it after parsing. daemontools/systemd pass sockets so only the socket opening needs privileges, which is done before forking from systemd or exec'ing from the run script in daemontools. That doesn't mean tinyproxy should never parse (it would be a really impractical tool otherwise), but just that this allows doing it only after privileges are dropped since it doesn't need to open the ports itself. Tbh with or without my suggestions this project seems to be the closest to what I want. If you're not interested in the changes I think it would be OK to close the issue.

rofl0r commented 9 months ago

alright then.