<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 14, 2021 at 9:29 PM Kevin P. Fleming <<a href="mailto:kevin@km6g.us">kevin@km6g.us</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">You might consider having systemd itself create the listening sockets<br>
and then pass them into the service; if you did that, then systemd<br>
would already know the port number that was allocated for the socket.<br>
<br></blockquote><div><br></div><div>I can't; a .socket unit gets activated, and subsequently starts its corresponding service, when the first connection is made. The primary purpose of the service is not to serve data over that socket; the socket is there for scraping metrics. </div><div><br></div><div>Thanks though,</div><div><br></div><div>/ji</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On Mon, Jun 14, 2021 at 9:17 PM John Ioannidis <<a href="mailto:systemd-devel@tla.org" target="_blank">systemd-devel@tla.org</a>> wrote:<br>
><br>
> I have an instanced service that gets started and stopped by another service: alice.service runs the equivalent of systemsctl start alice@foo.service, systemctl start alice@bar.service, systemctl stop alice@cat.service, and so on.<br>
> Each of the instanced services runs a little http service so its status can be monitored, metrics scraped, etc. The tcp port on which that service runs is just whatever the kernel allocated. I want to export that port number so other processes can find it and use it, for example, by doing the equivalent of systemctl list-units | grep alice@ so they find which instances are actually running, and then going about finding the corresponding ports.<br>
><br>
> I can think of a number of ad hoc ways:<br>
><br>
> * they can write the port number in a file like /run/alice/foo.port, /run/alice/bar.port, and whoever is interested can go read those files, in the same way that we use .pid files.<br>
> * They can use systemd-notify to export it as "Status"<br>
> * Using a service discovery mechanism would be an overkill, especially since whatever is actually talking to those ports is on the same host as the services themselves, but that's also a possibility.<br>
><br>
> Is there a systemd-native way of accomplishing this? It would be nice if it were possible to have user-defined properties that could be set with systemctl set-property, but that is not the case.<br>
><br>
> Thanks<br>
><br>
> /ji<br>
> _______________________________________________<br>
> systemd-devel mailing list<br>
> <a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/systemd-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
</blockquote></div></div>