Fork me on GitHub
#off-topic
<
2017-04-06
>
pesterhazy13:04:10

Is there a Unix tool that starts a daemon, optionally waits for it to listen on a port, then starts another process? When the second process exits, the tool should automatically kill the daemon.

jjl13:04:55

i expect that's within the capabilities of djb's daemontools (what most non-systemd init scripts use). i'd recommend the bash.

souenzzo14:04:43

Looks that ansible can do that. http://docs.ansible.com/ansible/wait_for_module.html (some other modules to stop/start if/already)

souenzzo14:04:51

Unix tool... nc can do the wait_for part, then combine your systed services/init scripts ...

sb20:04:06

clj ssh + screen, which kill automatically the screen?

sb20:04:51

or nohup command, but I didn’t use..

souenzzo15:04:43

I think that systemd itself will not "wait for a port", it "wait for a unit". One aproach was create a systemd service with nc --please-wait-localhost:3000, then another service that requires the finish of nc service. Maybe nc should kill your service's service too..

pesterhazy14:04:14

totally missed this comment thread

pesterhazy14:04:45

thanks for the suggestion, it all seems more complicated than it should

pesterhazy14:04:02

it's pretty easy to write a python script that does this, so I think I'll go that route

pesterhazy13:04:52

I suspect this can be achieved with a bash script but unless there's a battle-tested bash solution out there I'd rather not roll my one.

ejemba14:04:48

as they have events you can react on event or this is already built in

pesterhazy15:04:30

@ejemba it starts a separate daemon, which is not what I want; I'd like the tool to exit when the job is done

ejemba15:04:53

there are others

pesterhazy15:04:56

I've actually used supervisor for this kind of thing in the past, and it worked, but it's a bit messy for the simple task I want to accomplish

pesterhazy15:04:45

I envision a single-minded tool written in rust that does only this 🙂

ejemba15:04:35

I'm sure you'll find a go tool for that

pesterhazy15:04:20

what should I search for though?