Question

I've been googling around looking for a way to properly and cleanly start a series of binaries wich are pipeed toghether, and let all the whole stuff be launched normaly as a series of daemons would be... but no luck with this.

In a nutshell, here's my command:

ossrecord -s48000 -b16 -c2 -d/dev/oss/oss_envy24ht0/pcmin0 - | opusenc --bitrate 96 - - | oggfwd 192.168.1.12 7000 mysecret /mystream.opus

Basically it grabs oss v4 pcm audio from a capure device, pipes the output aout to opusenc binary, which in turn encodes it to opus format, and finally, I pipe the result out to a icecast2 server (all this is more or less nicely documented on the opus docs) And it works nicely!

The problem is that all this ocurs on the cli, it captures stdout ans starts yelding output. Being all that stuff a series of piped processes I dont manage to control them. Moreover, it would be nice to have some kind of launching/stopping script, that would make it possible to have all this running in the background.

I have being struggling with start-stop-daemon as I usually do, but my knowledge basically covers handling a single binary and its paramenters (as found on docs), and I think I'm blindly stepping on holy guru's domains.

So, maybe someone may find out how this can be totally or partially acomplished.

Was it helpful?

Solution

I came across exactly the same problem and decided for me to solve this once and forever ;-) [One reason was your question here at stackoverflow without an answer or even a comment.]

Therefore I wrote a small program called pipexec. The features in a nutshell:

  1. Starts programs and pipes them together.
  2. When a SIGTERM, SIGINT or SIGQUIT is send to the program, it terminates all it's children and then itself.
  3. When a SIGHUP is sent to pipexec it restarts all the children (including the pipes in between them).
  4. When a child terminates un-normally (e.g. by a signal), all children are terminated and restarted (including the pipes).
  5. Support for pid file.

It's written in plain C99 with Linux in mind. 500 lines of code resulting in about 20k executable. I integrated pipexec into the RHEL6 using /etc/init.d/functions daemon and killproc and it works seamlessly. The pid file feature was used here.

Kind regards - Andreas

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top