Skip to content
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

Init daemon to manage all running processes #54

Open
Gerschtli opened this issue Feb 14, 2020 · 15 comments · May be fixed by #203
Open

Init daemon to manage all running processes #54

Gerschtli opened this issue Feb 14, 2020 · 15 comments · May be fixed by #203

Comments

@Gerschtli
Copy link
Collaborator

Hey, in the last weeks I was trying to build service-like modules, e.g. an sshd service that will execute some commands before starting like generating a host key and start the sshd daemon. To stop it, you have to kill the process, which needs to be done on exiting the app, if not it will run in the background.

Similar problem with ssh-agent, the agent will not be killed on exiting the app.

Of course one could define for these commands services and let login-inner stop all running services on app exit, but this is not really error-prone.

That is why I thought of something like an init daemon, so that all processes started will be killed, when killing the init daemon.

Thats all I have for now. What do you thing? Have you another/a better idea?

@t184256
Copy link
Collaborator

t184256 commented Feb 14, 2020

Service management is complicated, mostly because it's android development territory, where I'm quite inept.

My ideal service management story would be having a real init (systemd would be sweet, but maybe something like runit might work), with a lifetime equal to the lifetime of the notification, so that you can acquire wakelock, end all sessions and still keep it running.

Are you sure that killing the app doesn't reap all its processes? That sounds real weird to me, actually, I would expect that it does.

@Gerschtli
Copy link
Collaborator Author

A real init system would be nice but maybe an overkill. But I had not that much contact with setting up init systems and what kind of init systems exist already. A quite mimimal one for a primitive service management with transitive dependencies should be sufficient.

Yes I am sure. Example: Run ssh-agent, you can see the process via htop for example. If you exit the app via the notification and start the app again, you can see ssh-agent process is still running. When instead you use force quit in android settings, the process will be killed.

@Gerschtli
Copy link
Collaborator Author

Maybe the app only kills the login process that it started but because ssh-agent is detached completely and no member of the login process group (which forces the app to kill it explicitly), it remains running.

@t184256
Copy link
Collaborator

t184256 commented Feb 17, 2020

Aha. Then we are after a process supervisor

@t184256 t184256 closed this as completed Feb 17, 2020
@t184256 t184256 reopened this Feb 17, 2020
@t184256
Copy link
Collaborator

t184256 commented Feb 17, 2020

(fat fingers) Then we are after a process supervisor (supervisord? daemontools? something else?), spawning it, demonized, from the login script, ensuring that we have one and, maybe, hooking the 'exit' button to stop it.

@t184256
Copy link
Collaborator

t184256 commented Feb 17, 2020

@Gerschtli
Copy link
Collaborator Author

Oh forgot about this thread here..

I think we should consider using a init system, that provides us with functionality like service management, but is still as minimal as it can be. I don't know many init systems out there, so can you recommend any?

Would be a pretty neat feature for our small project :)

@t184256
Copy link
Collaborator

t184256 commented May 30, 2020

Last time I've researched that, a systemd-versed friend told me that systemd is out of question (that the whole nix-on-droid is beyond crazy). For the remaining ones, I recall supervisord was the most promising one, but I don't remember the details now.

@Gerschtli
Copy link
Collaborator Author

Alright, I will have a look into supervisord as a starting point.

@MatthewCroughan
Copy link

@t184256 supervisord works flawlessly for managing multiple processes inside of Docker containers for example, here is an example config in a project:

I think it'd be a great fit for nix-on-droid. My use case is that I want to use nix-on-droid to replicate the work I've done with Docker to run on Android devices by acquiring wakelock and having these processes run under supervisord. It would be fantastic if we could spawn these processes declaratively in the nix configuration on Android by this method.

It's worth noting that Termux can already spawn processes at boot via this addon

@zhaofengli zhaofengli linked a pull request Sep 21, 2022 that will close this issue
@tobiasBora
Copy link

tobiasBora commented Jan 2, 2023

I would also love to see services in nix-on-droid. My use case would be to create a cron entry to start a script on a regular basis (it would be even cooler if it were compatible with systemd syntax, in order to re-use all the code made for systemd)

@Gerschtli
Copy link
Collaborator Author

The current approach would use supervisord, see #203, but it is still WIP

@tobiasBora
Copy link

Yeah, I saw that, thanks for the link. But I guess this would not start nix-on-droid automatically at startup, right? We should maybe add some options to automatically start nix-on-droid when the phone reboots, as I would not want my cron tasks to stop after a reboot.

@Gerschtli
Copy link
Collaborator Author

That sounds like some android stuff.. If you have more knowledge in this regard, feel free to play around with https://github.com/t184256/nix-on-droid-app. Android knowledge is generally lacking in this project unfortunately.

@phanirithvij
Copy link
Contributor

phanirithvij commented Dec 12, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants