[systemd-devel] Is it possible to let systemd create a listening socket and yet be able to have that socket activate nothing, at least temporarily?
Klaus Ebbe Grue
grue at di.ku.dk
Fri Oct 7 08:10:30 UTC 2022
Hi Mantas,
Thanks for the suggestion. I will take a look at it. When i do not want to do
int flag=1;
int rv=setsockopt(listen_fd,SOL_SOCKET,SO_REUSEADDR,&flag,sizeof(flag));
the central problem will be to avoid the 1 minute delay
Cheers,
Klaus
________________________________
Fra: Mantas Mikulėnas <grawity at gmail.com>
Sendt: 7. oktober 2022 09:51
Til: Klaus Ebbe Grue
Cc: systemd-devel at lists.freedesktop.org
Emne: Re: [systemd-devel] Is it possible to let systemd create a listening socket and yet be able to have that socket activate nothing, at least temporarily?
You don't often get email from grawity at gmail.com. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
On Fri, Oct 7, 2022 at 10:24 AM Klaus Ebbe Grue <grue at di.ku.dk<mailto:grue at di.ku.dk>> wrote:
Hi systemd-devel,
I have a user question which I take the liberty to send here since "about systemd-devel" says "... it's also OK to direct user questions to this mailing list ...".
I have a daemon, /usr/bin/mydaemon, which listens on one and only one TCP port, say 9999, and which does no more than communicating over 9999 and creating, reading, writing and deleting files in /home/me/mydaemon/.
Mydaemon leaves it to systemd to create a socket which listens at 9999.
It is unimportant whether or not mydaemon is started at boot and it is also unimportant whether or not mydaemon is socket activated. As long as it is at least one of the two.
Now I want to upgrade mydaemon to a new version using a script, without race conditions and without closing the listening socket. I want the listening socket to stay open since otherwise there can be a one minute interval during which it is impossible to reopen 9999.
If it is just a clean upgrade, the script could replace /usr/bin/mydaemon, then stop mydaemon. If the daemon is socket activated there is no more to do. If the daemon is activated only on boot then the script must end up restarting mydaemon.
But now I want to do some more while mydaemon is not running. It could be that my script should take a backup of /home/me/mydaemon/ in case things go wrong. It could be the script should translate some file in /home/me/mydaemon/ to some new format required by the new mydaemon or whatever.
So I need to stop mydaemon in such a way that mydaemon cannot wake up while my script fiddles with /home/me/mydaemon/.
Deploy the new version of your daemon to another location (/home/me/mydaemon.new/), perform all processing/conversions that are necessary, *then* stop the socket, `mv mydaemon mydaemon.old`, stop the service, `mv mydaemon.new mydaemon`, start the socket again. The interval for this will be more like half a second than a minute.
--
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20221007/463ac5e2/attachment-0001.htm>
More information about the systemd-devel
mailing list