-
Notifications
You must be signed in to change notification settings - Fork 89
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 system for startup and interactive? #170
Comments
What method do you use to start postgres? Usually, I have a Procfile that starts postgres, the backend and the frontend, and executed by foreman or hivemind. That lives in a shell of its own. |
The plugin. |
For files I created a If there is any interest, I can port it to a stand-alone version and open a PR. Basically,
Is s6, the best tool for the job? 🤷 When we should stop? Know bug: |
After thinking more about this, maybe the fact of opening services just by entering the shell is a wrong concept. Yes, there can be multiple shells. Also it makes it difficult to to think about direnv integration and other shells. I mean:
So maybe all we really need is to define services and provide a service manager that you execute manually. Let's say it's called So, you enter the folder, direnv does its work, you keep using Fish (or your favorite shell), and you just run I haven't tried yet with devshell-files. Does it allow this workflow? Does it integrate properly with the postgres service defined in this project? |
Is the standard workflow, but
I never tried, I'm running Postgres as docker service, there is no such thing as integration, you just need to specify a service like. In most of cases we need more arguments for init, usually, I do something like this (one of actual configurations): {
# files.alias is a helper to devshell.commands = [ { name = "apiSVC"; command = "cd ..."; } ];
# API
files.service.apiSVC = true; # it configures s6-suverpisor files for apiSVC
files.alias.apiSVC = ''cd api; exec docker compose up''; # stdout goes to .data/log/{name}/current
files.alias.apiSVC-finish = ''cd api; exec docker compose stop'';
# frontend
files.alias.webSVC = "cd webapp; exec npm run serve";
files.services.webSVC = true; # it configures s6-suverpisor files for webSVC
# the actual config has also ngrok (to espose 8080 to the world),
# a docker api logger, because stdout of docker compose up have log for both api and postgres
# my workflow involves a cloud workers, I created a service notify status with 'notify-desktop'
# I could create a 'pomodoro' service to notify start and stops
} I'm not sure how does it translate to TOML but should work since no function were called ;-) And again, I'm using s6 and not sure if it is the best tool for the job, recommendation are welcome edit: requires |
I've experimented with it and it looks good, but s6 is indeed giving some headaches. cruel-intentions/devshell-files#5 fixes some of them, but still not perfect. For example, if running a I'm attempting with |
As I can see our cases are different,
Anyway there are some bugs, running stopSvcs doesn't always stop all process. If it worked, and you experienced some stop issues, we are on same page :) There are two possibilities:
Thank you, I will look at it. Curiously, I'm trying to an option to intentionally make it child of pid 1 and don't block direnv, while you're saying that unintentionally it is child of pid 1. |
Yes, so it seems. I borrowed some ideas from here and there but I'm now using just devshell + a couple of customizations based on tini. It's making me very happy now, and I think the main specific point of enhancement in this issue is what I already explained in #170 (comment). Now that I managed to not start services when doing I opened #194 to explain how I managed to do it, to avoid going more off-topic here. |
I'm happy you choose s6 because is feature complete and wide compatible. But I will more happy if somebody gets to integrate https://github.com/svanderburg/nix-processmgmt into devshell. |
Summary: |
chvp |
Yesterday I was playing with this like:
SESSION_PID=$$
PARENT_PID=$PPID
while grep -q direnv /proc/$PARENT_PID/comm
do
SESSION_PID=$(ps -o ppid= $PARENT_PID|tr -d \[:space:\])
PARENT_PID=$SESSION_PID
done
ln -s /proc/$SESSION_PID/comm $PRJ_DATA_DIR/procs/$SESSION_PID &>/dev/null
# Stop services when all registered procs died
while true
do
sleep 1
# delete dead procs link
find $PRJ_DATA_DIR/procs/ -xtype l -delete
# stop services if folder is empty
find $PRJ_DATA_DIR/procs/ -type d -empty -exec stopSvcs \;
done Possible bug: |
Hello. I've been testing the new My use case is:
The important part (num. 4) is not achieved with Honcho. It lets the postgres service run although the parent VSCode process is stopped. With tini, I launch the process like this and it solves point 4: exec ${tini}/bin/tini -sp SIGTERM -- start-postgres So IMHO is a more straightforward way to do it. Anyway, it's not a problem because the change is backwards-compatible. I just wanted to point out why I won't use it, and help others that come here. |
I'm not sure how VSCode tasks work, but if honcho is launched from VSCode, I would expect it to be killed when VSCode is closed? Killing the honcho process also cleans up the running services. |
Well, that's what I expect too. However, with Honcho it does work with Mailhog, but not with Postgres. It seems there's something else involved in that. For example, with |
Ah yeah, processes managed by honcho shouldn't daemonize. I'll make a PR noting this in the documentation (if I don't forget). |
I was launching start-postgres from devshell/extra/services/postgres.nix Lines 35 to 39 in f9238ec
It's weird that these 2 systems provided are incompatible. Wouldn't it be easier to just switch to tini, which supports the same use case as honcho, but also the subreaper case? 🤔 |
I wouldn't say it supports the same use case. As far as I can tell, |
Ah indeed. Tini is just a process subreaper. Then maybe the solution is just to wrap the call to honcho with tini, so we get the best of both worlds. |
I was trying use tini as subreaper (adoption of grandchildren if parent process dies) and it didn't worked systemd (pid1) -> s6-svc -> s6-supervisor -> tini -> bash -> inotifywait inotifywait allways end as child of systemd, anyway I left this feature in the my code just in case. Also tested changing PGID (process group id) but it only works with TTY, not in background process, tested if session id, to kernel auto send signal HUP to childs, but no lucky. Maybe tini works for you because VSCode is the TTY/Session Parent/Group Parent. Fixed with Also did a test with unshare (linux namespaces) using |
Did you add the tini flags I mentioned in #170 (comment)? |
Yes 😖, actually copy and pasted directly from that command, |
Weird.. maybe the subprocess you want to reap needs a different termination signal? |
Is your feature request related to a problem? Please describe.
Exiting
nix develop
shell leaves running processes.Describe the solution you'd like
For interactive and startup sections, it would be great to be able to leverage some small init system that automatically reaps child processes.
Describe alternatives you've considered
Adding traps like here, but still not easy to get going right always, and some programs don't support daemon mode out of the box:
devshell/tests/extra/services.postgres.nix
Line 20 in 7033f64
Additional context
The text was updated successfully, but these errors were encountered: