Communicating with the running daemon #20
Replies: 6 comments
-
@ClementNerma This is an IPC task because the way daemonizing works is, you split off a child process from the parent process and as such you cannot get the pid, that's why there is a pid file option in the library, this is the usual way to pass that information. On the topic of IPC since there are a lot of ways to do it, and none that is a de-facto way. Something like unnamed pipes or FIFO (named) pipes or unix domain sockets should suffice, have a look at this library. |
Beta Was this translation helpful? Give feedback.
-
The main issue is that I could implement say both anon and named pipes, but the protocol would still be up to the user unless I also implement some protocol and so on, so I'm pretty much against implementing anything of the sort directly in the lib. I'm happy to provide guidance with IPC |
Beta Was this translation helpful? Give feedback.
-
On the topic of IPC, after having a transport it's pretty much RPC, so you have choices, for simple tasks something with serde and some binary encoding should do, and for more complex cases check https://github.com/google/tarpc. If you just want a simple is running check on the daemon, getting the child pid from the pid file and using system functions should not be hard to accomplish, I might have a look into adding this to the lib, or you could try implementing it, should be an easy one. |
Beta Was this translation helpful? Give feedback.
-
Another way that occurred to me to do IPC is shared memory along with a sync primitive this can be a pretty easy approach. |
Beta Was this translation helpful? Give feedback.
-
I ended up using Unix sockets (as my project is Unix-only for now) but I'll take a look at I think it could be a good idea to put an explanation in the README to indicate that this crate doesn't handle daemon communication and users must instead rely on other solutions like STD's Unix sockets, |
Beta Was this translation helpful? Give feedback.
-
I have made this into a discussion to keep it around for future reference :) |
Beta Was this translation helpful? Give feedback.
-
Hi there!
I've been using this library to create a daemon for a program I use. It works perfectly, but I don't know how to interact with it later.
Is there any function (or could there any that could be implemented) to check if the daemon is already running, and if so communicate with it? Even just getting its PID would already be useful, even better if it's possible to communicate natively with it.
Thanks in advance for your help :)
Beta Was this translation helpful? Give feedback.
All reactions