Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Communicating with the running daemon #19

Closed
ClementNerma opened this issue Sep 17, 2022 · 5 comments
Closed

Communicating with the running daemon #19

ClementNerma opened this issue Sep 17, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@ClementNerma
Copy link

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 :)

@ClementNerma ClementNerma added the enhancement New feature or request label Sep 17, 2022
@xadaemon
Copy link
Owner

@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.

https://docs.rs/interprocess/latest/interprocess/

@xadaemon
Copy link
Owner

xadaemon commented Sep 24, 2022

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

@xadaemon
Copy link
Owner

xadaemon commented Sep 24, 2022

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.

@xadaemon
Copy link
Owner

Another way that occurred to me to do IPC is shared memory along with a sync primitive this can be a pretty easy approach.

@ClementNerma
Copy link
Author

I ended up using Unix sockets (as my project is Unix-only for now) but I'll take a look at interprocess if I ever make it cross-platform.

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, interprocess, tarpc or others :)

Repository owner locked and limited conversation to collaborators Nov 17, 2022
@xadaemon xadaemon converted this issue into discussion #20 Nov 17, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants